Gestion d'un nombre arbitraire de sous catégories + transitions

This commit is contained in:
2015-08-26 20:17:18 +02:00
parent 5b1cec8789
commit d6dad43b3f
5 changed files with 145 additions and 37 deletions

24
js/anim.js Normal file
View File

@ -0,0 +1,24 @@
(function(Pitaya, window) {
"use strict";
var Anim = Pitaya.Anim = {};
var Events = Anim.Events = {
ANIMATION_END: 'webkitAnimationEnd'
};
Anim.play = function(el, animation) {
return new Promise(function(resolve, reject) {
el.addEventListener(Events.ANIMATION_END, onAnimEnd, false);
el.style.webkitAnimation = animation;
function onAnimEnd(evt) {
el.removeEventListener(Events.ANIMATION_END, onAnimEnd);
return resolve(el);
}
});
};
}(window.Pitaya = window.Pitaya || {}, window));

View File

@ -66,8 +66,6 @@
*/
Pitaya.renderLauncherView = function(currentItemPath) {
console.log('render', currentItemPath);
currentItemPath = Pitaya._normalizeItemPath(currentItemPath);
var rootEl = Pitaya._rootEl;
var currentItem = Pitaya._getItemByPath(currentItemPath);
@ -78,8 +76,6 @@
isRoot: currentItemPath.length === 0
};
console.log('render data', data);
rootEl.innerHTML = launcherViewTpl(data);
};
@ -110,27 +106,30 @@
var itemPath = appItemEl.dataset.itemPath;
var item = Pitaya._getItemByPath(itemPath);
console.log('item click',itemPath, item);
if(!item) return;
if('items' in item) {
return Pitaya.renderLauncherView(itemPath);
var rootEl = Pitaya._rootEl;
Pitaya.Anim.play(rootEl, 'slide-out-left 250ms ease-in-out')
.then(function() {
Pitaya.renderLauncherView(itemPath);
return Pitaya.Anim.play(rootEl, 'slide-in-right 250ms ease-in-out');
})
;
}
if(item.exec) {
console.info('Launching application "'+item.exec+'"...');
appItemEl.classList.add('loading');
appItemEl.classList.add('pulse');
Pitaya._runApp(item.exec)
.then(function() {
appItemEl.classList.remove('loading');
console.info('Application closed "'+item.exec+'".');
appItemEl.classList.remove('pulse');
})
.catch(function(err) {
Pitaya._onError(err);
appItemEl.classList.remove('loading');
appItemEl.classList.remove('pulse');
})
;
@ -155,7 +154,13 @@
parentItemPath.pop();
return Pitaya.renderLauncherView(parentItemPath);
var rootEl = Pitaya._rootEl;
Pitaya.Anim.play(rootEl, 'slide-out-right 250ms ease-in-out')
.then(function() {
Pitaya.renderLauncherView(parentItemPath);
return Pitaya.Anim.play(rootEl, 'slide-in-left 250ms ease-in-out');
})
;
};
@ -179,9 +184,9 @@
rootItem = rootItem || Pitaya._profile;
itemPath = Pitaya._normalizeItemPath(itemPath);
var index = itemPath.slice(0,1)[0];
var itemIndex = itemPath[0];
if(index === undefined) {
if(itemIndex === undefined) {
return rootItem;
}
@ -189,13 +194,13 @@
return undefined;
}
var subItem = rootItem.items[index];
var subItem = rootItem.items[itemIndex];
if(itemPath.length === 0) {
return subItem;
}
return Pitaya._getItemByPath(itemPath, subItem);
return Pitaya._getItemByPath(itemPath.slice(1), subItem);
};