dojox
Version:
Dojo eXtensions, a rollup of many useful sub-projects and varying states of maturity – from very stable and robust, to alpha and experimental. See individual projects contain README files for details.
120 lines (104 loc) • 3.33 kB
JavaScript
define([
"dojo/_base/array",
"dojo/_base/declare",
"dijit/_Contained",
"dijit/_Container",
"dijit/_WidgetBase",
"dojo/has",
"dojo/has!dojo-bidi?dojox/mobile/bidi/_PickerBase"
], function(array, declare, Contained, Container, WidgetBase, has, _BidiPickerBase){
// module:
// dojox/mobile/_PickerBase
var _PickerBase = declare(has("dojo-bidi") ? "dojox.mobile.NonBidi_PickerBase" : "dojox.mobile._PickerBase", [WidgetBase, Container, Contained],{
// summary:
// A base class for picker classes (e.g. SpinWheel, ValuePicker).
/*=====
// values: Array
// An array of slot values.
// Warning: Do not use this property directly, make sure to call set() or get() methods.
values: "",
=====*/
/*=====
// colors: Array
// An array of slot colors.
// Warning: Do not use this property directly, make sure to call set() or get() methods.
colors: "",
=====*/
/* internal properties */
// slotClasses: [protected] Array
// An array of slot classes. This property is intended to be used
// when you create a subclass of this widget that has specific slots.
slotClasses: [],
// slotProps: [protected] Array
// An array of property objects for each slot class specified in
// slotClasses. This property is intended to be used when you
// create a subclass of this widget that has specific slots.
slotProps: [],
// slotOrder: [protected] Array
// An array of index of slotClasses and slotProps.
// If there are three slots and slotOrder=[2,1,0], the slots are
// displayed in reversed order. This property is intended to be used
// when you create a subclass of this widget that has specific slots.
slotOrder: [],
buildRendering: function(){
this.inherited(arguments);
this.slots = [];
for(var i = 0; i < this.slotClasses.length; i++){
var idx = this.slotOrder.length ? this.slotOrder[i] : i;
var slot = new this.slotClasses[idx](this.slotProps[idx]);
this.addChild(slot);
this.slots[idx] = slot;
}
},
startup: function(){
if(this._started){ return; }
this._duringStartup = true;
this.inherited(arguments);
this.reset();
delete this._duringStartup;
},
getSlots: function(){
// summary:
// Returns an array of child slot widgets.
return this.slots.length ? this.slots :
array.filter(this.getChildren(), function(c){
return c.declaredClass.indexOf("Slot") !== -1;
});
},
_getValuesAttr: function(){
// summary:
// Returns an array of slot values.
// tags:
// private
return array.map(this.getSlots(), function(w){
return w.get("value");
});
},
_setValuesAttr: function(/*Array*/a){
// summary:
// Sets the slot values.
// tags:
// private
array.forEach(this.getSlots(), function(w, i){
w.set("value", a[i]);
});
},
_setColorsAttr: function(/*Array*/a){
// summary:
// Sets the slot colors.
// tags:
// private
array.forEach(this.getSlots(), function(w, i){
w.setColor && w.setColor(a[i]);
});
},
reset: function(){
// summary:
// Resets the picker to show the initial values.
array.forEach(this.getSlots(), function(w){
w.setInitialValue();
});
}
});
return has("dojo-bidi") ? declare("dojox.mobile._PickerBase", [_PickerBase, _BidiPickerBase]) : _PickerBase;
});