jquery-fileupload-rails 0.3.4 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,12 @@
1
1
  /*
2
- * jQuery UI Widget 1.8.23+amd
2
+ * jQuery UI Widget 1.9.1+amd
3
3
  * https://github.com/blueimp/jQuery-File-Upload
4
4
  *
5
- * Copyright 2012, AUTHORS.txt (http://jqueryui.com/about)
6
- * Dual licensed under the MIT or GPL Version 2 licenses.
5
+ * Copyright 2012 jQuery Foundation and other contributors
6
+ * Released under the MIT license.
7
7
  * http://jquery.org/license
8
8
  *
9
- * http://docs.jquery.com/UI/Widget
9
+ * http://api.jqueryui.com/jQuery.widget/
10
10
  */
11
11
 
12
12
  (function (factory) {
@@ -19,40 +19,23 @@
19
19
  }
20
20
  }(function( $, undefined ) {
21
21
 
22
- // jQuery 1.4+
23
- if ( $.cleanData ) {
24
- var _cleanData = $.cleanData;
25
- $.cleanData = function( elems ) {
26
- for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
27
- try {
28
- $( elem ).triggerHandler( "remove" );
29
- // http://bugs.jquery.com/ticket/8235
30
- } catch( e ) {}
31
- }
32
- _cleanData( elems );
33
- };
34
- } else {
35
- var _remove = $.fn.remove;
36
- $.fn.remove = function( selector, keepData ) {
37
- return this.each(function() {
38
- if ( !keepData ) {
39
- if ( !selector || $.filter( selector, [ this ] ).length ) {
40
- $( "*", this ).add( [ this ] ).each(function() {
41
- try {
42
- $( this ).triggerHandler( "remove" );
43
- // http://bugs.jquery.com/ticket/8235
44
- } catch( e ) {}
45
- });
46
- }
47
- }
48
- return _remove.call( $(this), selector, keepData );
49
- });
50
- };
51
- }
22
+ var uuid = 0,
23
+ slice = Array.prototype.slice,
24
+ _cleanData = $.cleanData;
25
+ $.cleanData = function( elems ) {
26
+ for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
27
+ try {
28
+ $( elem ).triggerHandler( "remove" );
29
+ // http://bugs.jquery.com/ticket/8235
30
+ } catch( e ) {}
31
+ }
32
+ _cleanData( elems );
33
+ };
52
34
 
53
35
  $.widget = function( name, base, prototype ) {
54
- var namespace = name.split( "." )[ 0 ],
55
- fullName;
36
+ var fullName, existingConstructor, constructor, basePrototype,
37
+ namespace = name.split( "." )[ 0 ];
38
+
56
39
  name = name.split( "." )[ 1 ];
57
40
  fullName = namespace + "-" + name;
58
41
 
@@ -62,81 +45,167 @@ $.widget = function( name, base, prototype ) {
62
45
  }
63
46
 
64
47
  // create selector for plugin
65
- $.expr[ ":" ][ fullName ] = function( elem ) {
66
- return !!$.data( elem, name );
48
+ $.expr[ ":" ][ fullName.toLowerCase() ] = function( elem ) {
49
+ return !!$.data( elem, fullName );
67
50
  };
68
51
 
69
52
  $[ namespace ] = $[ namespace ] || {};
70
- $[ namespace ][ name ] = function( options, element ) {
53
+ existingConstructor = $[ namespace ][ name ];
54
+ constructor = $[ namespace ][ name ] = function( options, element ) {
55
+ // allow instantiation without "new" keyword
56
+ if ( !this._createWidget ) {
57
+ return new constructor( options, element );
58
+ }
59
+
71
60
  // allow instantiation without initializing for simple inheritance
61
+ // must use "new" keyword (the code above always passes args)
72
62
  if ( arguments.length ) {
73
63
  this._createWidget( options, element );
74
64
  }
75
65
  };
76
-
77
- var basePrototype = new base();
66
+ // extend with the existing constructor to carry over any static properties
67
+ $.extend( constructor, existingConstructor, {
68
+ version: prototype.version,
69
+ // copy the object used to create the prototype in case we need to
70
+ // redefine the widget later
71
+ _proto: $.extend( {}, prototype ),
72
+ // track widgets that inherit from this widget in case this widget is
73
+ // redefined after a widget inherits from it
74
+ _childConstructors: []
75
+ });
76
+
77
+ basePrototype = new base();
78
78
  // we need to make the options hash a property directly on the new instance
79
79
  // otherwise we'll modify the options hash on the prototype that we're
80
80
  // inheriting from
81
- // $.each( basePrototype, function( key, val ) {
82
- // if ( $.isPlainObject(val) ) {
83
- // basePrototype[ key ] = $.extend( {}, val );
84
- // }
85
- // });
86
- basePrototype.options = $.extend( true, {}, basePrototype.options );
87
- $[ namespace ][ name ].prototype = $.extend( true, basePrototype, {
81
+ basePrototype.options = $.widget.extend( {}, basePrototype.options );
82
+ $.each( prototype, function( prop, value ) {
83
+ if ( $.isFunction( value ) ) {
84
+ prototype[ prop ] = (function() {
85
+ var _super = function() {
86
+ return base.prototype[ prop ].apply( this, arguments );
87
+ },
88
+ _superApply = function( args ) {
89
+ return base.prototype[ prop ].apply( this, args );
90
+ };
91
+ return function() {
92
+ var __super = this._super,
93
+ __superApply = this._superApply,
94
+ returnValue;
95
+
96
+ this._super = _super;
97
+ this._superApply = _superApply;
98
+
99
+ returnValue = value.apply( this, arguments );
100
+
101
+ this._super = __super;
102
+ this._superApply = __superApply;
103
+
104
+ return returnValue;
105
+ };
106
+ })();
107
+ }
108
+ });
109
+ constructor.prototype = $.widget.extend( basePrototype, {
110
+ // TODO: remove support for widgetEventPrefix
111
+ // always use the name + a colon as the prefix, e.g., draggable:start
112
+ // don't prefix for widgets that aren't DOM-based
113
+ widgetEventPrefix: basePrototype.widgetEventPrefix || name
114
+ }, prototype, {
115
+ constructor: constructor,
88
116
  namespace: namespace,
89
117
  widgetName: name,
90
- widgetEventPrefix: $[ namespace ][ name ].prototype.widgetEventPrefix || name,
91
- widgetBaseClass: fullName
92
- }, prototype );
118
+ // TODO remove widgetBaseClass, see #8155
119
+ widgetBaseClass: fullName,
120
+ widgetFullName: fullName
121
+ });
122
+
123
+ // If this widget is being redefined then we need to find all widgets that
124
+ // are inheriting from it and redefine all of them so that they inherit from
125
+ // the new version of this widget. We're essentially trying to replace one
126
+ // level in the prototype chain.
127
+ if ( existingConstructor ) {
128
+ $.each( existingConstructor._childConstructors, function( i, child ) {
129
+ var childPrototype = child.prototype;
130
+
131
+ // redefine the child widget using the same prototype that was
132
+ // originally used, but inherit from the new version of the base
133
+ $.widget( childPrototype.namespace + "." + childPrototype.widgetName, constructor, child._proto );
134
+ });
135
+ // remove the list of existing child constructors from the old constructor
136
+ // so the old child constructors can be garbage collected
137
+ delete existingConstructor._childConstructors;
138
+ } else {
139
+ base._childConstructors.push( constructor );
140
+ }
93
141
 
94
- $.widget.bridge( name, $[ namespace ][ name ] );
142
+ $.widget.bridge( name, constructor );
143
+ };
144
+
145
+ $.widget.extend = function( target ) {
146
+ var input = slice.call( arguments, 1 ),
147
+ inputIndex = 0,
148
+ inputLength = input.length,
149
+ key,
150
+ value;
151
+ for ( ; inputIndex < inputLength; inputIndex++ ) {
152
+ for ( key in input[ inputIndex ] ) {
153
+ value = input[ inputIndex ][ key ];
154
+ if ( input[ inputIndex ].hasOwnProperty( key ) && value !== undefined ) {
155
+ // Clone objects
156
+ if ( $.isPlainObject( value ) ) {
157
+ target[ key ] = $.isPlainObject( target[ key ] ) ?
158
+ $.widget.extend( {}, target[ key ], value ) :
159
+ // Don't extend strings, arrays, etc. with objects
160
+ $.widget.extend( {}, value );
161
+ // Copy everything else by reference
162
+ } else {
163
+ target[ key ] = value;
164
+ }
165
+ }
166
+ }
167
+ }
168
+ return target;
95
169
  };
96
170
 
97
171
  $.widget.bridge = function( name, object ) {
172
+ var fullName = object.prototype.widgetFullName;
98
173
  $.fn[ name ] = function( options ) {
99
174
  var isMethodCall = typeof options === "string",
100
- args = Array.prototype.slice.call( arguments, 1 ),
175
+ args = slice.call( arguments, 1 ),
101
176
  returnValue = this;
102
177
 
103
178
  // allow multiple hashes to be passed on init
104
179
  options = !isMethodCall && args.length ?
105
- $.extend.apply( null, [ true, options ].concat(args) ) :
180
+ $.widget.extend.apply( null, [ options ].concat(args) ) :
106
181
  options;
107
182
 
108
- // prevent calls to internal methods
109
- if ( isMethodCall && options.charAt( 0 ) === "_" ) {
110
- return returnValue;
111
- }
112
-
113
183
  if ( isMethodCall ) {
114
184
  this.each(function() {
115
- var instance = $.data( this, name ),
116
- methodValue = instance && $.isFunction( instance[options] ) ?
117
- instance[ options ].apply( instance, args ) :
118
- instance;
119
- // TODO: add this back in 1.9 and use $.error() (see #5972)
120
- // if ( !instance ) {
121
- // throw "cannot call methods on " + name + " prior to initialization; " +
122
- // "attempted to call method '" + options + "'";
123
- // }
124
- // if ( !$.isFunction( instance[options] ) ) {
125
- // throw "no such method '" + options + "' for " + name + " widget instance";
126
- // }
127
- // var methodValue = instance[ options ].apply( instance, args );
185
+ var methodValue,
186
+ instance = $.data( this, fullName );
187
+ if ( !instance ) {
188
+ return $.error( "cannot call methods on " + name + " prior to initialization; " +
189
+ "attempted to call method '" + options + "'" );
190
+ }
191
+ if ( !$.isFunction( instance[options] ) || options.charAt( 0 ) === "_" ) {
192
+ return $.error( "no such method '" + options + "' for " + name + " widget instance" );
193
+ }
194
+ methodValue = instance[ options ].apply( instance, args );
128
195
  if ( methodValue !== instance && methodValue !== undefined ) {
129
- returnValue = methodValue;
196
+ returnValue = methodValue && methodValue.jquery ?
197
+ returnValue.pushStack( methodValue.get() ) :
198
+ methodValue;
130
199
  return false;
131
200
  }
132
201
  });
133
202
  } else {
134
203
  this.each(function() {
135
- var instance = $.data( this, name );
204
+ var instance = $.data( this, fullName );
136
205
  if ( instance ) {
137
206
  instance.option( options || {} )._init();
138
207
  } else {
139
- $.data( this, name, new object( options, this ) );
208
+ new object( options, this );
140
209
  }
141
210
  });
142
211
  }
@@ -145,74 +214,126 @@ $.widget.bridge = function( name, object ) {
145
214
  };
146
215
  };
147
216
 
148
- $.Widget = function( options, element ) {
149
- // allow instantiation without initializing for simple inheritance
150
- if ( arguments.length ) {
151
- this._createWidget( options, element );
152
- }
153
- };
217
+ $.Widget = function( /* options, element */ ) {};
218
+ $.Widget._childConstructors = [];
154
219
 
155
220
  $.Widget.prototype = {
156
221
  widgetName: "widget",
157
222
  widgetEventPrefix: "",
223
+ defaultElement: "<div>",
158
224
  options: {
159
- disabled: false
225
+ disabled: false,
226
+
227
+ // callbacks
228
+ create: null
160
229
  },
161
230
  _createWidget: function( options, element ) {
162
- // $.widget.bridge stores the plugin instance, but we do it anyway
163
- // so that it's stored even before the _create function runs
164
- $.data( element, this.widgetName, this );
231
+ element = $( element || this.defaultElement || this )[ 0 ];
165
232
  this.element = $( element );
166
- this.options = $.extend( true, {},
233
+ this.uuid = uuid++;
234
+ this.eventNamespace = "." + this.widgetName + this.uuid;
235
+ this.options = $.widget.extend( {},
167
236
  this.options,
168
237
  this._getCreateOptions(),
169
238
  options );
170
239
 
171
- var self = this;
172
- this.element.bind( "remove." + this.widgetName, function() {
173
- self.destroy();
174
- });
240
+ this.bindings = $();
241
+ this.hoverable = $();
242
+ this.focusable = $();
243
+
244
+ if ( element !== this ) {
245
+ // 1.9 BC for #7810
246
+ // TODO remove dual storage
247
+ $.data( element, this.widgetName, this );
248
+ $.data( element, this.widgetFullName, this );
249
+ this._on( this.element, {
250
+ remove: function( event ) {
251
+ if ( event.target === element ) {
252
+ this.destroy();
253
+ }
254
+ }
255
+ });
256
+ this.document = $( element.style ?
257
+ // element within the document
258
+ element.ownerDocument :
259
+ // element is window or document
260
+ element.document || element );
261
+ this.window = $( this.document[0].defaultView || this.document[0].parentWindow );
262
+ }
175
263
 
176
264
  this._create();
177
- this._trigger( "create" );
265
+ this._trigger( "create", null, this._getCreateEventData() );
178
266
  this._init();
179
267
  },
180
- _getCreateOptions: function() {
181
- return $.metadata && $.metadata.get( this.element[0] )[ this.widgetName ];
182
- },
183
- _create: function() {},
184
- _init: function() {},
268
+ _getCreateOptions: $.noop,
269
+ _getCreateEventData: $.noop,
270
+ _create: $.noop,
271
+ _init: $.noop,
185
272
 
186
273
  destroy: function() {
274
+ this._destroy();
275
+ // we can probably remove the unbind calls in 2.0
276
+ // all event bindings should go through this._on()
187
277
  this.element
188
- .unbind( "." + this.widgetName )
189
- .removeData( this.widgetName );
278
+ .unbind( this.eventNamespace )
279
+ // 1.9 BC for #7810
280
+ // TODO remove dual storage
281
+ .removeData( this.widgetName )
282
+ .removeData( this.widgetFullName )
283
+ // support: jquery <1.6.3
284
+ // http://bugs.jquery.com/ticket/9413
285
+ .removeData( $.camelCase( this.widgetFullName ) );
190
286
  this.widget()
191
- .unbind( "." + this.widgetName )
287
+ .unbind( this.eventNamespace )
192
288
  .removeAttr( "aria-disabled" )
193
289
  .removeClass(
194
- this.widgetBaseClass + "-disabled " +
290
+ this.widgetFullName + "-disabled " +
195
291
  "ui-state-disabled" );
292
+
293
+ // clean up events and states
294
+ this.bindings.unbind( this.eventNamespace );
295
+ this.hoverable.removeClass( "ui-state-hover" );
296
+ this.focusable.removeClass( "ui-state-focus" );
196
297
  },
298
+ _destroy: $.noop,
197
299
 
198
300
  widget: function() {
199
301
  return this.element;
200
302
  },
201
303
 
202
304
  option: function( key, value ) {
203
- var options = key;
305
+ var options = key,
306
+ parts,
307
+ curOption,
308
+ i;
204
309
 
205
310
  if ( arguments.length === 0 ) {
206
311
  // don't return a reference to the internal hash
207
- return $.extend( {}, this.options );
312
+ return $.widget.extend( {}, this.options );
208
313
  }
209
314
 
210
- if (typeof key === "string" ) {
211
- if ( value === undefined ) {
212
- return this.options[ key ];
213
- }
315
+ if ( typeof key === "string" ) {
316
+ // handle nested keys, e.g., "foo.bar" => { foo: { bar: ___ } }
214
317
  options = {};
215
- options[ key ] = value;
318
+ parts = key.split( "." );
319
+ key = parts.shift();
320
+ if ( parts.length ) {
321
+ curOption = options[ key ] = $.widget.extend( {}, this.options[ key ] );
322
+ for ( i = 0; i < parts.length - 1; i++ ) {
323
+ curOption[ parts[ i ] ] = curOption[ parts[ i ] ] || {};
324
+ curOption = curOption[ parts[ i ] ];
325
+ }
326
+ key = parts.pop();
327
+ if ( value === undefined ) {
328
+ return curOption[ key ] === undefined ? null : curOption[ key ];
329
+ }
330
+ curOption[ key ] = value;
331
+ } else {
332
+ if ( value === undefined ) {
333
+ return this.options[ key ] === undefined ? null : this.options[ key ];
334
+ }
335
+ options[ key ] = value;
336
+ }
216
337
  }
217
338
 
218
339
  this._setOptions( options );
@@ -220,10 +341,11 @@ $.Widget.prototype = {
220
341
  return this;
221
342
  },
222
343
  _setOptions: function( options ) {
223
- var self = this;
224
- $.each( options, function( key, value ) {
225
- self._setOption( key, value );
226
- });
344
+ var key;
345
+
346
+ for ( key in options ) {
347
+ this._setOption( key, options[ key ] );
348
+ }
227
349
 
228
350
  return this;
229
351
  },
@@ -232,10 +354,10 @@ $.Widget.prototype = {
232
354
 
233
355
  if ( key === "disabled" ) {
234
356
  this.widget()
235
- [ value ? "addClass" : "removeClass"](
236
- this.widgetBaseClass + "-disabled" + " " +
237
- "ui-state-disabled" )
357
+ .toggleClass( this.widgetFullName + "-disabled ui-state-disabled", !!value )
238
358
  .attr( "aria-disabled", value );
359
+ this.hoverable.removeClass( "ui-state-hover" );
360
+ this.focusable.removeClass( "ui-state-focus" );
239
361
  }
240
362
 
241
363
  return this;
@@ -248,6 +370,88 @@ $.Widget.prototype = {
248
370
  return this._setOption( "disabled", true );
249
371
  },
250
372
 
373
+ _on: function( element, handlers ) {
374
+ var delegateElement,
375
+ instance = this;
376
+ // no element argument, shuffle and use this.element
377
+ if ( !handlers ) {
378
+ handlers = element;
379
+ element = this.element;
380
+ delegateElement = this.widget();
381
+ } else {
382
+ // accept selectors, DOM elements
383
+ element = delegateElement = $( element );
384
+ this.bindings = this.bindings.add( element );
385
+ }
386
+
387
+ $.each( handlers, function( event, handler ) {
388
+ function handlerProxy() {
389
+ // allow widgets to customize the disabled handling
390
+ // - disabled as an array instead of boolean
391
+ // - disabled class as method for disabling individual parts
392
+ if ( instance.options.disabled === true ||
393
+ $( this ).hasClass( "ui-state-disabled" ) ) {
394
+ return;
395
+ }
396
+ return ( typeof handler === "string" ? instance[ handler ] : handler )
397
+ .apply( instance, arguments );
398
+ }
399
+
400
+ // copy the guid so direct unbinding works
401
+ if ( typeof handler !== "string" ) {
402
+ handlerProxy.guid = handler.guid =
403
+ handler.guid || handlerProxy.guid || $.guid++;
404
+ }
405
+
406
+ var match = event.match( /^(\w+)\s*(.*)$/ ),
407
+ eventName = match[1] + instance.eventNamespace,
408
+ selector = match[2];
409
+ if ( selector ) {
410
+ delegateElement.delegate( selector, eventName, handlerProxy );
411
+ } else {
412
+ element.bind( eventName, handlerProxy );
413
+ }
414
+ });
415
+ },
416
+
417
+ _off: function( element, eventName ) {
418
+ eventName = (eventName || "").split( " " ).join( this.eventNamespace + " " ) + this.eventNamespace;
419
+ element.unbind( eventName ).undelegate( eventName );
420
+ },
421
+
422
+ _delay: function( handler, delay ) {
423
+ function handlerProxy() {
424
+ return ( typeof handler === "string" ? instance[ handler ] : handler )
425
+ .apply( instance, arguments );
426
+ }
427
+ var instance = this;
428
+ return setTimeout( handlerProxy, delay || 0 );
429
+ },
430
+
431
+ _hoverable: function( element ) {
432
+ this.hoverable = this.hoverable.add( element );
433
+ this._on( element, {
434
+ mouseenter: function( event ) {
435
+ $( event.currentTarget ).addClass( "ui-state-hover" );
436
+ },
437
+ mouseleave: function( event ) {
438
+ $( event.currentTarget ).removeClass( "ui-state-hover" );
439
+ }
440
+ });
441
+ },
442
+
443
+ _focusable: function( element ) {
444
+ this.focusable = this.focusable.add( element );
445
+ this._on( element, {
446
+ focusin: function( event ) {
447
+ $( event.currentTarget ).addClass( "ui-state-focus" );
448
+ },
449
+ focusout: function( event ) {
450
+ $( event.currentTarget ).removeClass( "ui-state-focus" );
451
+ }
452
+ });
453
+ },
454
+
251
455
  _trigger: function( type, event, data ) {
252
456
  var prop, orig,
253
457
  callback = this.options[ type ];
@@ -272,11 +476,53 @@ $.Widget.prototype = {
272
476
  }
273
477
 
274
478
  this.element.trigger( event, data );
275
-
276
- return !( $.isFunction(callback) &&
277
- callback.call( this.element[0], event, data ) === false ||
479
+ return !( $.isFunction( callback ) &&
480
+ callback.apply( this.element[0], [ event ].concat( data ) ) === false ||
278
481
  event.isDefaultPrevented() );
279
482
  }
280
483
  };
281
484
 
485
+ $.each( { show: "fadeIn", hide: "fadeOut" }, function( method, defaultEffect ) {
486
+ $.Widget.prototype[ "_" + method ] = function( element, options, callback ) {
487
+ if ( typeof options === "string" ) {
488
+ options = { effect: options };
489
+ }
490
+ var hasOptions,
491
+ effectName = !options ?
492
+ method :
493
+ options === true || typeof options === "number" ?
494
+ defaultEffect :
495
+ options.effect || defaultEffect;
496
+ options = options || {};
497
+ if ( typeof options === "number" ) {
498
+ options = { duration: options };
499
+ }
500
+ hasOptions = !$.isEmptyObject( options );
501
+ options.complete = callback;
502
+ if ( options.delay ) {
503
+ element.delay( options.delay );
504
+ }
505
+ if ( hasOptions && $.effects && ( $.effects.effect[ effectName ] || $.uiBackCompat !== false && $.effects[ effectName ] ) ) {
506
+ element[ method ]( options );
507
+ } else if ( effectName !== method && element[ effectName ] ) {
508
+ element[ effectName ]( options.duration, options.easing, callback );
509
+ } else {
510
+ element.queue(function( next ) {
511
+ $( this )[ method ]();
512
+ if ( callback ) {
513
+ callback.call( element[ 0 ] );
514
+ }
515
+ next();
516
+ });
517
+ }
518
+ };
519
+ });
520
+
521
+ // DEPRECATED
522
+ if ( $.uiBackCompat !== false ) {
523
+ $.Widget.prototype._getCreateOptions = function() {
524
+ return $.metadata && $.metadata.get( this.element[0] )[ this.widgetName ];
525
+ };
526
+ }
527
+
282
528
  }));