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