2018-10-16 19:22:21 -07:00
|
|
|
AFRAME.registerComponent('menu-slide-animation', {
|
|
|
|
|
schema: {
|
|
|
|
|
isSearching: {default: false},
|
|
|
|
|
menuSelectedChallengeId: {type: 'string'}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
init: function () {
|
2018-10-16 21:28:27 -07:00
|
|
|
this.isLeft = false; // Means toleft.
|
2018-10-16 19:22:21 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
update: function (oldData) {
|
|
|
|
|
const data = this.data;
|
|
|
|
|
|
2018-10-16 21:28:27 -07:00
|
|
|
if (this.isLeft) {
|
2018-10-16 19:22:21 -07:00
|
|
|
// Unselect.
|
2018-10-16 21:28:27 -07:00
|
|
|
if (oldData.menuSelectedChallengeId && !data.menuSelectedChallengeId &&
|
|
|
|
|
!data.isSearching) { this.rightMenu(); }
|
2018-10-16 19:22:21 -07:00
|
|
|
// Keyboard close.
|
2018-10-16 21:28:27 -07:00
|
|
|
if (oldData.isSearching && !data.isSearching && !data.menuSelectedChallengeId) {
|
|
|
|
|
this.rightMenu();
|
|
|
|
|
}
|
|
|
|
|
return;
|
2018-10-16 19:22:21 -07:00
|
|
|
}
|
|
|
|
|
|
2018-10-16 21:28:27 -07:00
|
|
|
if (!this.isLeft) {
|
2018-10-16 19:22:21 -07:00
|
|
|
// Select.
|
2018-10-16 21:28:27 -07:00
|
|
|
if (!oldData.menuSelectedChallengeId && data.menuSelectedChallengeId) { this.leftMenu(); }
|
2018-10-16 19:22:21 -07:00
|
|
|
// Keyboard open.
|
2018-10-16 21:28:27 -07:00
|
|
|
if (!oldData.isSearching && data.isSearching) { this.leftMenu(); }
|
2018-10-16 19:22:21 -07:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2018-10-16 21:28:27 -07:00
|
|
|
rightMenu: function () {
|
|
|
|
|
if (!this.isLeft) { return; }
|
2018-10-16 19:22:21 -07:00
|
|
|
this.el.components.animation__menuright.beginAnimation();
|
2018-10-16 21:28:27 -07:00
|
|
|
this.isLeft = false;
|
2018-10-16 19:22:21 -07:00
|
|
|
},
|
|
|
|
|
|
2018-10-16 21:28:27 -07:00
|
|
|
leftMenu: function () {
|
|
|
|
|
if (this.isLeft) { return; }
|
2018-10-16 19:22:21 -07:00
|
|
|
this.el.components.animation__menuleft.beginAnimation();
|
2018-10-16 21:28:27 -07:00
|
|
|
this.isLeft = true;
|
2018-10-16 19:22:21 -07:00
|
|
|
}
|
|
|
|
|
});
|