Merge branch 'feature/categories' into develop

This commit is contained in:
William Petit 2015-08-26 20:18:04 +02:00
commit 011168b6a1
5 changed files with 282 additions and 35 deletions

View File

@ -3,21 +3,51 @@
}
html, body {
padding: 1Opx 10px;
padding: 0;
margin: 0;
font-family: 'Droid Sans', 'Ubuntu Sans', sans-serif;
background: url('../img/background.png') no-repeat;
background-size: contain;
background-position: center;
background-color: rgb(34, 107, 160);
}
body, ul.apps-list {
width: 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;
margin: 0;
padding: 0;
@ -28,10 +58,10 @@ ul.apps-list {
justify-content: center;
align-items: center;
align-content: center;
flex-grow: 1;
}
li.app-item {
background-color: red;
.launcher li.app-item {
margin: 5px;
border-radius: 5px;
background-color: rgba(0,0,0,0.4);
@ -43,9 +73,10 @@ li.app-item {
transition: 150ms linear;
position: relative;
overflow: hidden;
min-width: 150px;
}
li.app-item::after {
.launcher li.app-item::after {
content: ' ';
display: block;
border-radius: 50%;
@ -57,22 +88,24 @@ li.app-item::after {
top: -75%;
}
li.app-item:hover {
.launcher li.app-item:hover {
background-color: rgba(0,0,0,0.6);
}
li.app-item > .app-icon {
.launcher li.app-item > .app-icon {
width: 70%;
height: auto;
}
li.app-item > .app-label {
.launcher li.app-item > .app-label {
display: block;
text-align: center;
color: white;
}
li.app-item.loading {
/* Animations */
.pulse {
-webkit-animation: 1s pulse infinite;
}
@ -81,3 +114,29 @@ li.app-item.loading {
50% { transform: scale(1.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,9 +1,38 @@
{
"items": [
{
"label": "Level 1",
"icon": "/usr/share/icons/Mint-X/apps/48/chromium-browser.png",
"items": [
{
"label": "Level 2-1",
"icon": "/usr/share/icons/Mint-X/apps/48/chromium-browser.png",
"items": [
{
"label": "Chromium Browser",
"exec": "/usr/bin/chromium-browser",
"icon": "/usr/share/icons/Mint-X/apps/48/chromium-browser.png"
"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",
"items": [
{
"label": "Chromium Browser",
"icon": "/usr/share/icons/Mint-X/apps/48/chromium-browser.png",
"exec": "/usr/bin/chromium-browser"
}
]
}
]
}
]
}
]
}

View File

@ -9,19 +9,38 @@
<div id="pitaya"></div>
<!-- Templates -->
<script id="launcher-view-tpl" type="text/x-template">
<div class="launcher">
{{#unless isRoot}}
<div class="category-header">
<a href="#" class="goback" data-item-path="{{currentItemPath}}">&#9668;</a>
<span class="category-label">{{currentItem.label}}</span>
</div>
{{/unless}}
{{> itemListTpl}}
</div>
</script>
<script id="items-list-tpl" type="text/x-template">
<ul class="apps-list">
{{#each items}}
<li data-exec="{{exec}}" class="app-item">
<img class="app-icon" src="{{icon}}" />
<span class="app-label">{{label}}</span>
</li>
{{#each currentItem.items}}
{{> itemTpl currentItemPath=../currentItemPath}}
{{/each}}
</ul>
</script>
<script id="item-tpl" type="text/x-template">
<li class="app-item"
data-item-path="{{currentItemPath}}.{{@index}}">
<img class="app-icon" src="{{icon}}" />
<span class="app-label">{{label}}</span>
</li>
</script>
<!-- Scripts -->
<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>
<!-- 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));

146
js/app.js
View File

@ -10,8 +10,12 @@
var gui = require('nw.gui');
var minimist = require('minimist');
// Load templates
var itemsListTpl = Handlebars.compile(Pitaya.DOM.select('#items-list-tpl').innerHTML);
// Load templates...
var launcherViewTpl = Handlebars.compile(Pitaya.DOM.select('#launcher-view-tpl').innerHTML);
// ... and partials
Handlebars.registerPartial('itemListTpl', Pitaya.DOM.select('#items-list-tpl').innerHTML);
Handlebars.registerPartial('itemTpl', Pitaya.DOM.select('#item-tpl').innerHTML);
// Internal constants
var DEFAULT_PROFILE = './default-profile.json';
@ -34,6 +38,7 @@
.then(function() {
return Pitaya;
})
.catch(Pitaya._onError)
;
};
@ -48,7 +53,7 @@
return Pitaya._loadJSONFile(profilePath)
.then(function(profile) {
Pitaya._profile = profile;
Pitaya.render();
Pitaya.renderLauncherView();
return profile;
})
;
@ -59,10 +64,20 @@
*
* @return Pitaya
*/
Pitaya.render = function() {
Pitaya.renderLauncherView = function(currentItemPath) {
currentItemPath = Pitaya._normalizeItemPath(currentItemPath);
var rootEl = Pitaya._rootEl;
var profile = Pitaya._profile;
rootEl.innerHTML = itemsListTpl(profile);
var currentItem = Pitaya._getItemByPath(currentItemPath);
var data = {
currentItemPath: currentItemPath.join('.'),
currentItem: currentItem,
isRoot: currentItemPath.length === 0
};
rootEl.innerHTML = launcherViewTpl(data);
};
@ -73,6 +88,7 @@
Pitaya._initListeners = function() {
var rootEl = Pitaya._rootEl;
rootEl.addEventListener('click', Pitaya._onItemClick);
rootEl.addEventListener('click', Pitaya._onGoBackClick);
};
/**
@ -87,19 +103,114 @@
if( !appItemEl ) return;
var execPath = appItemEl.dataset.exec;
var itemPath = appItemEl.dataset.itemPath;
var item = Pitaya._getItemByPath(itemPath);
console.info('Launching application "'+execPath+'"...');
if(!item) return;
if(execPath) {
appItemEl.classList.add('loading');
cp.exec(execPath, function(err) {
appItemEl.classList.remove('loading');
if(err) return console.error(err.stack || err);
console.info('Application closed "'+execPath+'".');
});
if('items' in item) {
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('pulse');
Pitaya._runApp(item.exec)
.then(function() {
appItemEl.classList.remove('pulse');
})
.catch(function(err) {
Pitaya._onError(err);
appItemEl.classList.remove('pulse');
})
;
}
};
/**
* GoBack button click handler
* @private
*/
Pitaya._onGoBackClick = function(evt) {
var goBackEl = evt.srcElement.matches( '.goback') ? evt.srcElement :
Pitaya.DOM.getClosestAncestor(evt.srcElement, '.goback')
;
if(!goBackEl) return;
var currentItemPath = goBackEl.dataset.itemPath;
var parentItemPath = Pitaya._normalizeItemPath(currentItemPath);
parentItemPath.pop();
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');
})
;
};
Pitaya._normalizeItemPath = function(itemPath) {
if( Array.isArray(itemPath) ) return itemPath;
if((typeof itemPath === 'string' && itemPath.length === 0) || !itemPath) return [];
return itemPath.split('.').reduce(function(arr, index) {
if(index !== '') {
arr.push(+index);
}
return arr;
}, []);
};
Pitaya._getItemByPath = function(itemPath, rootItem) {
rootItem = rootItem || Pitaya._profile;
itemPath = Pitaya._normalizeItemPath(itemPath);
var itemIndex = itemPath[0];
if(itemIndex === undefined) {
return rootItem;
}
if(!('items' in rootItem)) {
return undefined;
}
var subItem = rootItem.items[itemIndex];
if(itemPath.length === 0) {
return subItem;
}
return Pitaya._getItemByPath(itemPath.slice(1), subItem);
};
Pitaya._runApp = function(execPath) {
return new Promise(function(resolve, reject) {
cp.exec(execPath, function(err) {
if(err) return reject(err);
return resolve();
});
});
};
/**
@ -123,4 +234,9 @@
});
};
Pitaya._onError = function(err) {
console.error(err.stack ? err.stack : err);
};
}(window.Pitaya = window.Pitaya || {}, window));