formtastic-jquery_inputmask 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. checksums.yaml +4 -4
  2. data/.bowerrc +3 -0
  3. data/bower.json +19 -0
  4. data/lib/formtastic/jquery_inputmask/engine.rb +1 -1
  5. data/lib/formtastic/jquery_inputmask/version.rb +1 -1
  6. data/vendor/inputmask/.bower.json +59 -0
  7. data/vendor/inputmask/bower.json +40 -0
  8. data/vendor/inputmask/dist/inputmask/bindings/inputmask.binding.js +21 -0
  9. data/vendor/inputmask/dist/inputmask/dependencyLibs/inputmask.dependencyLib.jqlite.js +62 -0
  10. data/vendor/inputmask/dist/inputmask/dependencyLibs/inputmask.dependencyLib.jquery.js +13 -0
  11. data/vendor/inputmask/dist/inputmask/dependencyLibs/inputmask.dependencyLib.js +133 -0
  12. data/vendor/inputmask/dist/inputmask/global/document.js +11 -0
  13. data/vendor/inputmask/dist/inputmask/global/window.js +11 -0
  14. data/vendor/inputmask/dist/inputmask/inputmask.date.extensions.js +490 -0
  15. data/vendor/inputmask/dist/inputmask/inputmask.extensions.js +97 -0
  16. data/vendor/inputmask/dist/inputmask/inputmask.js +1643 -0
  17. data/vendor/inputmask/dist/inputmask/inputmask.numeric.extensions.js +347 -0
  18. data/vendor/inputmask/dist/inputmask/inputmask.phone.extensions.js +61 -0
  19. data/vendor/inputmask/dist/inputmask/inputmask.regex.extensions.js +115 -0
  20. data/vendor/inputmask/dist/inputmask/jquery.inputmask.js +62 -0
  21. data/vendor/inputmask/dist/inputmask/phone-codes/phone-be.js +244 -0
  22. data/vendor/inputmask/dist/inputmask/phone-codes/phone-nl.js +924 -0
  23. data/vendor/inputmask/dist/inputmask/phone-codes/phone-ru.js +19240 -0
  24. data/vendor/inputmask/dist/inputmask/phone-codes/phone-uk.js +1009 -0
  25. data/vendor/inputmask/dist/inputmask/phone-codes/phone.js +2111 -0
  26. data/vendor/inputmask/dist/jquery.inputmask.bundle.js +3085 -0
  27. data/vendor/inputmask/dist/min/inputmask/inputmask.date.extensions.min.js +9 -0
  28. data/vendor/inputmask/dist/min/inputmask/inputmask.extensions.min.js +9 -0
  29. data/vendor/inputmask/dist/min/inputmask/inputmask.min.js +10 -0
  30. data/vendor/inputmask/dist/min/inputmask/inputmask.numeric.extensions.min.js +9 -0
  31. data/vendor/inputmask/dist/min/inputmask/inputmask.phone.extensions.min.js +9 -0
  32. data/vendor/inputmask/dist/min/inputmask/inputmask.regex.extensions.min.js +9 -0
  33. data/vendor/inputmask/dist/min/inputmask/jquery.inputmask.min.js +9 -0
  34. data/vendor/inputmask/dist/min/jquery.inputmask.bundle.min.js +11 -0
  35. data/vendor/jquery/.bower.json +25 -0
  36. data/vendor/jquery/AUTHORS.txt +301 -0
  37. data/vendor/jquery/LICENSE.txt +36 -0
  38. data/vendor/jquery/README.md +67 -0
  39. data/vendor/jquery/bower.json +14 -0
  40. data/vendor/jquery/dist/core.js +476 -0
  41. data/vendor/jquery/dist/jquery.js +10253 -0
  42. data/vendor/jquery/dist/jquery.min.js +4 -0
  43. data/vendor/jquery/dist/jquery.min.map +1 -0
  44. data/vendor/jquery/dist/jquery.slim.js +8160 -0
  45. data/vendor/jquery/dist/jquery.slim.min.js +4 -0
  46. data/vendor/jquery/dist/jquery.slim.min.map +1 -0
  47. data/vendor/jquery/external/sizzle/LICENSE.txt +36 -0
  48. data/vendor/jquery/external/sizzle/dist/sizzle.js +2272 -0
  49. data/vendor/jquery/external/sizzle/dist/sizzle.min.js +3 -0
  50. data/vendor/jquery/external/sizzle/dist/sizzle.min.map +1 -0
  51. data/vendor/jquery/src/.eslintrc.json +5 -0
  52. data/vendor/jquery/src/ajax.js +855 -0
  53. data/vendor/jquery/src/ajax/jsonp.js +102 -0
  54. data/vendor/jquery/src/ajax/load.js +76 -0
  55. data/vendor/jquery/src/ajax/parseXML.js +30 -0
  56. data/vendor/jquery/src/ajax/script.js +77 -0
  57. data/vendor/jquery/src/ajax/var/location.js +5 -0
  58. data/vendor/jquery/src/ajax/var/nonce.js +7 -0
  59. data/vendor/jquery/src/ajax/var/rquery.js +5 -0
  60. data/vendor/jquery/src/ajax/xhr.js +169 -0
  61. data/vendor/jquery/src/attributes.js +13 -0
  62. data/vendor/jquery/src/attributes/attr.js +141 -0
  63. data/vendor/jquery/src/attributes/classes.js +174 -0
  64. data/vendor/jquery/src/attributes/prop.js +143 -0
  65. data/vendor/jquery/src/attributes/support.js +33 -0
  66. data/vendor/jquery/src/attributes/val.js +190 -0
  67. data/vendor/jquery/src/callbacks.js +234 -0
  68. data/vendor/jquery/src/core.js +476 -0
  69. data/vendor/jquery/src/core/DOMEval.js +16 -0
  70. data/vendor/jquery/src/core/access.js +70 -0
  71. data/vendor/jquery/src/core/init.js +128 -0
  72. data/vendor/jquery/src/core/nodeName.js +13 -0
  73. data/vendor/jquery/src/core/parseHTML.js +65 -0
  74. data/vendor/jquery/src/core/ready-no-deferred.js +96 -0
  75. data/vendor/jquery/src/core/ready.js +86 -0
  76. data/vendor/jquery/src/core/readyException.js +13 -0
  77. data/vendor/jquery/src/core/stripAndCollapse.js +14 -0
  78. data/vendor/jquery/src/core/support.js +20 -0
  79. data/vendor/jquery/src/core/var/rsingleTag.js +6 -0
  80. data/vendor/jquery/src/css.js +438 -0
  81. data/vendor/jquery/src/css/addGetHookIf.js +26 -0
  82. data/vendor/jquery/src/css/adjustCSS.js +71 -0
  83. data/vendor/jquery/src/css/curCSS.js +65 -0
  84. data/vendor/jquery/src/css/hiddenVisibleSelectors.js +15 -0
  85. data/vendor/jquery/src/css/showHide.js +105 -0
  86. data/vendor/jquery/src/css/support.js +89 -0
  87. data/vendor/jquery/src/css/var/cssExpand.js +5 -0
  88. data/vendor/jquery/src/css/var/getStyles.js +17 -0
  89. data/vendor/jquery/src/css/var/isHiddenWithinTree.js +34 -0
  90. data/vendor/jquery/src/css/var/rmargin.js +5 -0
  91. data/vendor/jquery/src/css/var/rnumnonpx.js +7 -0
  92. data/vendor/jquery/src/css/var/swap.js +26 -0
  93. data/vendor/jquery/src/data.js +179 -0
  94. data/vendor/jquery/src/data/Data.js +161 -0
  95. data/vendor/jquery/src/data/var/acceptData.js +19 -0
  96. data/vendor/jquery/src/data/var/dataPriv.js +7 -0
  97. data/vendor/jquery/src/data/var/dataUser.js +7 -0
  98. data/vendor/jquery/src/deferred.js +391 -0
  99. data/vendor/jquery/src/deferred/exceptionHook.js +21 -0
  100. data/vendor/jquery/src/deprecated.js +40 -0
  101. data/vendor/jquery/src/dimensions.js +56 -0
  102. data/vendor/jquery/src/effects.js +699 -0
  103. data/vendor/jquery/src/effects/Tween.js +123 -0
  104. data/vendor/jquery/src/effects/animatedSelector.js +15 -0
  105. data/vendor/jquery/src/event.js +746 -0
  106. data/vendor/jquery/src/event/ajax.js +22 -0
  107. data/vendor/jquery/src/event/alias.js +29 -0
  108. data/vendor/jquery/src/event/focusin.js +55 -0
  109. data/vendor/jquery/src/event/support.js +11 -0
  110. data/vendor/jquery/src/event/trigger.js +185 -0
  111. data/vendor/jquery/src/exports/amd.js +26 -0
  112. data/vendor/jquery/src/exports/global.js +34 -0
  113. data/vendor/jquery/src/jquery.js +41 -0
  114. data/vendor/jquery/src/manipulation.js +488 -0
  115. data/vendor/jquery/src/manipulation/_evalUrl.js +23 -0
  116. data/vendor/jquery/src/manipulation/buildFragment.js +104 -0
  117. data/vendor/jquery/src/manipulation/getAll.js +32 -0
  118. data/vendor/jquery/src/manipulation/setGlobalEval.js +22 -0
  119. data/vendor/jquery/src/manipulation/support.js +35 -0
  120. data/vendor/jquery/src/manipulation/var/rcheckableType.js +5 -0
  121. data/vendor/jquery/src/manipulation/var/rscriptType.js +5 -0
  122. data/vendor/jquery/src/manipulation/var/rtagName.js +5 -0
  123. data/vendor/jquery/src/manipulation/wrapMap.js +29 -0
  124. data/vendor/jquery/src/offset.js +229 -0
  125. data/vendor/jquery/src/queue.js +145 -0
  126. data/vendor/jquery/src/queue/delay.js +24 -0
  127. data/vendor/jquery/src/selector-native.js +237 -0
  128. data/vendor/jquery/src/selector-sizzle.js +19 -0
  129. data/vendor/jquery/src/selector.js +3 -0
  130. data/vendor/jquery/src/serialize.js +130 -0
  131. data/vendor/jquery/src/traversing.js +191 -0
  132. data/vendor/jquery/src/traversing/findFilter.js +106 -0
  133. data/vendor/jquery/src/traversing/var/dir.js +22 -0
  134. data/vendor/jquery/src/traversing/var/rneedsContext.js +8 -0
  135. data/vendor/jquery/src/traversing/var/siblings.js +17 -0
  136. data/vendor/jquery/src/var/ObjectFunctionString.js +7 -0
  137. data/vendor/jquery/src/var/arr.js +5 -0
  138. data/vendor/jquery/src/var/class2type.js +6 -0
  139. data/vendor/jquery/src/var/concat.js +7 -0
  140. data/vendor/jquery/src/var/document.js +5 -0
  141. data/vendor/jquery/src/var/documentElement.js +7 -0
  142. data/vendor/jquery/src/var/fnToString.js +7 -0
  143. data/vendor/jquery/src/var/getProto.js +5 -0
  144. data/vendor/jquery/src/var/hasOwn.js +7 -0
  145. data/vendor/jquery/src/var/indexOf.js +7 -0
  146. data/vendor/jquery/src/var/pnum.js +5 -0
  147. data/vendor/jquery/src/var/push.js +7 -0
  148. data/vendor/jquery/src/var/rcssNum.js +9 -0
  149. data/vendor/jquery/src/var/rnothtmlwhite.js +8 -0
  150. data/vendor/jquery/src/var/slice.js +7 -0
  151. data/vendor/jquery/src/var/support.js +6 -0
  152. data/vendor/jquery/src/var/toString.js +7 -0
  153. data/vendor/jquery/src/wrap.js +77 -0
  154. metadata +152 -3
  155. data/.gitmodules +0 -3
@@ -0,0 +1,7 @@
1
+ define( [
2
+ "../../var/pnum"
3
+ ], function( pnum ) {
4
+ "use strict";
5
+
6
+ return new RegExp( "^(" + pnum + ")(?!px)[a-z%]+$", "i" );
7
+ } );
@@ -0,0 +1,26 @@
1
+ define( function() {
2
+
3
+ "use strict";
4
+
5
+ // A method for quickly swapping in/out CSS properties to get correct calculations.
6
+ return function( elem, options, callback, args ) {
7
+ var ret, name,
8
+ old = {};
9
+
10
+ // Remember the old values, and insert the new ones
11
+ for ( name in options ) {
12
+ old[ name ] = elem.style[ name ];
13
+ elem.style[ name ] = options[ name ];
14
+ }
15
+
16
+ ret = callback.apply( elem, args || [] );
17
+
18
+ // Revert the old values
19
+ for ( name in options ) {
20
+ elem.style[ name ] = old[ name ];
21
+ }
22
+
23
+ return ret;
24
+ };
25
+
26
+ } );
@@ -0,0 +1,179 @@
1
+ define( [
2
+ "./core",
3
+ "./core/access",
4
+ "./data/var/dataPriv",
5
+ "./data/var/dataUser"
6
+ ], function( jQuery, access, dataPriv, dataUser ) {
7
+
8
+ "use strict";
9
+
10
+ // Implementation Summary
11
+ //
12
+ // 1. Enforce API surface and semantic compatibility with 1.9.x branch
13
+ // 2. Improve the module's maintainability by reducing the storage
14
+ // paths to a single mechanism.
15
+ // 3. Use the same single mechanism to support "private" and "user" data.
16
+ // 4. _Never_ expose "private" data to user code (TODO: Drop _data, _removeData)
17
+ // 5. Avoid exposing implementation details on user objects (eg. expando properties)
18
+ // 6. Provide a clear path for implementation upgrade to WeakMap in 2014
19
+
20
+ var rbrace = /^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,
21
+ rmultiDash = /[A-Z]/g;
22
+
23
+ function getData( data ) {
24
+ if ( data === "true" ) {
25
+ return true;
26
+ }
27
+
28
+ if ( data === "false" ) {
29
+ return false;
30
+ }
31
+
32
+ if ( data === "null" ) {
33
+ return null;
34
+ }
35
+
36
+ // Only convert to a number if it doesn't change the string
37
+ if ( data === +data + "" ) {
38
+ return +data;
39
+ }
40
+
41
+ if ( rbrace.test( data ) ) {
42
+ return JSON.parse( data );
43
+ }
44
+
45
+ return data;
46
+ }
47
+
48
+ function dataAttr( elem, key, data ) {
49
+ var name;
50
+
51
+ // If nothing was found internally, try to fetch any
52
+ // data from the HTML5 data-* attribute
53
+ if ( data === undefined && elem.nodeType === 1 ) {
54
+ name = "data-" + key.replace( rmultiDash, "-$&" ).toLowerCase();
55
+ data = elem.getAttribute( name );
56
+
57
+ if ( typeof data === "string" ) {
58
+ try {
59
+ data = getData( data );
60
+ } catch ( e ) {}
61
+
62
+ // Make sure we set the data so it isn't changed later
63
+ dataUser.set( elem, key, data );
64
+ } else {
65
+ data = undefined;
66
+ }
67
+ }
68
+ return data;
69
+ }
70
+
71
+ jQuery.extend( {
72
+ hasData: function( elem ) {
73
+ return dataUser.hasData( elem ) || dataPriv.hasData( elem );
74
+ },
75
+
76
+ data: function( elem, name, data ) {
77
+ return dataUser.access( elem, name, data );
78
+ },
79
+
80
+ removeData: function( elem, name ) {
81
+ dataUser.remove( elem, name );
82
+ },
83
+
84
+ // TODO: Now that all calls to _data and _removeData have been replaced
85
+ // with direct calls to dataPriv methods, these can be deprecated.
86
+ _data: function( elem, name, data ) {
87
+ return dataPriv.access( elem, name, data );
88
+ },
89
+
90
+ _removeData: function( elem, name ) {
91
+ dataPriv.remove( elem, name );
92
+ }
93
+ } );
94
+
95
+ jQuery.fn.extend( {
96
+ data: function( key, value ) {
97
+ var i, name, data,
98
+ elem = this[ 0 ],
99
+ attrs = elem && elem.attributes;
100
+
101
+ // Gets all values
102
+ if ( key === undefined ) {
103
+ if ( this.length ) {
104
+ data = dataUser.get( elem );
105
+
106
+ if ( elem.nodeType === 1 && !dataPriv.get( elem, "hasDataAttrs" ) ) {
107
+ i = attrs.length;
108
+ while ( i-- ) {
109
+
110
+ // Support: IE 11 only
111
+ // The attrs elements can be null (#14894)
112
+ if ( attrs[ i ] ) {
113
+ name = attrs[ i ].name;
114
+ if ( name.indexOf( "data-" ) === 0 ) {
115
+ name = jQuery.camelCase( name.slice( 5 ) );
116
+ dataAttr( elem, name, data[ name ] );
117
+ }
118
+ }
119
+ }
120
+ dataPriv.set( elem, "hasDataAttrs", true );
121
+ }
122
+ }
123
+
124
+ return data;
125
+ }
126
+
127
+ // Sets multiple values
128
+ if ( typeof key === "object" ) {
129
+ return this.each( function() {
130
+ dataUser.set( this, key );
131
+ } );
132
+ }
133
+
134
+ return access( this, function( value ) {
135
+ var data;
136
+
137
+ // The calling jQuery object (element matches) is not empty
138
+ // (and therefore has an element appears at this[ 0 ]) and the
139
+ // `value` parameter was not undefined. An empty jQuery object
140
+ // will result in `undefined` for elem = this[ 0 ] which will
141
+ // throw an exception if an attempt to read a data cache is made.
142
+ if ( elem && value === undefined ) {
143
+
144
+ // Attempt to get data from the cache
145
+ // The key will always be camelCased in Data
146
+ data = dataUser.get( elem, key );
147
+ if ( data !== undefined ) {
148
+ return data;
149
+ }
150
+
151
+ // Attempt to "discover" the data in
152
+ // HTML5 custom data-* attrs
153
+ data = dataAttr( elem, key );
154
+ if ( data !== undefined ) {
155
+ return data;
156
+ }
157
+
158
+ // We tried really hard, but the data doesn't exist.
159
+ return;
160
+ }
161
+
162
+ // Set the data...
163
+ this.each( function() {
164
+
165
+ // We always store the camelCased key
166
+ dataUser.set( this, key, value );
167
+ } );
168
+ }, null, value, arguments.length > 1, null, true );
169
+ },
170
+
171
+ removeData: function( key ) {
172
+ return this.each( function() {
173
+ dataUser.remove( this, key );
174
+ } );
175
+ }
176
+ } );
177
+
178
+ return jQuery;
179
+ } );
@@ -0,0 +1,161 @@
1
+ define( [
2
+ "../core",
3
+ "../var/rnothtmlwhite",
4
+ "./var/acceptData"
5
+ ], function( jQuery, rnothtmlwhite, acceptData ) {
6
+
7
+ "use strict";
8
+
9
+ function Data() {
10
+ this.expando = jQuery.expando + Data.uid++;
11
+ }
12
+
13
+ Data.uid = 1;
14
+
15
+ Data.prototype = {
16
+
17
+ cache: function( owner ) {
18
+
19
+ // Check if the owner object already has a cache
20
+ var value = owner[ this.expando ];
21
+
22
+ // If not, create one
23
+ if ( !value ) {
24
+ value = {};
25
+
26
+ // We can accept data for non-element nodes in modern browsers,
27
+ // but we should not, see #8335.
28
+ // Always return an empty object.
29
+ if ( acceptData( owner ) ) {
30
+
31
+ // If it is a node unlikely to be stringify-ed or looped over
32
+ // use plain assignment
33
+ if ( owner.nodeType ) {
34
+ owner[ this.expando ] = value;
35
+
36
+ // Otherwise secure it in a non-enumerable property
37
+ // configurable must be true to allow the property to be
38
+ // deleted when data is removed
39
+ } else {
40
+ Object.defineProperty( owner, this.expando, {
41
+ value: value,
42
+ configurable: true
43
+ } );
44
+ }
45
+ }
46
+ }
47
+
48
+ return value;
49
+ },
50
+ set: function( owner, data, value ) {
51
+ var prop,
52
+ cache = this.cache( owner );
53
+
54
+ // Handle: [ owner, key, value ] args
55
+ // Always use camelCase key (gh-2257)
56
+ if ( typeof data === "string" ) {
57
+ cache[ jQuery.camelCase( data ) ] = value;
58
+
59
+ // Handle: [ owner, { properties } ] args
60
+ } else {
61
+
62
+ // Copy the properties one-by-one to the cache object
63
+ for ( prop in data ) {
64
+ cache[ jQuery.camelCase( prop ) ] = data[ prop ];
65
+ }
66
+ }
67
+ return cache;
68
+ },
69
+ get: function( owner, key ) {
70
+ return key === undefined ?
71
+ this.cache( owner ) :
72
+
73
+ // Always use camelCase key (gh-2257)
74
+ owner[ this.expando ] && owner[ this.expando ][ jQuery.camelCase( key ) ];
75
+ },
76
+ access: function( owner, key, value ) {
77
+
78
+ // In cases where either:
79
+ //
80
+ // 1. No key was specified
81
+ // 2. A string key was specified, but no value provided
82
+ //
83
+ // Take the "read" path and allow the get method to determine
84
+ // which value to return, respectively either:
85
+ //
86
+ // 1. The entire cache object
87
+ // 2. The data stored at the key
88
+ //
89
+ if ( key === undefined ||
90
+ ( ( key && typeof key === "string" ) && value === undefined ) ) {
91
+
92
+ return this.get( owner, key );
93
+ }
94
+
95
+ // When the key is not a string, or both a key and value
96
+ // are specified, set or extend (existing objects) with either:
97
+ //
98
+ // 1. An object of properties
99
+ // 2. A key and value
100
+ //
101
+ this.set( owner, key, value );
102
+
103
+ // Since the "set" path can have two possible entry points
104
+ // return the expected data based on which path was taken[*]
105
+ return value !== undefined ? value : key;
106
+ },
107
+ remove: function( owner, key ) {
108
+ var i,
109
+ cache = owner[ this.expando ];
110
+
111
+ if ( cache === undefined ) {
112
+ return;
113
+ }
114
+
115
+ if ( key !== undefined ) {
116
+
117
+ // Support array or space separated string of keys
118
+ if ( Array.isArray( key ) ) {
119
+
120
+ // If key is an array of keys...
121
+ // We always set camelCase keys, so remove that.
122
+ key = key.map( jQuery.camelCase );
123
+ } else {
124
+ key = jQuery.camelCase( key );
125
+
126
+ // If a key with the spaces exists, use it.
127
+ // Otherwise, create an array by matching non-whitespace
128
+ key = key in cache ?
129
+ [ key ] :
130
+ ( key.match( rnothtmlwhite ) || [] );
131
+ }
132
+
133
+ i = key.length;
134
+
135
+ while ( i-- ) {
136
+ delete cache[ key[ i ] ];
137
+ }
138
+ }
139
+
140
+ // Remove the expando if there's no more data
141
+ if ( key === undefined || jQuery.isEmptyObject( cache ) ) {
142
+
143
+ // Support: Chrome <=35 - 45
144
+ // Webkit & Blink performance suffers when deleting properties
145
+ // from DOM nodes, so set to undefined instead
146
+ // https://bugs.chromium.org/p/chromium/issues/detail?id=378607 (bug restricted)
147
+ if ( owner.nodeType ) {
148
+ owner[ this.expando ] = undefined;
149
+ } else {
150
+ delete owner[ this.expando ];
151
+ }
152
+ }
153
+ },
154
+ hasData: function( owner ) {
155
+ var cache = owner[ this.expando ];
156
+ return cache !== undefined && !jQuery.isEmptyObject( cache );
157
+ }
158
+ };
159
+
160
+ return Data;
161
+ } );
@@ -0,0 +1,19 @@
1
+ define( function() {
2
+
3
+ "use strict";
4
+
5
+ /**
6
+ * Determines whether an object can have data
7
+ */
8
+ return function( owner ) {
9
+
10
+ // Accepts only:
11
+ // - Node
12
+ // - Node.ELEMENT_NODE
13
+ // - Node.DOCUMENT_NODE
14
+ // - Object
15
+ // - Any
16
+ return owner.nodeType === 1 || owner.nodeType === 9 || !( +owner.nodeType );
17
+ };
18
+
19
+ } );
@@ -0,0 +1,7 @@
1
+ define( [
2
+ "../Data"
3
+ ], function( Data ) {
4
+ "use strict";
5
+
6
+ return new Data();
7
+ } );
@@ -0,0 +1,7 @@
1
+ define( [
2
+ "../Data"
3
+ ], function( Data ) {
4
+ "use strict";
5
+
6
+ return new Data();
7
+ } );
@@ -0,0 +1,391 @@
1
+ define( [
2
+ "./core",
3
+ "./var/slice",
4
+ "./callbacks"
5
+ ], function( jQuery, slice ) {
6
+
7
+ "use strict";
8
+
9
+ function Identity( v ) {
10
+ return v;
11
+ }
12
+ function Thrower( ex ) {
13
+ throw ex;
14
+ }
15
+
16
+ function adoptValue( value, resolve, reject, noValue ) {
17
+ var method;
18
+
19
+ try {
20
+
21
+ // Check for promise aspect first to privilege synchronous behavior
22
+ if ( value && jQuery.isFunction( ( method = value.promise ) ) ) {
23
+ method.call( value ).done( resolve ).fail( reject );
24
+
25
+ // Other thenables
26
+ } else if ( value && jQuery.isFunction( ( method = value.then ) ) ) {
27
+ method.call( value, resolve, reject );
28
+
29
+ // Other non-thenables
30
+ } else {
31
+
32
+ // Control `resolve` arguments by letting Array#slice cast boolean `noValue` to integer:
33
+ // * false: [ value ].slice( 0 ) => resolve( value )
34
+ // * true: [ value ].slice( 1 ) => resolve()
35
+ resolve.apply( undefined, [ value ].slice( noValue ) );
36
+ }
37
+
38
+ // For Promises/A+, convert exceptions into rejections
39
+ // Since jQuery.when doesn't unwrap thenables, we can skip the extra checks appearing in
40
+ // Deferred#then to conditionally suppress rejection.
41
+ } catch ( value ) {
42
+
43
+ // Support: Android 4.0 only
44
+ // Strict mode functions invoked without .call/.apply get global-object context
45
+ reject.apply( undefined, [ value ] );
46
+ }
47
+ }
48
+
49
+ jQuery.extend( {
50
+
51
+ Deferred: function( func ) {
52
+ var tuples = [
53
+
54
+ // action, add listener, callbacks,
55
+ // ... .then handlers, argument index, [final state]
56
+ [ "notify", "progress", jQuery.Callbacks( "memory" ),
57
+ jQuery.Callbacks( "memory" ), 2 ],
58
+ [ "resolve", "done", jQuery.Callbacks( "once memory" ),
59
+ jQuery.Callbacks( "once memory" ), 0, "resolved" ],
60
+ [ "reject", "fail", jQuery.Callbacks( "once memory" ),
61
+ jQuery.Callbacks( "once memory" ), 1, "rejected" ]
62
+ ],
63
+ state = "pending",
64
+ promise = {
65
+ state: function() {
66
+ return state;
67
+ },
68
+ always: function() {
69
+ deferred.done( arguments ).fail( arguments );
70
+ return this;
71
+ },
72
+ "catch": function( fn ) {
73
+ return promise.then( null, fn );
74
+ },
75
+
76
+ // Keep pipe for back-compat
77
+ pipe: function( /* fnDone, fnFail, fnProgress */ ) {
78
+ var fns = arguments;
79
+
80
+ return jQuery.Deferred( function( newDefer ) {
81
+ jQuery.each( tuples, function( i, tuple ) {
82
+
83
+ // Map tuples (progress, done, fail) to arguments (done, fail, progress)
84
+ var fn = jQuery.isFunction( fns[ tuple[ 4 ] ] ) && fns[ tuple[ 4 ] ];
85
+
86
+ // deferred.progress(function() { bind to newDefer or newDefer.notify })
87
+ // deferred.done(function() { bind to newDefer or newDefer.resolve })
88
+ // deferred.fail(function() { bind to newDefer or newDefer.reject })
89
+ deferred[ tuple[ 1 ] ]( function() {
90
+ var returned = fn && fn.apply( this, arguments );
91
+ if ( returned && jQuery.isFunction( returned.promise ) ) {
92
+ returned.promise()
93
+ .progress( newDefer.notify )
94
+ .done( newDefer.resolve )
95
+ .fail( newDefer.reject );
96
+ } else {
97
+ newDefer[ tuple[ 0 ] + "With" ](
98
+ this,
99
+ fn ? [ returned ] : arguments
100
+ );
101
+ }
102
+ } );
103
+ } );
104
+ fns = null;
105
+ } ).promise();
106
+ },
107
+ then: function( onFulfilled, onRejected, onProgress ) {
108
+ var maxDepth = 0;
109
+ function resolve( depth, deferred, handler, special ) {
110
+ return function() {
111
+ var that = this,
112
+ args = arguments,
113
+ mightThrow = function() {
114
+ var returned, then;
115
+
116
+ // Support: Promises/A+ section 2.3.3.3.3
117
+ // https://promisesaplus.com/#point-59
118
+ // Ignore double-resolution attempts
119
+ if ( depth < maxDepth ) {
120
+ return;
121
+ }
122
+
123
+ returned = handler.apply( that, args );
124
+
125
+ // Support: Promises/A+ section 2.3.1
126
+ // https://promisesaplus.com/#point-48
127
+ if ( returned === deferred.promise() ) {
128
+ throw new TypeError( "Thenable self-resolution" );
129
+ }
130
+
131
+ // Support: Promises/A+ sections 2.3.3.1, 3.5
132
+ // https://promisesaplus.com/#point-54
133
+ // https://promisesaplus.com/#point-75
134
+ // Retrieve `then` only once
135
+ then = returned &&
136
+
137
+ // Support: Promises/A+ section 2.3.4
138
+ // https://promisesaplus.com/#point-64
139
+ // Only check objects and functions for thenability
140
+ ( typeof returned === "object" ||
141
+ typeof returned === "function" ) &&
142
+ returned.then;
143
+
144
+ // Handle a returned thenable
145
+ if ( jQuery.isFunction( then ) ) {
146
+
147
+ // Special processors (notify) just wait for resolution
148
+ if ( special ) {
149
+ then.call(
150
+ returned,
151
+ resolve( maxDepth, deferred, Identity, special ),
152
+ resolve( maxDepth, deferred, Thrower, special )
153
+ );
154
+
155
+ // Normal processors (resolve) also hook into progress
156
+ } else {
157
+
158
+ // ...and disregard older resolution values
159
+ maxDepth++;
160
+
161
+ then.call(
162
+ returned,
163
+ resolve( maxDepth, deferred, Identity, special ),
164
+ resolve( maxDepth, deferred, Thrower, special ),
165
+ resolve( maxDepth, deferred, Identity,
166
+ deferred.notifyWith )
167
+ );
168
+ }
169
+
170
+ // Handle all other returned values
171
+ } else {
172
+
173
+ // Only substitute handlers pass on context
174
+ // and multiple values (non-spec behavior)
175
+ if ( handler !== Identity ) {
176
+ that = undefined;
177
+ args = [ returned ];
178
+ }
179
+
180
+ // Process the value(s)
181
+ // Default process is resolve
182
+ ( special || deferred.resolveWith )( that, args );
183
+ }
184
+ },
185
+
186
+ // Only normal processors (resolve) catch and reject exceptions
187
+ process = special ?
188
+ mightThrow :
189
+ function() {
190
+ try {
191
+ mightThrow();
192
+ } catch ( e ) {
193
+
194
+ if ( jQuery.Deferred.exceptionHook ) {
195
+ jQuery.Deferred.exceptionHook( e,
196
+ process.stackTrace );
197
+ }
198
+
199
+ // Support: Promises/A+ section 2.3.3.3.4.1
200
+ // https://promisesaplus.com/#point-61
201
+ // Ignore post-resolution exceptions
202
+ if ( depth + 1 >= maxDepth ) {
203
+
204
+ // Only substitute handlers pass on context
205
+ // and multiple values (non-spec behavior)
206
+ if ( handler !== Thrower ) {
207
+ that = undefined;
208
+ args = [ e ];
209
+ }
210
+
211
+ deferred.rejectWith( that, args );
212
+ }
213
+ }
214
+ };
215
+
216
+ // Support: Promises/A+ section 2.3.3.3.1
217
+ // https://promisesaplus.com/#point-57
218
+ // Re-resolve promises immediately to dodge false rejection from
219
+ // subsequent errors
220
+ if ( depth ) {
221
+ process();
222
+ } else {
223
+
224
+ // Call an optional hook to record the stack, in case of exception
225
+ // since it's otherwise lost when execution goes async
226
+ if ( jQuery.Deferred.getStackHook ) {
227
+ process.stackTrace = jQuery.Deferred.getStackHook();
228
+ }
229
+ window.setTimeout( process );
230
+ }
231
+ };
232
+ }
233
+
234
+ return jQuery.Deferred( function( newDefer ) {
235
+
236
+ // progress_handlers.add( ... )
237
+ tuples[ 0 ][ 3 ].add(
238
+ resolve(
239
+ 0,
240
+ newDefer,
241
+ jQuery.isFunction( onProgress ) ?
242
+ onProgress :
243
+ Identity,
244
+ newDefer.notifyWith
245
+ )
246
+ );
247
+
248
+ // fulfilled_handlers.add( ... )
249
+ tuples[ 1 ][ 3 ].add(
250
+ resolve(
251
+ 0,
252
+ newDefer,
253
+ jQuery.isFunction( onFulfilled ) ?
254
+ onFulfilled :
255
+ Identity
256
+ )
257
+ );
258
+
259
+ // rejected_handlers.add( ... )
260
+ tuples[ 2 ][ 3 ].add(
261
+ resolve(
262
+ 0,
263
+ newDefer,
264
+ jQuery.isFunction( onRejected ) ?
265
+ onRejected :
266
+ Thrower
267
+ )
268
+ );
269
+ } ).promise();
270
+ },
271
+
272
+ // Get a promise for this deferred
273
+ // If obj is provided, the promise aspect is added to the object
274
+ promise: function( obj ) {
275
+ return obj != null ? jQuery.extend( obj, promise ) : promise;
276
+ }
277
+ },
278
+ deferred = {};
279
+
280
+ // Add list-specific methods
281
+ jQuery.each( tuples, function( i, tuple ) {
282
+ var list = tuple[ 2 ],
283
+ stateString = tuple[ 5 ];
284
+
285
+ // promise.progress = list.add
286
+ // promise.done = list.add
287
+ // promise.fail = list.add
288
+ promise[ tuple[ 1 ] ] = list.add;
289
+
290
+ // Handle state
291
+ if ( stateString ) {
292
+ list.add(
293
+ function() {
294
+
295
+ // state = "resolved" (i.e., fulfilled)
296
+ // state = "rejected"
297
+ state = stateString;
298
+ },
299
+
300
+ // rejected_callbacks.disable
301
+ // fulfilled_callbacks.disable
302
+ tuples[ 3 - i ][ 2 ].disable,
303
+
304
+ // progress_callbacks.lock
305
+ tuples[ 0 ][ 2 ].lock
306
+ );
307
+ }
308
+
309
+ // progress_handlers.fire
310
+ // fulfilled_handlers.fire
311
+ // rejected_handlers.fire
312
+ list.add( tuple[ 3 ].fire );
313
+
314
+ // deferred.notify = function() { deferred.notifyWith(...) }
315
+ // deferred.resolve = function() { deferred.resolveWith(...) }
316
+ // deferred.reject = function() { deferred.rejectWith(...) }
317
+ deferred[ tuple[ 0 ] ] = function() {
318
+ deferred[ tuple[ 0 ] + "With" ]( this === deferred ? undefined : this, arguments );
319
+ return this;
320
+ };
321
+
322
+ // deferred.notifyWith = list.fireWith
323
+ // deferred.resolveWith = list.fireWith
324
+ // deferred.rejectWith = list.fireWith
325
+ deferred[ tuple[ 0 ] + "With" ] = list.fireWith;
326
+ } );
327
+
328
+ // Make the deferred a promise
329
+ promise.promise( deferred );
330
+
331
+ // Call given func if any
332
+ if ( func ) {
333
+ func.call( deferred, deferred );
334
+ }
335
+
336
+ // All done!
337
+ return deferred;
338
+ },
339
+
340
+ // Deferred helper
341
+ when: function( singleValue ) {
342
+ var
343
+
344
+ // count of uncompleted subordinates
345
+ remaining = arguments.length,
346
+
347
+ // count of unprocessed arguments
348
+ i = remaining,
349
+
350
+ // subordinate fulfillment data
351
+ resolveContexts = Array( i ),
352
+ resolveValues = slice.call( arguments ),
353
+
354
+ // the master Deferred
355
+ master = jQuery.Deferred(),
356
+
357
+ // subordinate callback factory
358
+ updateFunc = function( i ) {
359
+ return function( value ) {
360
+ resolveContexts[ i ] = this;
361
+ resolveValues[ i ] = arguments.length > 1 ? slice.call( arguments ) : value;
362
+ if ( !( --remaining ) ) {
363
+ master.resolveWith( resolveContexts, resolveValues );
364
+ }
365
+ };
366
+ };
367
+
368
+ // Single- and empty arguments are adopted like Promise.resolve
369
+ if ( remaining <= 1 ) {
370
+ adoptValue( singleValue, master.done( updateFunc( i ) ).resolve, master.reject,
371
+ !remaining );
372
+
373
+ // Use .then() to unwrap secondary thenables (cf. gh-3000)
374
+ if ( master.state() === "pending" ||
375
+ jQuery.isFunction( resolveValues[ i ] && resolveValues[ i ].then ) ) {
376
+
377
+ return master.then();
378
+ }
379
+ }
380
+
381
+ // Multiple arguments are aggregated like Promise.all array elements
382
+ while ( i-- ) {
383
+ adoptValue( resolveValues[ i ], updateFunc( i ), master.reject );
384
+ }
385
+
386
+ return master.promise();
387
+ }
388
+ } );
389
+
390
+ return jQuery;
391
+ } );