]> git.wh0rd.org - tt-rss.git/blob - lib/dijit/form/_FormValueMixin.js.uncompressed.js
make precache_headlines_idle() start slower
[tt-rss.git] / lib / dijit / form / _FormValueMixin.js.uncompressed.js
1 define("dijit/form/_FormValueMixin", [
2 "dojo/_base/declare", // declare
3 "dojo/dom-attr", // domAttr.set
4 "dojo/keys", // keys.ESCAPE
5 "dojo/_base/sniff", // has("ie"), has("quirks")
6 "./_FormWidgetMixin"
7 ], function(declare, domAttr, keys, has, _FormWidgetMixin){
8
9 /*=====
10 var _FormWidgetMixin = dijit.form._FormWidgetMixin;
11 =====*/
12
13 // module:
14 // dijit/form/_FormValueMixin
15 // summary:
16 // Mixin for widgets corresponding to native HTML elements such as <input> or <select> that have user changeable values.
17
18 return declare("dijit.form._FormValueMixin", _FormWidgetMixin, {
19 // summary:
20 // Mixin for widgets corresponding to native HTML elements such as <input> or <select> that have user changeable values.
21 // description:
22 // Each _FormValueMixin represents a single input value, and has a (possibly hidden) <input> element,
23 // to which it serializes it's input value, so that form submission (either normal submission or via FormBind?)
24 // works as expected.
25
26 // readOnly: Boolean
27 // Should this widget respond to user input?
28 // In markup, this is specified as "readOnly".
29 // Similar to disabled except readOnly form values are submitted.
30 readOnly: false,
31
32 _setReadOnlyAttr: function(/*Boolean*/ value){
33 domAttr.set(this.focusNode, 'readOnly', value);
34 this.focusNode.setAttribute("aria-readonly", value);
35 this._set("readOnly", value);
36 },
37
38 postCreate: function(){
39 this.inherited(arguments);
40
41 if(has("ie")){ // IE won't stop the event with keypress
42 this.connect(this.focusNode || this.domNode, "onkeydown", this._onKeyDown);
43 }
44 // Update our reset value if it hasn't yet been set (because this.set()
45 // is only called when there *is* a value)
46 if(this._resetValue === undefined){
47 this._lastValueReported = this._resetValue = this.value;
48 }
49 },
50
51 _setValueAttr: function(/*anything*/ newValue, /*Boolean?*/ priorityChange){
52 // summary:
53 // Hook so set('value', value) works.
54 // description:
55 // Sets the value of the widget.
56 // If the value has changed, then fire onChange event, unless priorityChange
57 // is specified as null (or false?)
58 this._handleOnChange(newValue, priorityChange);
59 },
60
61 _handleOnChange: function(/*anything*/ newValue, /*Boolean?*/ priorityChange){
62 // summary:
63 // Called when the value of the widget has changed. Saves the new value in this.value,
64 // and calls onChange() if appropriate. See _FormWidget._handleOnChange() for details.
65 this._set("value", newValue);
66 this.inherited(arguments);
67 },
68
69 undo: function(){
70 // summary:
71 // Restore the value to the last value passed to onChange
72 this._setValueAttr(this._lastValueReported, false);
73 },
74
75 reset: function(){
76 // summary:
77 // Reset the widget's value to what it was at initialization time
78 this._hasBeenBlurred = false;
79 this._setValueAttr(this._resetValue, true);
80 },
81
82 _onKeyDown: function(e){
83 if(e.keyCode == keys.ESCAPE && !(e.ctrlKey || e.altKey || e.metaKey)){
84 var te;
85 if(has("ie") < 9 || (has("ie") && has("quirks"))){
86 e.preventDefault(); // default behavior needs to be stopped here since keypress is too late
87 te = document.createEventObject();
88 te.keyCode = keys.ESCAPE;
89 te.shiftKey = e.shiftKey;
90 e.srcElement.fireEvent('onkeypress', te);
91 }
92 }
93 }
94 });
95 });