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
63
gaia/shared/js/manifest_helper.js
Executable file
63
gaia/shared/js/manifest_helper.js
Executable file
|
|
@ -0,0 +1,63 @@
|
|||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
|
||||
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
||||
|
||||
// Start Outer IIFE
|
||||
(function(exports) {
|
||||
'use strict';
|
||||
|
||||
// helper function, bound to manifest and property name in constructor
|
||||
function ManifestHelper_get(prop) {
|
||||
var manifest = this;
|
||||
var value = manifest[prop];
|
||||
|
||||
var lang = document.documentElement.lang || '';
|
||||
|
||||
if (manifest.locales) {
|
||||
// try to replace values from the locales object using the best language
|
||||
// match. stop when a replacement is found
|
||||
[lang, lang.substr(0, lang.indexOf('-'))].some(function tryLanguage(lang) {
|
||||
// this === manifest.locales
|
||||
if (this[lang] && this[lang][prop]) {
|
||||
value = this[lang][prop];
|
||||
// aborts [].some
|
||||
return true;
|
||||
}
|
||||
}, manifest.locales);
|
||||
}
|
||||
|
||||
// return a new ManifestHelper for any object children
|
||||
if (typeof value === 'object' && !(value instanceof Array)) {
|
||||
value = new ManifestHelper(value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper object to access manifest information with locale support.
|
||||
*
|
||||
* @constructor
|
||||
* @param {Object} manifest The app manifest.
|
||||
*/
|
||||
function ManifestHelper(manifest) {
|
||||
// Bind getters for the localized property values.
|
||||
for (var prop in manifest) {
|
||||
Object.defineProperty(this, prop, {
|
||||
get: ManifestHelper_get.bind(manifest, prop),
|
||||
enumerable: true
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for display name (short_name if defined, otherwise name).
|
||||
*/
|
||||
Object.defineProperty(ManifestHelper.prototype, 'displayName', {
|
||||
get: function displayName() {
|
||||
return this.short_name || this.name;
|
||||
}
|
||||
});
|
||||
|
||||
exports.ManifestHelper = ManifestHelper;
|
||||
|
||||
// End outer IIFE
|
||||
}(window));
|
||||
Loading…
Reference in a new issue