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
|
|
@ -0,0 +1,147 @@
|
|||
/* global LazyLoader */
|
||||
|
||||
(function(exports) {
|
||||
'use strict';
|
||||
|
||||
var resources = ['/shared/js/component_utils.js',
|
||||
'/shared/elements/gaia_buttons/script.js',
|
||||
'/shared/elements/gaia_confirm/script.js',
|
||||
'/shared/elements/gaia_menu/script.js'];
|
||||
/**
|
||||
Generic dialog helper this _depends_ on <gaia-confirm> but is not required
|
||||
to be loaded as part of the main gaia-confirm script.
|
||||
*/
|
||||
function ConfirmDialogHelper(config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
ConfirmDialogHelper.prototype = {
|
||||
show: function(parent) {
|
||||
LazyLoader.load(resources, this._show.bind(this, parent));
|
||||
},
|
||||
|
||||
_show: function(parent) {
|
||||
var config = this.config;
|
||||
var wrapper = document.createElement('div');
|
||||
|
||||
// only include a cancel button if the config was given...
|
||||
var cancelButton = config.cancel ?
|
||||
'<button class="cancel" type="button"></button>' :
|
||||
'';
|
||||
|
||||
wrapper.innerHTML =
|
||||
'<gaia-confirm>' +
|
||||
'<h1></h1>' +
|
||||
'<p></p>' +
|
||||
'<gaia-buttons skin="dark">' +
|
||||
cancelButton +
|
||||
'<button class="confirm" type="button"></button>' +
|
||||
'</gaia-buttons>' +
|
||||
'</gaia-confirm>';
|
||||
|
||||
var element = wrapper.firstElementChild;
|
||||
|
||||
this.element = element;
|
||||
|
||||
element.dataset.type = config.type;
|
||||
element.addEventListener('confirm', this);
|
||||
element.addEventListener('cancel', this);
|
||||
|
||||
// XXX: Primarily here for pressing the home screen button.
|
||||
// The home button triggers a hashchange of the homescreen.
|
||||
window.addEventListener('hashchange', this);
|
||||
// TODO: Add visibility change handling...
|
||||
|
||||
var title = element.querySelector('h1');
|
||||
var body = element.querySelector('p');
|
||||
var cancel = element.querySelector('.cancel');
|
||||
var confirm = element.querySelector('.confirm');
|
||||
|
||||
var setL10nAttributes = function (element, options){
|
||||
if ('string' === typeof options) {
|
||||
navigator.mozL10n.setAttributes(element, options);
|
||||
}
|
||||
|
||||
if(options.id) {
|
||||
navigator.mozL10n.setAttributes(element, options.id, options.args);
|
||||
}
|
||||
};
|
||||
|
||||
setL10nAttributes(title, config.title);
|
||||
setL10nAttributes(body, config.body);
|
||||
setL10nAttributes(confirm, config.confirm.title);
|
||||
|
||||
if (config.cancel) {
|
||||
setL10nAttributes(cancel, config.cancel.title);
|
||||
}
|
||||
|
||||
if (config.confirm.type) {
|
||||
confirm.classList.add(config.confirm.type);
|
||||
}
|
||||
|
||||
document.activeElement.blur();
|
||||
element.setAttribute('hidden', '');
|
||||
parent.appendChild(element);
|
||||
|
||||
// This nested requestAnimationFrame is to work around the coalescing
|
||||
// of the style changes associated with removing of the 'hidden'
|
||||
// attribute with the creation of the element.
|
||||
// For whatever reason, flushing the style with the usual trick of
|
||||
// accessing clientTop doesn't work, and a setTimeout requires an
|
||||
// unreasonably lengthy timeout (>50ms) to work, and that may not be
|
||||
// a reliable solution.
|
||||
// This work-around, though gross, appears to work consistently without
|
||||
// introducing too much lag or extra work.
|
||||
window.requestAnimationFrame(() => {
|
||||
window.requestAnimationFrame(() => {
|
||||
element.removeAttribute('hidden');
|
||||
window.dispatchEvent(new CustomEvent('gaia-confirm-open'));
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
destroy: function() {
|
||||
if (!this.element) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Ensure cleanup of our hacks!
|
||||
window.removeEventListener('hashchange', this);
|
||||
|
||||
this.element.addEventListener('transitionend',
|
||||
function removeAfterHide(e) {
|
||||
if (e.target !== this.element) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.element.parentNode.removeChild(this.element);
|
||||
this.element = null;
|
||||
window.dispatchEvent(new CustomEvent('gaia-confirm-close'));
|
||||
}.bind(this));
|
||||
|
||||
this.element.setAttribute('hidden', '');
|
||||
},
|
||||
|
||||
handleEvent: function(e) {
|
||||
// Ensure we hide the dialog in the face of other errors.
|
||||
this.destroy();
|
||||
|
||||
switch (e.type) {
|
||||
case 'hashchange':
|
||||
// Hashchange is only here to trigger this to call destroy.
|
||||
break;
|
||||
case 'confirm':
|
||||
var confirm = this.config.confirm.cb;
|
||||
confirm && confirm();
|
||||
break;
|
||||
case 'cancel':
|
||||
var cancel = this.config.cancel.cb;
|
||||
cancel && cancel();
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// This name is intentionally verbose.
|
||||
window.ConfirmDialogHelper = ConfirmDialogHelper;
|
||||
}(window));
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
;'use strict';(function(exports){const FETCH_XHR_TIMEOUT=10000;function fetchBlob(uri){return new Promise(function(accept,reject){var xhr=new XMLHttpRequest({mozAnon:true,mozSystem:true});xhr.open('GET',uri,true);xhr.responseType='blob';xhr.timeout=FETCH_XHR_TIMEOUT;xhr.send();xhr.onload=function(){var status=xhr.status;if(status!==0&&status!==200){reject(new Error('Got HTTP status '+status+' trying to load '+uri));return;}
|
||||
accept(xhr.response);};xhr.onerror=xhr.ontimeout=function(){reject(new Error('Error while HTTP GET: ',uri));};});}
|
||||
function Icon(elem,uri){this.elem=elem;this.uri=uri;}
|
||||
Icon.prototype={get size(){return this._size||40;},set size(size){this._size=size||this.size;var style=this.elem.style;var sizeInRems=(this._size/10)+'rem';style.backgroundSize=style.width=style.height=sizeInRems;},render:function render(options){options=options||{};var uri=this.uri;this.size=options.size;if(!uri){return;}
|
||||
fetchBlob(uri).then(function(blob){this.renderBlob(blob,options);}.bind(this));},renderBlob:function renderBlob(blob,options){options=options||{};var style=this.elem.style;this.size=options.size;var img=new Image();img.src=URL.createObjectURL(blob);var size=this.size;img.onload=()=>{var renderer=new GridIconRenderer({grid:{layout:{get gridIconSize(){return size;},get gridMaxIconSize(){return size*devicePixelRatio;}}}});var type=options.type||GridIconRenderer.TYPE.FAVICON;renderer[type](img).then((blob)=>{var url=URL.createObjectURL(blob);var imageUrl='url('+url+')';style.backgroundImage=imageUrl;if(options.onLoad){options.onLoad(blob);}});URL.revokeObjectURL(img.src);};img.onerror=()=>{if(options.onerror){options.onerror();}};}};exports.Icon=Icon;}(window));
|
||||
Loading…
Reference in a new issue