Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
This commit is contained in:
parent
93e3a48004
commit
b38dea0597
25901 changed files with 9982925 additions and 369 deletions
20
assets/webapps/verticalhome.gaiamobile.org/js/app.js
Normal file
20
assets/webapps/verticalhome.gaiamobile.org/js/app.js
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
;'use strict';(function(exports){const HIDDEN_ROLES=['system','input','homescreen','theme','addon','langpack'];const EDIT_MODE_TRANSITION_STYLE='transform 0.25s ease 0s, height 0s ease 0.5s';function App(){window.performance.mark('navigationLoaded');this.grid=document.getElementById('icons');this.grid.addEventListener('iconblobdecorated',this);this.grid.addEventListener('gaiagrid-iconbloberror',this);this.grid.addEventListener('gaiagrid-attention',this);this.grid.addEventListener('gaiagrid-resize',this);this.grid.addEventListener('cached-icons-rendered',this);this.grid.addEventListener('edititem',this);this.grid.addEventListener('editmode-start',this);this.grid.addEventListener('editmode-end',this);window.addEventListener('hashchange',this);window.addEventListener('gaiagrid-saveitems',this);window.addEventListener('online',this.retryFailedIcons.bind(this));var editModeDone=document.getElementById('exit-edit-mode');editModeDone.addEventListener('click',this.exitEditMode);window.addEventListener('gaiagrid-dragdrop-begin',this);window.addEventListener('gaiagrid-dragdrop-finish',this);window.addEventListener('context-menu-open',this);window.addEventListener('context-menu-close',this);window.addEventListener('gaia-confirm-open',this);window.addEventListener('gaia-confirm-close',this);this.layoutReady=false;window.addEventListener('gaiagrid-layout-ready',this);this._iconsToRetry=[];document.addEventListener('visibilitychange',this);window.performance.mark('navigationInteractive');}
|
||||
App.prototype={HIDDEN_ROLES:HIDDEN_ROLES,EDIT_MODE_TRANSITION_STYLE:EDIT_MODE_TRANSITION_STYLE,retryFailedIcons:function(){if(!this._iconsToRetry.length){return;}
|
||||
var icons=this.grid.getIcons();var iconId;while((iconId=this._iconsToRetry.shift())){var icon=icons[iconId];if(!icon){continue;}
|
||||
icon.renderIcon();}},init:function(){this.itemStore=new ItemStore((firstTime)=>{if(!firstTime){return;}
|
||||
LazyLoader.load(['shared/js/icc_helper.js','shared/js/version_helper.js','js/configurator.js'],function onLoad(){exports.configurator=new Configurator();});});this.itemStore.all(function _all(results){results.forEach(function _eachResult(result){this.grid.add(result);},this);if(this.layoutReady){this.renderGrid();}else{window.addEventListener('gaiagrid-layout-ready',function onReady(){window.removeEventListener('gaiagrid-layout-ready',onReady);this.renderGrid();}.bind(this));}
|
||||
window.performance.mark('visuallyLoaded');window.performance.mark('contentInteractive');window.addEventListener('localized',this.onLocalized.bind(this));LazyLoader.load(['shared/elements/gaia-header/dist/gaia-header.js','js/contextmenu_handler.js','/shared/js/homescreens/confirm_dialog_helper.js'],function(){window.performance.mark('fullyLoaded');});}.bind(this));},renderGrid:function(){this.grid.setEditHeaderElement(document.getElementById('edit-header'));this.grid.render();},start:function(){this.grid.start();},stop:function(){this.grid.stop();},onLocalized:function(){var items=this.grid.getItems();items.forEach(function eachItem(item){if(!item.name){return;}
|
||||
item.updateTitle();});this.renderGrid();},exitEditMode:function(e){e.preventDefault();window.dispatchEvent(new CustomEvent('hashchange'));},handleEvent:function(e){switch(e.type){case'cached-icons-rendered':window.dispatchEvent(new CustomEvent('gaiagrid-cached-icons-rendered'));break;case'iconblobdecorated':var item=e.detail;this.itemStore.saveItem(item.detail,()=>{item.element.classList.add('test-icon-cached');});break;case'edititem':var icon=e.detail;if(icon.detail.type!='divider'){return;}
|
||||
LazyLoader.load('js/edit_group.js',()=>{groupEditor.edit(icon);});break;case'gaiagrid-iconbloberror':this._iconsToRetry.push(e.detail.identifier);break;case'gaiagrid-attention':var offsetTop=this.grid.offsetTop;var scrollTop=window.scrollY;var gridHeight=document.body.clientHeight;if(this.grid._grid.dragdrop.inEditMode){gridHeight-=offsetTop;}else{scrollTop-=offsetTop;}
|
||||
var rect=e.detail;if(scrollTop+gridHeight<rect.y+rect.height){scrollTop=(rect.y+rect.height)-gridHeight;}
|
||||
if(scrollTop>rect.y){scrollTop=rect.y;}
|
||||
if(!this.grid._grid.dragdrop.inEditMode){scrollTop+=offsetTop;}
|
||||
if(scrollTop!==window.scrollY){document.body.style.overflow='';requestAnimationFrame(()=>{requestAnimationFrame(()=>{window.scrollTo({left:0,top:scrollTop,behavior:'smooth'});});});}
|
||||
break;case'gaiagrid-resize':var height=e.detail;var oldHeight=this.grid.clientHeight;if(this.gridResizeTimeout!==null){clearTimeout(this.gridResizeTimeout);this.gridResizeTimeout=null;}
|
||||
if(height<oldHeight){var viewHeight=document.body.clientHeight;var scrollBottom=window.scrollY+viewHeight;var padding=window.getComputedStyle?parseInt(window.getComputedStyle(this.grid).paddingBottom):0;var maxScrollBottom=height+this.grid.offsetTop+padding;if(scrollBottom>=maxScrollBottom){requestAnimationFrame(()=>{requestAnimationFrame(()=>{window.scrollTo({left:0,top:maxScrollBottom-viewHeight,behavior:'smooth'});});});}}
|
||||
if(height===oldHeight){break;}
|
||||
this.grid.style.height=height+'px';break;case'gaiagrid-saveitems':this.itemStore.save(this.grid.getItems());break;case'context-menu-open':case'gaia-confirm-open':document.body.classList.add('fixed-overlay-shown');case'gaiagrid-dragdrop-begin':window.removeEventListener('hashchange',this);break;case'context-menu-close':case'gaia-confirm-close':document.body.classList.remove('fixed-overlay-shown');case'gaiagrid-dragdrop-finish':window.addEventListener('hashchange',this);break;case'gaiagrid-layout-ready':this.layoutReady=true;window.removeEventListener('gaiagrid-layout-ready',this);break;case'visibilitychange':if(document.hidden){document.body.style.overflow='hidden';}else{setTimeout(function(){document.body.style.overflow='';});}
|
||||
break;case'editmode-start':this.grid.style.transition=this.EDIT_MODE_TRANSITION_STYLE;break;case'editmode-end':this.grid.style.transition='';break;case'hashchange':var editor=exports.groupEditor;if(editor&&!editor.hidden){return;}
|
||||
var _grid=this.grid._grid;if(_grid.dragdrop&&_grid.dragdrop.inEditMode){_grid.dragdrop.exitEditMode();return;}
|
||||
if(document.hidden){return;}
|
||||
window.scrollTo({left:0,top:0,behavior:'smooth'});}}};exports.configurator={getSingleVariantApp:function(){return{};},get isSingleVariantReady(){return true;},get isSimPresentOnFirstBoot(){return false;},getItems:function(role){return{};}};exports.app=new App();exports.app.init();}(window));
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
;'use strict';(function(exports){function AppManager(){var grid=document.querySelector('gaia-grid');var self=this;navigator.mozApps.getSelf().onsuccess=function(evt){self.app=evt.target.result;window.dispatchEvent(new CustomEvent('appmanager-ready'));};grid.addEventListener('removeitem',this);}
|
||||
AppManager.prototype={dialogVisible:false,get self(){return this.app;},handleItemRemoval:function(item){function errorLogger(err){console.error('Error while trying to remove',item.name,err);}
|
||||
switch(item.detail.type){case'bookmark':BookmarksDatabase.remove(item.identifier).catch(errorLogger);break;default:console.error('Cannot handle remove for item type ',item.detail.type);}},handleEvent:function(e){var nameObj={name:e.detail&&e.detail.name};switch(e.type){case'removeitem':if(this.dialogVisible){return;}
|
||||
this.dialogVisible=true;if(e.detail.detail.type=='app'){var request=navigator.mozApps.mgmt.uninstall(e.detail.app);request.onsuccess=()=>{e.detail.removeFromGrid();this.dialogVisible=false;};request.onerror=()=>{console.error('Error while trying to remove',e.detail.name,request.error);this.dialogVisible=false;};break;}
|
||||
var dialog=new ConfirmDialogHelper({type:'remove',title:{id:'delete-title',args:nameObj},body:{id:'delete-body',args:nameObj},cancel:{title:'cancel',cb:()=>{this.dialogVisible=false;}},confirm:{title:'delete',type:'danger',cb:()=>{e.detail.removeFromGrid();this.handleItemRemoval(e.detail);this.dialogVisible=false;}}});dialog.show(document.body);break;}}};exports.appManager=new AppManager();}(window));
|
||||
245
assets/webapps/verticalhome.gaiamobile.org/js/configurator.js
Normal file
245
assets/webapps/verticalhome.gaiamobile.org/js/configurator.js
Normal file
|
|
@ -0,0 +1,245 @@
|
|||
/* global IccHelper, verticalPreferences,
|
||||
VersionHelper, LazyLoader */
|
||||
/* exported configurator */
|
||||
|
||||
'use strict';
|
||||
|
||||
(function(exports) {
|
||||
|
||||
// We're going to use the mcc_mnc as a semaphore as well as to store its
|
||||
// value during the singleVariant file's processing time.
|
||||
var mcc_mnc;
|
||||
|
||||
// Globar configuration
|
||||
var conf = {};
|
||||
|
||||
// Path of the single variant configuration file
|
||||
var SINGLE_VARIANT_CONF_FILE = 'js/singlevariantconf.json';
|
||||
|
||||
// Keeps the list of single variant apps, indexed by manifestURL
|
||||
var singleVariantApps = {};
|
||||
var simPresentOnFirstBoot = true;
|
||||
|
||||
function loadSettingSIMPresent(currentMccMnc) {
|
||||
var settings = navigator.mozSettings;
|
||||
if (!settings) {
|
||||
console.log('Settings is not available');
|
||||
return;
|
||||
}
|
||||
var req = settings.createLock().get('ftu.simPresentOnFirstBoot');
|
||||
|
||||
req.onsuccess = function osv_success(e) {
|
||||
var simOnFirstBoot = req.result['ftu.simPresentOnFirstBoot'];
|
||||
simPresentOnFirstBoot = !simOnFirstBoot ||
|
||||
req.result['ftu.simPresentOnFirstBoot'] === currentMccMnc;
|
||||
};
|
||||
|
||||
req.onerror = function osv_error(e) {
|
||||
console.error('Error retrieving ftu.simPresentOnFirstBoot. ' + e);
|
||||
};
|
||||
}
|
||||
|
||||
function loadSingleVariantConf() {
|
||||
if (!IccHelper) {
|
||||
console.error('IccHelper isn\'t enabled. SingleVariant configuration' +
|
||||
' can\'t be loaded');
|
||||
return;
|
||||
}
|
||||
// Given a number returns a three characters string padding with zeroes
|
||||
// to the left until the desired length (3) is reached
|
||||
function normalizeCode(aCode) {
|
||||
var ncode = '' + aCode;
|
||||
while (ncode.length < 3) {
|
||||
ncode = '0' + ncode;
|
||||
}
|
||||
return ncode;
|
||||
}
|
||||
|
||||
var getMccMnc = function getMccMnc() {
|
||||
if (IccHelper.iccInfo) {
|
||||
var mcc = IccHelper.iccInfo.mcc;
|
||||
var mnc = IccHelper.iccInfo.mnc;
|
||||
if ((mcc !== undefined) && (mcc !== null) &&
|
||||
(mnc !== undefined) && (mnc !== null)) {
|
||||
return normalizeCode(mcc) + '-' + normalizeCode(mnc);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function dispatchSVReadyEvent() {
|
||||
mcc_mnc = undefined;
|
||||
window.dispatchEvent(new CustomEvent('singlevariant-ready'));
|
||||
}
|
||||
|
||||
function loadSVConfFileSuccess(loadedData) {
|
||||
try {
|
||||
loadSettingSIMPresent(mcc_mnc);
|
||||
singleVariantApps = {};
|
||||
if (loadedData && loadedData[mcc_mnc]) {
|
||||
loadedData[mcc_mnc].forEach(function(app) {
|
||||
if (app.manifestURL) {
|
||||
singleVariantApps[app.manifestURL] = app;
|
||||
} else if (app.id) {
|
||||
singleVariantApps[app.id] = app;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.log('There is not singleVariant configuration for ' +
|
||||
mcc_mnc);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('There was an error loading singleVariant configuration',
|
||||
e);
|
||||
} finally {
|
||||
dispatchSVReadyEvent();
|
||||
}
|
||||
}
|
||||
|
||||
function loadSVConfFileError(e) {
|
||||
singleVariantApps = {};
|
||||
if (e.name === 'NS_ERROR_FILE_NOT_FOUND') {
|
||||
console.log('No single variant configuration file found');
|
||||
} else {
|
||||
console.error('Failed parsing singleVariant configuration file [' +
|
||||
SINGLE_VARIANT_CONF_FILE + ']: ', e);
|
||||
}
|
||||
dispatchSVReadyEvent();
|
||||
}
|
||||
|
||||
var iccHandler = function(evt) {
|
||||
mcc_mnc = getMccMnc();
|
||||
if (mcc_mnc) {
|
||||
IccHelper.removeEventListener('iccinfochange', iccHandler);
|
||||
LazyLoader.getJSON(SINGLE_VARIANT_CONF_FILE).then(
|
||||
loadSVConfFileSuccess, loadSVConfFileError
|
||||
);
|
||||
// No needed anymore
|
||||
iccHandler = null;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
if (!iccHandler()) { // Maybe we already have the mcc and mnc...
|
||||
IccHelper.addEventListener('iccinfochange', iccHandler);
|
||||
}
|
||||
}
|
||||
|
||||
function onLoadInitJSON(loadedData) {
|
||||
conf = loadedData;
|
||||
setupColumns();
|
||||
window.dispatchEvent(new CustomEvent('configuration-ready'));
|
||||
loadSingleVariantConf();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the default columns.
|
||||
*/
|
||||
function setupColumns() {
|
||||
var defaultCols = conf && conf.preferences &&
|
||||
conf.preferences['grid.cols'] || undefined;
|
||||
|
||||
if (defaultCols) {
|
||||
verticalPreferences.get('grid.cols').then(function(cols) {
|
||||
// Set the number of cols by default in preference's datastore
|
||||
!cols && verticalPreferences.put('grid.cols', defaultCols);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function onErrorInitJSON(e) {
|
||||
conf = {};
|
||||
console.error('Failed parsing homescreen configuration file:' + e);
|
||||
window.dispatchEvent(new CustomEvent('configuration-ready'));
|
||||
loadSingleVariantConf();
|
||||
}
|
||||
|
||||
function handlerGridLayout(evt) {
|
||||
switch(evt.type) {
|
||||
case 'updated':
|
||||
if (evt.target.name === 'grid.layout') {
|
||||
verticalPreferences.removeEventListener('updated', handlerGridLayout);
|
||||
onLoadInitJSON(evt.target.value);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function load() {
|
||||
conf = {};
|
||||
|
||||
VersionHelper.getVersionInfo().then(function(verInfo) {
|
||||
if (verInfo.isUpgrade()) {
|
||||
verticalPreferences.get('grid.layout').then(function(grid) {
|
||||
if (!grid) {
|
||||
verticalPreferences.addEventListener('updated', handlerGridLayout);
|
||||
} else {
|
||||
onLoadInitJSON(grid);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
LazyLoader.getJSON('js/init.json').then(
|
||||
onLoadInitJSON, onErrorInitJSON
|
||||
);
|
||||
}
|
||||
}, function(err) {
|
||||
console.error('VersionHelper failed to lookup version settings, ' +
|
||||
'asumming no version upgrade.\n');
|
||||
});
|
||||
}
|
||||
|
||||
function Configurator() {
|
||||
load();
|
||||
}
|
||||
|
||||
Configurator.prototype = {
|
||||
getSection: function(section) {
|
||||
return conf[section];
|
||||
},
|
||||
|
||||
getGrid: function() {
|
||||
return conf.grid;
|
||||
},
|
||||
|
||||
getItems: function(role) {
|
||||
var items = {};
|
||||
|
||||
conf.grid.forEach(function forEachSection(section) {
|
||||
section.forEach(function forEachItem(item) {
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
if (item.role === role) {
|
||||
items[item.id] = item;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return items;
|
||||
},
|
||||
|
||||
getSingleVariantApp: function(manifestURL) {
|
||||
if (manifestURL in singleVariantApps) {
|
||||
var svApp = singleVariantApps[manifestURL];
|
||||
if (svApp.location !== undefined) {
|
||||
return svApp;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
get isSingleVariantReady() {
|
||||
return !mcc_mnc;
|
||||
},
|
||||
|
||||
load: load,
|
||||
|
||||
get isSimPresentOnFirstBoot() {
|
||||
return simPresentOnFirstBoot;
|
||||
},
|
||||
|
||||
loadSettingSIMPresent: loadSettingSIMPresent
|
||||
};
|
||||
|
||||
exports.Configurator = Configurator;
|
||||
|
||||
}(window));
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
'use strict';
|
||||
/* global LazyLoader, contextMenuUI */
|
||||
|
||||
(function(exports) {
|
||||
|
||||
function ContextMenuHandler() {
|
||||
this.container = document.getElementById('icons').parentNode;
|
||||
this.container.addEventListener('contextmenu', this);
|
||||
this.container.addEventListener('touchstart', this);
|
||||
window.addEventListener('hashchange', this);
|
||||
}
|
||||
|
||||
ContextMenuHandler.prototype = {
|
||||
handleEvent: function(e) {
|
||||
switch(e.type) {
|
||||
case 'touchstart':
|
||||
this.canceled = e.touches.length > 1;
|
||||
break;
|
||||
|
||||
case 'contextmenu':
|
||||
if (this.canceled || app.grid._grid.dragdrop.inEditMode) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Prevent the click when the finger is released
|
||||
e.preventDefault();
|
||||
|
||||
var resources = ['/shared/js/component_utils.js',
|
||||
'/shared/elements/gaia_buttons/script.js',
|
||||
'/shared/elements/gaia_menu/script.js',
|
||||
'js/contextmenu_ui.js'];
|
||||
LazyLoader.load(resources, function loaded() {
|
||||
// pass the event through for processing
|
||||
setTimeout(() => { contextMenuUI.show(e); });
|
||||
});
|
||||
|
||||
break;
|
||||
|
||||
case 'hashchange':
|
||||
window.contextMenuUI && contextMenuUI.hide();
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
exports.contextMenuHandler = new ContextMenuHandler();
|
||||
|
||||
}(window));
|
||||
|
|
@ -0,0 +1,93 @@
|
|||
'use strict';
|
||||
/* global LazyLoader */
|
||||
/* global MozActivity */
|
||||
/* global wallpaper */
|
||||
/* jshint nonew: false */
|
||||
|
||||
(function(exports) {
|
||||
|
||||
function ContextMenuUI() {
|
||||
this.grid = document.getElementById('icons');
|
||||
this.dialog = document.getElementById('contextmenu-dialog');
|
||||
this.wallpaperOption = document.getElementById('change-wallpaper-action');
|
||||
this.settingsOption = document.getElementById('homescreen-settings-action');
|
||||
|
||||
this.handleCancel = this._handleCancel.bind(this);
|
||||
}
|
||||
|
||||
ContextMenuUI.prototype = {
|
||||
show: function(e) {
|
||||
var nearestIndex = this.grid._grid.getNearestItemIndex(
|
||||
e.pageX,
|
||||
e.pageY - this.grid.offsetTop
|
||||
);
|
||||
|
||||
window.dispatchEvent(new CustomEvent('context-menu-open', {
|
||||
detail: {
|
||||
nearestIndex: nearestIndex
|
||||
}
|
||||
}));
|
||||
|
||||
this.dialog.addEventListener('gaiamenu-cancel', this.handleCancel);
|
||||
this.dialog.removeAttribute('hidden');
|
||||
this.wallpaperOption.addEventListener('click', this);
|
||||
this.settingsOption.addEventListener('click', this);
|
||||
window.addEventListener('visibilitychange', this);
|
||||
},
|
||||
|
||||
hide: function() {
|
||||
this.dialog.removeEventListener('gaiamenu-cancel', this.handleCancel);
|
||||
this.dialog.setAttribute('hidden', '');
|
||||
this.wallpaperOption.removeEventListener('click', this);
|
||||
this.settingsOption.removeEventListener('click', this);
|
||||
window.removeEventListener('visibilitychange', this);
|
||||
|
||||
window.dispatchEvent(new CustomEvent('context-menu-close'));
|
||||
},
|
||||
|
||||
_handleCancel: function(e) {
|
||||
this.hide();
|
||||
},
|
||||
|
||||
_actions: {
|
||||
'change-wallpaper-action': function() {
|
||||
LazyLoader.load([
|
||||
'shared/js/omadrm/fl.js',
|
||||
'js/wallpaper.js'
|
||||
], function() {
|
||||
this.hide();
|
||||
wallpaper.change();
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
'homescreen-settings-action': function() {
|
||||
this.hide();
|
||||
|
||||
new MozActivity({
|
||||
name: 'configure',
|
||||
data: {
|
||||
target: 'device',
|
||||
section: 'homescreens-list'
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
handleEvent: function(e) {
|
||||
switch (e.type) {
|
||||
case 'click':
|
||||
this._actions[e.target.id].call(this);
|
||||
break;
|
||||
|
||||
case 'visibilitychange':
|
||||
if (document.hidden) {
|
||||
this.hide();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
exports.contextMenuUI = new ContextMenuUI();
|
||||
|
||||
}(window));
|
||||
95
assets/webapps/verticalhome.gaiamobile.org/js/edit_group.js
Normal file
95
assets/webapps/verticalhome.gaiamobile.org/js/edit_group.js
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
'use strict';
|
||||
|
||||
/* global LazyLoader */
|
||||
|
||||
(function(exports) {
|
||||
|
||||
var resources = ['shared/style/input_areas.css', 'style/css/edit_group.css'];
|
||||
|
||||
function GroupEditor() {
|
||||
this.container = document.getElementById('edit-group');
|
||||
this.header = document.getElementById('edit-group-header');
|
||||
this.save = document.getElementById('edit-group-save');
|
||||
this.form = this.container.querySelector('form');
|
||||
this.clear = document.getElementById('edit-group-title-clear');
|
||||
this.nameField = document.getElementById('edit-group-title');
|
||||
}
|
||||
|
||||
GroupEditor.prototype = {
|
||||
handleEvent: function(e) {
|
||||
switch(e.type) {
|
||||
case 'click':
|
||||
case 'submit':
|
||||
this.group.name = this.nameField.value;
|
||||
this.close();
|
||||
break;
|
||||
|
||||
case 'action':
|
||||
case 'hashchange':
|
||||
this.nameField.blur();
|
||||
this.close();
|
||||
break;
|
||||
|
||||
case 'touchstart':
|
||||
e.preventDefault();
|
||||
this.nameField.value = '';
|
||||
this.checkSaveAction();
|
||||
break;
|
||||
|
||||
case 'input':
|
||||
this.checkSaveAction();
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
edit: function(group) {
|
||||
LazyLoader.load(resources, () => {
|
||||
this.group = group;
|
||||
this.attachHandlers();
|
||||
this.nameField.value = group.name || '';
|
||||
this.checkSaveAction();
|
||||
document.body.classList.add('edit-group');
|
||||
this.container.hidden = false;
|
||||
setTimeout(() => {
|
||||
this.nameField.focus();
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
close: function() {
|
||||
this.removeHandlers();
|
||||
this.container.hidden = true;
|
||||
document.body.classList.remove('edit-group');
|
||||
},
|
||||
|
||||
checkSaveAction: function() {
|
||||
var name = this.nameField.value.trim();
|
||||
this.save.disabled = name === this.group.name;
|
||||
},
|
||||
|
||||
attachHandlers: function() {
|
||||
this.header.addEventListener('action', this);
|
||||
this.save.addEventListener('click', this);
|
||||
this.form.addEventListener('input', this);
|
||||
this.form.addEventListener('submit', this);
|
||||
this.clear.addEventListener('touchstart', this);
|
||||
window.addEventListener('hashchange', this);
|
||||
},
|
||||
|
||||
removeHandlers: function() {
|
||||
this.header.removeEventListener('action', this);
|
||||
this.save.removeEventListener('click', this);
|
||||
this.form.removeEventListener('input', this);
|
||||
this.form.removeEventListener('submit', this);
|
||||
this.clear.removeEventListener('touchstart', this);
|
||||
window.removeEventListener('hashchange', this);
|
||||
},
|
||||
|
||||
get hidden() {
|
||||
return this.container.hidden;
|
||||
}
|
||||
};
|
||||
|
||||
exports.groupEditor = new GroupEditor();
|
||||
|
||||
})(window);
|
||||
1
assets/webapps/verticalhome.gaiamobile.org/js/init.json
Normal file
1
assets/webapps/verticalhome.gaiamobile.org/js/init.json
Normal file
File diff suppressed because one or more lines are too long
4
assets/webapps/verticalhome.gaiamobile.org/js/search.js
Normal file
4
assets/webapps/verticalhome.gaiamobile.org/js/search.js
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
;(function(exports){'use strict';function Search(){this._port=null;this.connected=false;this.pendingRender=false;if(!appManager.app){window.addEventListener('appmanager-ready',function onReady(){window.removeEventListener('appmanager-ready',onReady);this.onAppReady();}.bind(this));}else{this.onAppReady();}
|
||||
var input=document.getElementById('search');input.addEventListener('click',this.open.bind(this));input.addEventListener('contextmenu',(e)=>{e.stopPropagation();});}
|
||||
Search.prototype={onAppReady:function onAppReady(){appManager.app.connect('search-results').then(function onConnectionAccepted(ports){ports.forEach(function(port){this._port=port;}.bind(this));this.connected=true;if(this.pendingRender){this.open();}}.bind(this),function onConnectionRejected(){});},open:function openRocketbar(e){window.scrollTo(0,0);e.stopPropagation();e.preventDefault();if(!this.connected){this.pendingRender=true;return;}
|
||||
this._port.postMessage({action:'render'});}};exports.search=new Search();})(window);
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
;'use strict';(function(exports){var appMgr=navigator.mozApps.mgmt;var apps=null;window.performance.mark('homescreenStart@system.gaiamobile.org');appMgr.getAll().onsuccess=function onsuccess(event){apps=event.target.result;window.dispatchEvent(new CustomEvent('navigator-mozapps-ready'));};function ApplicationSource(store){this.store=store;this.entries=[];this.entriesByManifestUrl={};this.svPreviouslyInstalledApps=[];var pendingInstallRequests=[];function addSVEventListener(){window.addEventListener('singlevariant-ready',function svFileReady(ev){window.removeEventListener('singlevariant-ready',svFileReady);for(var i=0;i<pendingInstallRequests;i++){pendingInstallRequests[i]();}});}
|
||||
addSVEventListener();var self=this;function addIcons(){window.removeEventListener('navigator-mozapps-ready',addIcons);for(var i=0,iLen=apps.length;i<iLen;i++){self.makeIcons(apps[i]);}
|
||||
apps=null;}
|
||||
apps?addIcons():window.addEventListener('navigator-mozapps-ready',addIcons);function install(application){var manifest=application.manifest||application.updateManifest;if(manifest.role&&app.HIDDEN_ROLES.indexOf(manifest.role)!==-1){return;}
|
||||
this.addIconToGrid(application);var svApp=configurator.getSingleVariantApp(application.manifestURL);var lastElem=app.grid.getIndexLastIcon();if(configurator.isSimPresentOnFirstBoot&&svApp&&svApp.location<lastElem&&!this.isPreviouslyInstalled(application.manifestURL)){app.grid.popDivider();app.grid.removeNonVisualElements();lastElem=app.grid.getIndexLastIcon();app.grid.moveTo(lastElem,svApp.location);_moveAhead(svApp.location+1);this.addPreviouslyInstalledSvApp(application.manifestURL);app.itemStore.savePrevInstalledSvApp(this.svPreviouslyInstalledApps);}
|
||||
app.grid.render();app.itemStore.deferredSave(app.grid.getItems());}
|
||||
function _moveAhead(startPos){var elems=app.grid.getItems();for(var i=startPos,iLen=elems.length;i<iLen;i++){var item=elems[i];if(item instanceof GaiaGrid.Mozapp){var svApp=configurator.getSingleVariantApp(elems[i].identifier);if(svApp&&i>svApp.location){app.grid.moveTo(i,i-1);}}}}
|
||||
appMgr.oninstall=function oninstall(event){if(configurator.isSingleVariantReady){install.bind(this)(event.application);}else{pendingInstallRequests.push(install.bind(this,event.application));}}.bind(this);appMgr.onuninstall=function onuninstall(event){var application=event.application;var manifest=application.updateManifest||application.manifest;this.removeIconFromGrid(application.manifestURL);app.itemStore.deferredSave(app.grid.getItems());if(app.HIDDEN_ROLES.indexOf(manifest.role)!==-1){return;}}.bind(this);}
|
||||
ApplicationSource.prototype={synchronize:function(){var storeItems=this.store._allItems;var toAdd=[];var appIconsByManifestUrl={};for(var i=0,iLen=storeItems.length;i<iLen;i++){var item=storeItems[i];if(!(item instanceof GaiaGrid.Mozapp)){continue;}
|
||||
appIconsByManifestUrl[item.detail.manifestURL]=item;}
|
||||
for(i=0,iLen=this.entries.length;i<iLen;i++){var entry=this.entries[i];var manifest=entry.app.updateManifest||entry.app.manifest;if(!appIconsByManifestUrl[entry.detail.manifestURL]&&!manifest.entry_points){toAdd.push(entry);}else{delete appIconsByManifestUrl[entry.detail.manifestURL];}}
|
||||
for(i in appIconsByManifestUrl){this.removeIconFromGrid(i);}
|
||||
toAdd.forEach(function _toAdd(newApp){this.addIconToGrid(newApp.app);},this);app.itemStore.deferredSave(app.grid.getItems());},addIconToGrid:function(application){this.makeIcons(application);var appObject=this.mapToApp({manifestURL:application.manifestURL});app.grid.appendItemToExpandedGroup(appObject);app.grid.render();},removeIconFromGrid:function(manifestURL){var icons=app.grid.getIcons();var appObject=icons[manifestURL];if(appObject){appObject.removeFromGrid();}},populate:function(success){success(this.entries);},makeIcons:function(eachApp){var manifest=eachApp.manifest||eachApp.updateManifest;if(app.HIDDEN_ROLES.indexOf(manifest.role)!==-1){return;}
|
||||
function eachIcon(icon){if(!icon.icon){return;}
|
||||
icon.setPosition(this.store.getNextPosition());this.entries.push(icon);}
|
||||
this.entriesByManifestUrl[eachApp.manifestURL]=eachApp;if(manifest.entry_points){for(var i in manifest.entry_points){eachIcon.call(this,new GaiaGrid.Mozapp(eachApp,i));}}else{eachIcon.call(this,new GaiaGrid.Mozapp(eachApp));}},mapToApp:function(entry){var app=this.entriesByManifestUrl[entry.manifestURL];app=app||{manifestURL:entry.manifestURL,manifest:{name:'',icons:[]}};return new GaiaGrid.Mozapp(app,entry.entryPoint,{decoratedIconBlob:entry.decoratedIconBlob});},addPreviouslyInstalledSvApp:function(manifest){this.svPreviouslyInstalledApps.push({manifestURL:manifest});},isPreviouslyInstalled:function(manifest){for(var i=0,elemNum=this.svPreviouslyInstalledApps.length;i<elemNum;i++){if(this.svPreviouslyInstalledApps[i].manifestURL===manifest){return true;}}
|
||||
return false;}};exports.ApplicationSource=ApplicationSource;}(window));
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
;'use strict';(function(exports){var eventTypesToListenFor=['added','updated','removed'];function BookmarkSource(store){this.store=store;this.entries=[];eventTypesToListenFor.forEach(function iterateTypes(type){BookmarksDatabase.addEventListener(type,this);},this);}
|
||||
BookmarkSource.prototype={synchronize:function(){var allAppBookmarks={};var toAdd=[];var icons=app.grid.getIcons();for(var i in icons){var icon=icons[i];if(icon.detail.type!=='bookmark'){continue;}
|
||||
allAppBookmarks[icon.detail.url]=icon;}
|
||||
for(var j=0,jLen=this.entries.length;j<jLen;j++){var entry=this.entries[j];if(!allAppBookmarks[entry.detail.url]){toAdd.push(entry);}else{delete allAppBookmarks[entry.detail.url];}}
|
||||
for(i in allAppBookmarks){this.removeIconFromGrid(allAppBookmarks[i].detail.url);}
|
||||
for(i=0;i<toAdd.length;i++){this.addIconToGrid(toAdd[i].detail);}
|
||||
app.itemStore.deferredSave(app.grid.getItems());},populate:function(success){var self=this;BookmarksDatabase.getAll().then(function(systemBookmarks){Object.keys(systemBookmarks).forEach(function(id){self.entries.push(new GaiaGrid.Bookmark(systemBookmarks[id]));});success(self.entries);},success);},handleEvent:function(e){switch(e.type){case'added':case'updated':this.addIconToGrid(e.target);app.itemStore.deferredSave(app.grid.getItems());break;case'removed':var id=e.target.id;this.removeIconFromGrid(id);break;}},addIconToGrid:function(detail){var icons=app.grid.getIcons();var existing=icons[detail.id];if(existing){existing.update(detail);app.grid.render();return;}
|
||||
var bookmark=new GaiaGrid.Bookmark(detail);bookmark.setPosition(this.store.getNextPosition());this.entries.push(bookmark);app.grid.appendItemToExpandedGroup(bookmark);app.grid.render();},removeIconFromGrid:function(url){var icons=app.grid.getIcons();var appObject=icons[url];if(appObject){appObject.removeFromGrid();}}};exports.BookmarkSource=BookmarkSource;}(window));
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
;'use strict';(function(exports){const APPEARANCE={OPAQUE:'opaque',SEMI_TRANSPARENT:'semi-transparent'};function StatusBar(){this.threshold=document.getElementById('search').clientHeight;if(!appManager.app){window.addEventListener('appmanager-ready',function onReady(){window.removeEventListener('appmanager-ready',onReady);this.onAppReady();}.bind(this));}else{this.onAppReady();}}
|
||||
StatusBar.prototype={handleEvent:function(e){switch(e.type){case'editmode-start':window.removeEventListener('context-menu-open',this);window.removeEventListener('context-menu-close',this);window.removeEventListener('gaia-confirm-open',this);window.removeEventListener('gaia-confirm-close',this);case'context-menu-open':case'gaia-confirm-open':window.removeEventListener('scroll',this);this.setAppearance(APPEARANCE.OPAQUE);break;case'editmode-end':window.addEventListener('context-menu-open',this);window.addEventListener('context-menu-close',this);window.addEventListener('gaia-confirm-open',this);window.addEventListener('gaia-confirm-close',this);case'context-menu-close':case'gaia-confirm-close':window.addEventListener('scroll',this);case'scroll':this.setAppearance(this.calculateAppearance());break;case'visibilitychange':if(document.hidden){break;}
|
||||
this.appearance=null;this.setAppearance(this.calculateAppearance());break;}},onAppReady:function(){var grid=app.grid;window.addEventListener('scroll',this);grid.addEventListener('editmode-start',this);grid.addEventListener('editmode-end',this);window.addEventListener('context-menu-close',this);window.addEventListener('context-menu-open',this);window.addEventListener('gaia-confirm-open',this);window.addEventListener('gaia-confirm-close',this);window.addEventListener('visibilitychange',this);this.setAppearance(APPEARANCE.SEMI_TRANSPARENT);},calculateAppearance:function(){return window.scrollY>this.threshold?APPEARANCE.OPAQUE:APPEARANCE.SEMI_TRANSPARENT;},setAppearance:function(value){if(this.appearance===value){return;}
|
||||
this.appearance=value;var meta=document.head.querySelector('meta[name="theme-color"]');if(value==APPEARANCE.OPAQUE){meta.content='black';}else{meta.content='transparent';}}};exports.statusBar=new StatusBar();}(window));
|
||||
35
assets/webapps/verticalhome.gaiamobile.org/js/stores/item.js
Normal file
35
assets/webapps/verticalhome.gaiamobile.org/js/stores/item.js
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
;'use strict';(function(exports){const DB_VERSION=1;const DB_NAME='verticalhome';const DB_ITEM_STORE='items';const DB_SV_APP_STORE_NAME='svAppsInstalled';const DATASTORE_NAME='verticalhome_items_migration';const PREFS_STORE='vertical_preferences_store';var db;var datastore;function sort(entries,order){if(!order||!order.length){return entries;}
|
||||
var newEntries=[];function isEqual(lookFor,compareWith){if(!compareWith.detail||!lookFor){return false;}
|
||||
if(compareWith instanceof GaiaGrid.Mozapp){if(!lookFor.manifestURL||!compareWith.detail.manifestURL){return false;}
|
||||
if(compareWith.detail.entryPoint){return lookFor.manifestURL===compareWith.detail.manifestURL&&lookFor.entry_point===compareWith.detail.entryPoint;}else{return lookFor.manifestURL===compareWith.detail.manifestURL;}}else if(compareWith instanceof GaiaGrid.Bookmark){if(!lookFor.id||!compareWith.detail.id){return false;}
|
||||
return lookFor.id===compareWith.detail.id;}}
|
||||
for(var i=0,iLen=order.length;i<iLen;i++){for(var j=0,jLen=order[i].length;j<jLen;j++){var ind=entries.findIndex(isEqual.bind(null,order[i][j]));if(ind>=0){newEntries.push(entries.splice(ind,1)[0]);}}
|
||||
if(i<iLen-1){newEntries.push(new GaiaGrid.Divider());}}
|
||||
if(entries.length>0){if(configurator.isSimPresentOnFirstBoot){sortUnclassifiedApps(newEntries,entries);}else{newEntries.push(new GaiaGrid.Divider());newEntries=newEntries.concat(entries);}}
|
||||
for(i=0,iLen=newEntries.length;i<iLen;i++){if(newEntries[i].detail){newEntries[i].detail.index=i;}}
|
||||
return newEntries;}
|
||||
function sortUnclassifiedApps(dstEntries,orgEntries){function compareApps(appA,appB){var svAppA=null;var svAppB=null;if(appA){svAppA=configurator.getSingleVariantApp(appA.detail.manifestURL);}
|
||||
if(appB){svAppB=configurator.getSingleVariantApp(appB.detail.manifestURL);}
|
||||
var locA=svAppA&&svAppA.location!==undefined&&svAppA.location||Number.MAX_VALUE;var locB=svAppB&&svAppB.location!==undefined&&svAppB.location||Number.MAX_VALUE;var relPos=locA-locB;return relPos?(relPos>0?1:-1):0;}
|
||||
orgEntries.sort(compareApps);if(!configurator.getSingleVariantApp(orgEntries[0].detail.manifestURL)){dstEntries.push(new GaiaGrid.Divider());dstEntries=dstEntries.concat(orgEntries);}else{var sepAdded=false;for(var i=0,iLen=orgEntries.length;i<iLen;i++){var app=orgEntries[i];var svApp=configurator.getSingleVariantApp(app.detail.manifestURL);if(!svApp){if(!sepAdded){dstEntries.push(new GaiaGrid.Divider());sepAdded=true;}
|
||||
dstEntries.push(app);}else{if(svApp.location!==undefined){dstEntries.splice(svApp.location,0,app);}else{dstEntries.push(app);}}}}}
|
||||
function loadTable(table,indexName,iterator,aNext){newTxn(table,'readonly',function(txn,store){var index=store.index(indexName);index.openCursor().onsuccess=function onsuccess(event){var cursor=event.target.result;if(!cursor){return;}
|
||||
iterator(cursor.value);cursor.continue();};},aNext);}
|
||||
function newTxn(storeName,txnType,withTxnAndStore,successCb){var txn=db.transaction([storeName],txnType);var store=txn.objectStore(storeName);txn.oncomplete=function(event){if(successCb){successCb(event);}};txn.onerror=function(event){console.warn('Error during transaction.');};withTxnAndStore(txn,store);}
|
||||
function ItemStore(onsuccess){var self=this;this.applicationSource=new ApplicationSource(this);this.bookmarkSource=new BookmarkSource(this);this.sources=[this.applicationSource,this.bookmarkSource];this.ready=false;var isEmpty=false;self.gridOrder=null;var request=window.indexedDB.open(DB_NAME,DB_VERSION);request.onupgradeneeded=function _onupgradeneeded(event){var db=event.target.result;var oldVersion=event.oldVersion||0;switch(oldVersion){case 0:var objectStore=db.createObjectStore(DB_ITEM_STORE,{keyPath:'index'});objectStore.createIndex('index','index',{unique:true});isEmpty=true;var objectSV=db.createObjectStore(DB_SV_APP_STORE_NAME,{keyPath:'manifestURL'});objectSV.createIndex('indexSV','indexSV',{unique:true});}};request.onsuccess=function _onsuccess(){onsuccess&&onsuccess(isEmpty);db=request.result;var cb=self.fetch.bind(self,self.synchronize.bind(self));if(isEmpty){window.addEventListener('configuration-ready',function onReady(){window.removeEventListener('configuration-ready',onReady);self.gridOrder=configurator.getGrid();self.populate(cb);});}else{self.initSources(cb);}
|
||||
navigator.mozSetMessageHandler('connection',self.handleIAC.bind(self));};window.addEventListener('gaiagrid-cached-icons-rendered',this);}
|
||||
ItemStore.prototype={_renderedOnce:false,_deferredSaveArgs:[],_allItems:[],nextPosition:0,all:function(success){if(!this.ready){window.addEventListener('databaseready',this.all.bind(this,success));return;}
|
||||
success(this._allItems);},saveTable:function(table,objArr,column,checkPersist,aNext){newTxn(table,'readwrite',function(txn,store){store.clear();for(var i=0,iLen=objArr.length;i<iLen;i++){if(!checkPersist||(checkPersist&&objArr[i].persistToDB)){store.put(column?objArr[i][column]:objArr[i]);}}
|
||||
if(typeof aNext==='function'){aNext();}});},saveMigrationData:function(objArr,column,checkPersist){return datastore.clear().then(()=>{var chain=[];objArr.forEach((object)=>{if(!checkPersist||object.persistToDB){var data=column?object[column]:object;chain.push(datastore.put(data,data.index+1));}});return Promise.all(chain);});},saveItem:function(object,callback){if(object.index==null){console.error('Attempting to save object without `index`');return;}
|
||||
newTxn(DB_ITEM_STORE,'readwrite',function(txn,store){store.put(object);},callback);},deferredSave:function(){var args=Array.slice(arguments);if(this._renderedOnce){return this.save.apply(this,args);}
|
||||
this._deferredSaveArgs=args;},save:function(entries,aNext){entries=sort(entries,this.gridOrder);this.gridOrder=null;this.saveTable(DB_ITEM_STORE,entries,'detail',true,aNext);},savePrevInstalledSvApp:function(svApps,aNext){this.saveTable(DB_SV_APP_STORE_NAME,svApps,null,false,aNext);},fetch:function(callback){var cached={};var collected=[];function iterator(value){collected.push(value);}
|
||||
function iteratorSV(value){this.applicationSource.addPreviouslyInstalledSvApp(value.manifestURL);}
|
||||
loadTable(DB_SV_APP_STORE_NAME,'indexSV',iteratorSV.bind(this));loadTable(DB_ITEM_STORE,'index',iterator,finish.bind(this));function addIfUnique(item){if(!cached[item.identifier]){cached[item.identifier]=true;this._allItems.push(item);}}
|
||||
function finish(){for(var i=0,iLen=collected.length;i<iLen;i++){var thisItem=collected[i];if(thisItem.type==='app'){var itemObj=this.applicationSource.mapToApp(thisItem);addIfUnique.call(this,itemObj);}else if(thisItem.type==='divider'){var divider=new GaiaGrid.Divider(thisItem);this._allItems.push(divider);}else if(thisItem.type==='bookmark'){var bookmark=new GaiaGrid.Bookmark(thisItem);addIfUnique.call(this,bookmark);}}
|
||||
this.notifyReady();if(callback&&typeof callback==='function'){callback();}}},synchronize:function(){this.sources.forEach(function eachSource(source){source.synchronize();});},initSources:function(callback){var pending=this.sources.length;var allEntries=[];var self=this;var current=0;function handleSource(){var source=self.sources[current];current++;source.populate(next);}
|
||||
handleSource();function next(entries){allEntries=allEntries.concat(entries);if(!(--pending)){callback(allEntries);}else{handleSource();}}},populate:function(callback){this.initSources(function(entries){this.deferredSave(entries,callback);}.bind(this));},notifyReady:function(){this.ready=true;dispatchEvent(new CustomEvent('databaseready'));},getNextPosition:function(){var nextPosition=this.nextPosition;this.nextPosition++;return nextPosition;},handleIAC:function(connectionRequest){if(connectionRequest.keyword!=='verticalhome-migrate'){return;}
|
||||
var port=connectionRequest.port;port.onmessage=(event)=>{if(event.data.action!=='migrate'){console.error('Unhandled migration action requested:',event.data.action);return;}
|
||||
this.migrate(event.data.manifestURL);};port.start();},migrate:function(manifestURL){this.migratingTo=manifestURL;console.info('verticalhome migrating to '+this.migratingTo);if(this.migrating){return;}
|
||||
this.migrating=true;(datastore?Promise.resolve():navigator.getDataStores(DATASTORE_NAME).then(stores=>{datastore=stores[0];return Promise.resolve();},(e)=>{return Promise.reject(e);})).then(()=>{this.all(entries=>{this.saveMigrationData(entries,'detail',true).then(()=>{this.migrating=false;window.navigator.mozSettings.createLock().set({'homescreen.manifestURL':this.migratingTo});navigator.getDataStores(PREFS_STORE).then(stores=>{if(stores.length<1){console.error('Error opening verticalhome prefs datastore');return;}
|
||||
stores[0].put('migrated',true).then(()=>{window.close();},e=>{console.error('Error storing migration pref',e);window.close();});});});});},e=>{console.error('Error retrieving datastore',e);});},handleEvent:function(e){switch(e.type){case'gaiagrid-cached-icons-rendered':this._renderedOnce=true;window.removeEventListener('gaiagrid-cached-icons-rendered',this);if(this._deferredSaveArgs.length){this.save.apply(this,this._deferredSaveArgs);}
|
||||
break;}}};exports.ItemStore=ItemStore;}(window));
|
||||
59
assets/webapps/verticalhome.gaiamobile.org/js/wallpaper.js
Normal file
59
assets/webapps/verticalhome.gaiamobile.org/js/wallpaper.js
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
'use strict';
|
||||
/* global ForwardLock, MozActivity */
|
||||
|
||||
(function(exports) {
|
||||
|
||||
function Wallpaper() {
|
||||
// Do nothing...
|
||||
}
|
||||
|
||||
Wallpaper.prototype = {
|
||||
change: function() {
|
||||
// Ask for the locked content key first, because if it does not exist
|
||||
// we know there is no locked content on the phone and we don't have
|
||||
// to show the Locked Content app in the activity request.
|
||||
ForwardLock.getKey(function(secret) {
|
||||
var activity = new MozActivity({
|
||||
name: 'pick',
|
||||
data: {
|
||||
type: ['wallpaper', 'image/*'],
|
||||
includeLocked: (secret !== null),
|
||||
// XXX: This will not work with Desktop Fx / Simulator.
|
||||
width: Math.ceil(window.screen.width * window.devicePixelRatio),
|
||||
height: Math.ceil(window.screen.height * window.devicePixelRatio)
|
||||
}
|
||||
});
|
||||
|
||||
activity.onsuccess = function onWallpaperSuccess() {
|
||||
var blob = activity.result.blob;
|
||||
|
||||
if (!blob) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If this is a locked image from the locked content app, unlock it
|
||||
if (blob.type.split('/')[1] === ForwardLock.mimeSubtype) {
|
||||
ForwardLock.unlockBlob(secret, blob, function(unlocked) {
|
||||
setWallpaper(unlocked);
|
||||
});
|
||||
} else {
|
||||
setWallpaper(blob);
|
||||
}
|
||||
|
||||
function setWallpaper(blob) {
|
||||
navigator.mozSettings.createLock().set({
|
||||
'wallpaper.image': blob
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
activity.onerror = function onWallpaperError() {
|
||||
console.warn('pick failed!');
|
||||
};
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
exports.wallpaper = new Wallpaper();
|
||||
|
||||
}(window));
|
||||
Loading…
Reference in a new issue