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
91
gaia/apps/clock/js/picker/picker.js
Executable file
91
gaia/apps/clock/js/picker/picker.js
Executable file
|
|
@ -0,0 +1,91 @@
|
|||
define(function(require) {
|
||||
'use strict';
|
||||
var Spinner = require('picker/spinner');
|
||||
|
||||
/**
|
||||
* Picker
|
||||
*
|
||||
* Create an inline "picker", comprised of n "spinners".
|
||||
*
|
||||
* @param {Object} setup An object containing setup data.
|
||||
* - element, The container element.
|
||||
* - pickers, an object whose properties
|
||||
* correspond to a Picker that will
|
||||
* be created.
|
||||
*
|
||||
*
|
||||
* new Picker({
|
||||
* element: 'time-picker',
|
||||
* pickers: {
|
||||
* hours: {
|
||||
* range: [0, 24],
|
||||
* l10nId: 'nSpinnerHours'
|
||||
* },
|
||||
* minutes: {
|
||||
* range: [0, 60],
|
||||
* isPadded: true,
|
||||
* l10nId: 'nSpinnerMinutes'
|
||||
* }
|
||||
* }
|
||||
* });
|
||||
*
|
||||
*/
|
||||
function Picker(setup) {
|
||||
this.nodes = {};
|
||||
this.spinners = {};
|
||||
this.pickers = Object.keys(setup.pickers);
|
||||
|
||||
this.pickers.forEach(function(picker) {
|
||||
var values = [];
|
||||
var range = setup.pickers[picker].range;
|
||||
var isPadded = setup.pickers[picker].isPadded || false;
|
||||
|
||||
this.nodes[picker] = setup.element.querySelector('.picker-' + picker);
|
||||
|
||||
for (var i = range[0]; i <= range[1]; i++) {
|
||||
values.push(i);
|
||||
}
|
||||
|
||||
this.spinners[picker] = new Spinner({
|
||||
element: this.nodes[picker],
|
||||
values: values,
|
||||
isPadded: isPadded,
|
||||
l10nId: setup.pickers[picker].l10nId
|
||||
});
|
||||
}, this);
|
||||
}
|
||||
|
||||
Picker.prototype = {
|
||||
get value() {
|
||||
// Protect against uninitialized [[Get]] access
|
||||
if (typeof this.pickers === 'undefined') {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.pickers.map(function(picker) {
|
||||
return this.spinners[picker].value;
|
||||
}, this).join(':');
|
||||
},
|
||||
|
||||
set value(value) {
|
||||
// Protect against uninitialized [[Set]] access
|
||||
if (typeof this.pickers === 'undefined') {
|
||||
return null;
|
||||
}
|
||||
|
||||
value.split(':').forEach(function(value, i) {
|
||||
this.spinners[this.pickers[i]].value = value;
|
||||
}, this);
|
||||
|
||||
return this.value;
|
||||
},
|
||||
|
||||
reset: function() {
|
||||
this.pickers.forEach(function(picker) {
|
||||
this.spinners[picker].reset();
|
||||
}, this);
|
||||
}
|
||||
};
|
||||
|
||||
return Picker;
|
||||
});
|
||||
Loading…
Reference in a new issue