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

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

View File

@ -3,21 +3,51 @@
} }
html, body { html, body {
padding: 1Opx 10px; padding: 0;
margin: 0; margin: 0;
font-family: 'Droid Sans', 'Ubuntu Sans', sans-serif; font-family: 'Droid Sans', 'Ubuntu Sans', sans-serif;
background: url('../img/background.png') no-repeat; background: url('../img/background.png') no-repeat;
background-size: contain; background-size: contain;
background-position: center; background-position: center;
background-color: rgb(34, 107, 160); background-color: rgb(34, 107, 160);
}
body, ul.apps-list {
width: 100%; width: 100%;
height: 100%; height: 100%;
color: white;
overflow-x: hidden;
} }
ul.apps-list { /* Launcher View */
.launcher {
display: flex;
width: 100%;
height: 100%;
flex-direction: column;
}
.launcher .category-header {
padding: 40px 50px 0;
font-size: 50px;
}
.launcher .category-header a.goback {
text-decoration: none;
color: white;
}
.launcher .category-header a.goback:hover {
-webkit-animation: 500ms pulse-large infinite;
}
.launcher .category-header > .category-label {
float: right;
}
.launcher .category-header .goback {
font-weight: normal;
}
.launcher ul.apps-list {
display: block; display: block;
margin: 0; margin: 0;
padding: 0; padding: 0;
@ -28,10 +58,10 @@ ul.apps-list {
justify-content: center; justify-content: center;
align-items: center; align-items: center;
align-content: center; align-content: center;
flex-grow: 1;
} }
li.app-item { .launcher li.app-item {
background-color: red;
margin: 5px; margin: 5px;
border-radius: 5px; border-radius: 5px;
background-color: rgba(0,0,0,0.4); background-color: rgba(0,0,0,0.4);
@ -43,10 +73,10 @@ li.app-item {
transition: 150ms linear; transition: 150ms linear;
position: relative; position: relative;
overflow: hidden; overflow: hidden;
min-width: 10%; min-width: 150px;
} }
li.app-item::after { .launcher li.app-item::after {
content: ' '; content: ' ';
display: block; display: block;
border-radius: 50%; border-radius: 50%;
@ -58,22 +88,24 @@ li.app-item::after {
top: -75%; top: -75%;
} }
li.app-item:hover { .launcher li.app-item:hover {
background-color: rgba(0,0,0,0.6); background-color: rgba(0,0,0,0.6);
} }
li.app-item > .app-icon { .launcher li.app-item > .app-icon {
width: 70%; width: 70%;
height: auto; height: auto;
} }
li.app-item > .app-label { .launcher li.app-item > .app-label {
display: block; display: block;
text-align: center; text-align: center;
color: white; color: white;
} }
li.app-item.loading { /* Animations */
.pulse {
-webkit-animation: 1s pulse infinite; -webkit-animation: 1s pulse infinite;
} }
@ -82,3 +114,29 @@ li.app-item.loading {
50% { transform: scale(1.1); } 50% { transform: scale(1.1); }
100% { transform: scale(1); } 100% { transform: scale(1); }
} }
@-webkit-keyframes pulse-large {
0% { transform: scale(1); }
50% { transform: scale(1.5); }
100% { transform: scale(1); }
}
@-webkit-keyframes slide-in-left {
0% { transform: translateX(-100%); }
100% { transform: translateX(0%); }
}
@-webkit-keyframes slide-in-right {
0% { transform: translateX(100%); }
100% { transform: translateX(0%); }
}
@-webkit-keyframes slide-out-left {
0% { transform: translateX(0%); }
100% { transform: translateX(-100%); }
}
@-webkit-keyframes slide-out-right {
0% { transform: translateX(0%); }
100% { transform: translateX(100%); }
}

View File

@ -1,11 +1,26 @@
{ {
"items": [ "items": [
{ {
"label": "Root", "label": "Level 1",
"icon": "/usr/share/icons/Mint-X/apps/48/chromium-browser.png", "icon": "/usr/share/icons/Mint-X/apps/48/chromium-browser.png",
"items": [ "items": [
{ {
"label": "Level 1", "label": "Level 2-1",
"icon": "/usr/share/icons/Mint-X/apps/48/chromium-browser.png",
"items": [
{
"label": "Chromium Browser",
"icon": "/usr/share/icons/Mint-X/apps/48/chromium-browser.png",
"exec": "/usr/bin/chromium-browser"
}
]
},
{
"label": "Level 2-2",
"icon": "/usr/share/icons/Mint-X/apps/48/chromium-browser.png",
"items": [
{
"label": "Level 3-1",
"icon": "/usr/share/icons/Mint-X/apps/48/chromium-browser.png", "icon": "/usr/share/icons/Mint-X/apps/48/chromium-browser.png",
"items": [ "items": [
{ {
@ -18,4 +33,6 @@
] ]
} }
] ]
}
]
} }

View File

@ -11,12 +11,15 @@
<!-- Templates --> <!-- Templates -->
<script id="launcher-view-tpl" type="text/x-template"> <script id="launcher-view-tpl" type="text/x-template">
<div class="launcher">
{{#unless isRoot}} {{#unless isRoot}}
<div class="category-header"> <div class="category-header">
<h2><a href="#" class="goback" data-item-path="{{currentItemPath}}">&#8678;</a> {{currentItem.label}}</h2> <a href="#" class="goback" data-item-path="{{currentItemPath}}">&#9668;</a>
<span class="category-label">{{currentItem.label}}</span>
</div> </div>
{{/unless}} {{/unless}}
{{> itemListTpl}} {{> itemListTpl}}
</div>
</script> </script>
<script id="items-list-tpl" type="text/x-template"> <script id="items-list-tpl" type="text/x-template">
@ -37,6 +40,7 @@
<!-- Scripts --> <!-- Scripts -->
<script type="text/javascript" src="js/dom.js"></script> <script type="text/javascript" src="js/dom.js"></script>
<script type="text/javascript" src="js/anim.js"></script>
<script type="text/javascript" src="js/app.js"></script> <script type="text/javascript" src="js/app.js"></script>
<!-- Application bootstrapping --> <!-- Application bootstrapping -->

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