Projet

Général

Profil

Révision 503b3f7b

Ajouté par Assos Assos il y a environ 10 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/jquery_update/replace/ui/ui/jquery.ui.widget.js
1 1
/*!
2
 * jQuery UI Widget 1.8.11
2
 * jQuery UI Widget 1.10.2
3
 * http://jqueryui.com
3 4
 *
4
 * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
5
 * Dual licensed under the MIT or GPL Version 2 licenses.
5
 * Copyright 2013 jQuery Foundation and other contributors
6
 * Released under the MIT license.
6 7
 * http://jquery.org/license
7 8
 *
8
 * http://docs.jquery.com/UI/Widget
9
 * http://api.jqueryui.com/jQuery.widget/
9 10
 */
10 11
(function( $, undefined ) {
11 12

  
12
// jQuery 1.4+
13
if ( $.cleanData ) {
14
	var _cleanData = $.cleanData;
15
	$.cleanData = function( elems ) {
16
		for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
13
var uuid = 0,
14
	slice = Array.prototype.slice,
15
	_cleanData = $.cleanData;
16
$.cleanData = function( elems ) {
17
	for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
18
		try {
17 19
			$( elem ).triggerHandler( "remove" );
18
		}
19
		_cleanData( elems );
20
	};
21
} else {
22
	var _remove = $.fn.remove;
23
	$.fn.remove = function( selector, keepData ) {
24
		return this.each(function() {
25
			if ( !keepData ) {
26
				if ( !selector || $.filter( selector, [ this ] ).length ) {
27
					$( "*", this ).add( [ this ] ).each(function() {
28
						$( this ).triggerHandler( "remove" );
29
					});
30
				}
31
			}
32
			return _remove.call( $(this), selector, keepData );
33
		});
34
	};
35
}
20
		// http://bugs.jquery.com/ticket/8235
21
		} catch( e ) {}
22
	}
23
	_cleanData( elems );
24
};
36 25

  
37 26
$.widget = function( name, base, prototype ) {
38
	var namespace = name.split( "." )[ 0 ],
39
		fullName;
27
	var fullName, existingConstructor, constructor, basePrototype,
28
		// proxiedPrototype allows the provided prototype to remain unmodified
29
		// so that it can be used as a mixin for multiple widgets (#8876)
30
		proxiedPrototype = {},
31
		namespace = name.split( "." )[ 0 ];
32

  
40 33
	name = name.split( "." )[ 1 ];
41 34
	fullName = namespace + "-" + name;
42 35

  
......
46 39
	}
47 40

  
48 41
	// create selector for plugin
49
	$.expr[ ":" ][ fullName ] = function( elem ) {
50
		return !!$.data( elem, name );
42
	$.expr[ ":" ][ fullName.toLowerCase() ] = function( elem ) {
43
		return !!$.data( elem, fullName );
51 44
	};
52 45

  
53 46
	$[ namespace ] = $[ namespace ] || {};
54
	$[ namespace ][ name ] = function( options, element ) {
47
	existingConstructor = $[ namespace ][ name ];
48
	constructor = $[ namespace ][ name ] = function( options, element ) {
49
		// allow instantiation without "new" keyword
50
		if ( !this._createWidget ) {
51
			return new constructor( options, element );
52
		}
53

  
55 54
		// allow instantiation without initializing for simple inheritance
55
		// must use "new" keyword (the code above always passes args)
56 56
		if ( arguments.length ) {
57 57
			this._createWidget( options, element );
58 58
		}
59 59
	};
60

  
61
	var basePrototype = new base();
60
	// extend with the existing constructor to carry over any static properties
61
	$.extend( constructor, existingConstructor, {
62
		version: prototype.version,
63
		// copy the object used to create the prototype in case we need to
64
		// redefine the widget later
65
		_proto: $.extend( {}, prototype ),
66
		// track widgets that inherit from this widget in case this widget is
67
		// redefined after a widget inherits from it
68
		_childConstructors: []
69
	});
70

  
71
	basePrototype = new base();
62 72
	// we need to make the options hash a property directly on the new instance
63 73
	// otherwise we'll modify the options hash on the prototype that we're
64 74
	// inheriting from
65
//	$.each( basePrototype, function( key, val ) {
66
//		if ( $.isPlainObject(val) ) {
67
//			basePrototype[ key ] = $.extend( {}, val );
68
//		}
69
//	});
70
	basePrototype.options = $.extend( true, {}, basePrototype.options );
71
	$[ namespace ][ name ].prototype = $.extend( true, basePrototype, {
75
	basePrototype.options = $.widget.extend( {}, basePrototype.options );
76
	$.each( prototype, function( prop, value ) {
77
		if ( !$.isFunction( value ) ) {
78
			proxiedPrototype[ prop ] = value;
79
			return;
80
		}
81
		proxiedPrototype[ prop ] = (function() {
82
			var _super = function() {
83
					return base.prototype[ prop ].apply( this, arguments );
84
				},
85
				_superApply = function( args ) {
86
					return base.prototype[ prop ].apply( this, args );
87
				};
88
			return function() {
89
				var __super = this._super,
90
					__superApply = this._superApply,
91
					returnValue;
92

  
93
				this._super = _super;
94
				this._superApply = _superApply;
95

  
96
				returnValue = value.apply( this, arguments );
97

  
98
				this._super = __super;
99
				this._superApply = __superApply;
100

  
101
				return returnValue;
102
			};
103
		})();
104
	});
105
	constructor.prototype = $.widget.extend( basePrototype, {
106
		// TODO: remove support for widgetEventPrefix
107
		// always use the name + a colon as the prefix, e.g., draggable:start
108
		// don't prefix for widgets that aren't DOM-based
109
		widgetEventPrefix: existingConstructor ? basePrototype.widgetEventPrefix : name
110
	}, proxiedPrototype, {
111
		constructor: constructor,
72 112
		namespace: namespace,
73 113
		widgetName: name,
74
		widgetEventPrefix: $[ namespace ][ name ].prototype.widgetEventPrefix || name,
75
		widgetBaseClass: fullName
76
	}, prototype );
114
		widgetFullName: fullName
115
	});
116

  
117
	// If this widget is being redefined then we need to find all widgets that
118
	// are inheriting from it and redefine all of them so that they inherit from
119
	// the new version of this widget. We're essentially trying to replace one
120
	// level in the prototype chain.
121
	if ( existingConstructor ) {
122
		$.each( existingConstructor._childConstructors, function( i, child ) {
123
			var childPrototype = child.prototype;
124

  
125
			// redefine the child widget using the same prototype that was
126
			// originally used, but inherit from the new version of the base
127
			$.widget( childPrototype.namespace + "." + childPrototype.widgetName, constructor, child._proto );
128
		});
129
		// remove the list of existing child constructors from the old constructor
130
		// so the old child constructors can be garbage collected
131
		delete existingConstructor._childConstructors;
132
	} else {
133
		base._childConstructors.push( constructor );
134
	}
135

  
136
	$.widget.bridge( name, constructor );
137
};
77 138

  
78
	$.widget.bridge( name, $[ namespace ][ name ] );
139
$.widget.extend = function( target ) {
140
	var input = slice.call( arguments, 1 ),
141
		inputIndex = 0,
142
		inputLength = input.length,
143
		key,
144
		value;
145
	for ( ; inputIndex < inputLength; inputIndex++ ) {
146
		for ( key in input[ inputIndex ] ) {
147
			value = input[ inputIndex ][ key ];
148
			if ( input[ inputIndex ].hasOwnProperty( key ) && value !== undefined ) {
149
				// Clone objects
150
				if ( $.isPlainObject( value ) ) {
151
					target[ key ] = $.isPlainObject( target[ key ] ) ?
152
						$.widget.extend( {}, target[ key ], value ) :
153
						// Don't extend strings, arrays, etc. with objects
154
						$.widget.extend( {}, value );
155
				// Copy everything else by reference
156
				} else {
157
					target[ key ] = value;
158
				}
159
			}
160
		}
161
	}
162
	return target;
79 163
};
80 164

  
81 165
$.widget.bridge = function( name, object ) {
166
	var fullName = object.prototype.widgetFullName || name;
82 167
	$.fn[ name ] = function( options ) {
83 168
		var isMethodCall = typeof options === "string",
84
			args = Array.prototype.slice.call( arguments, 1 ),
169
			args = slice.call( arguments, 1 ),
85 170
			returnValue = this;
86 171

  
87 172
		// allow multiple hashes to be passed on init
88 173
		options = !isMethodCall && args.length ?
89
			$.extend.apply( null, [ true, options ].concat(args) ) :
174
			$.widget.extend.apply( null, [ options ].concat(args) ) :
90 175
			options;
91 176

  
92
		// prevent calls to internal methods
93
		if ( isMethodCall && options.charAt( 0 ) === "_" ) {
94
			return returnValue;
95
		}
96

  
97 177
		if ( isMethodCall ) {
98 178
			this.each(function() {
99
				var instance = $.data( this, name ),
100
					methodValue = instance && $.isFunction( instance[options] ) ?
101
						instance[ options ].apply( instance, args ) :
102
						instance;
103
				// TODO: add this back in 1.9 and use $.error() (see #5972)
104
//				if ( !instance ) {
105
//					throw "cannot call methods on " + name + " prior to initialization; " +
106
//						"attempted to call method '" + options + "'";
107
//				}
108
//				if ( !$.isFunction( instance[options] ) ) {
109
//					throw "no such method '" + options + "' for " + name + " widget instance";
110
//				}
111
//				var methodValue = instance[ options ].apply( instance, args );
179
				var methodValue,
180
					instance = $.data( this, fullName );
181
				if ( !instance ) {
182
					return $.error( "cannot call methods on " + name + " prior to initialization; " +
183
						"attempted to call method '" + options + "'" );
184
				}
185
				if ( !$.isFunction( instance[options] ) || options.charAt( 0 ) === "_" ) {
186
					return $.error( "no such method '" + options + "' for " + name + " widget instance" );
187
				}
188
				methodValue = instance[ options ].apply( instance, args );
112 189
				if ( methodValue !== instance && methodValue !== undefined ) {
113
					returnValue = methodValue;
190
					returnValue = methodValue && methodValue.jquery ?
191
						returnValue.pushStack( methodValue.get() ) :
192
						methodValue;
114 193
					return false;
115 194
				}
116 195
			});
117 196
		} else {
118 197
			this.each(function() {
119
				var instance = $.data( this, name );
198
				var instance = $.data( this, fullName );
120 199
				if ( instance ) {
121 200
					instance.option( options || {} )._init();
122 201
				} else {
123
					$.data( this, name, new object( options, this ) );
202
					$.data( this, fullName, new object( options, this ) );
124 203
				}
125 204
			});
126 205
		}
......
129 208
	};
130 209
};
131 210

  
132
$.Widget = function( options, element ) {
133
	// allow instantiation without initializing for simple inheritance
134
	if ( arguments.length ) {
135
		this._createWidget( options, element );
136
	}
137
};
211
$.Widget = function( /* options, element */ ) {};
212
$.Widget._childConstructors = [];
138 213

  
139 214
$.Widget.prototype = {
140 215
	widgetName: "widget",
141 216
	widgetEventPrefix: "",
217
	defaultElement: "<div>",
142 218
	options: {
143
		disabled: false
219
		disabled: false,
220

  
221
		// callbacks
222
		create: null
144 223
	},
145 224
	_createWidget: function( options, element ) {
146
		// $.widget.bridge stores the plugin instance, but we do it anyway
147
		// so that it's stored even before the _create function runs
148
		$.data( element, this.widgetName, this );
225
		element = $( element || this.defaultElement || this )[ 0 ];
149 226
		this.element = $( element );
150
		this.options = $.extend( true, {},
227
		this.uuid = uuid++;
228
		this.eventNamespace = "." + this.widgetName + this.uuid;
229
		this.options = $.widget.extend( {},
151 230
			this.options,
152 231
			this._getCreateOptions(),
153 232
			options );
154 233

  
155
		var self = this;
156
		this.element.bind( "remove." + this.widgetName, function() {
157
			self.destroy();
158
		});
234
		this.bindings = $();
235
		this.hoverable = $();
236
		this.focusable = $();
237

  
238
		if ( element !== this ) {
239
			$.data( element, this.widgetFullName, this );
240
			this._on( true, this.element, {
241
				remove: function( event ) {
242
					if ( event.target === element ) {
243
						this.destroy();
244
					}
245
				}
246
			});
247
			this.document = $( element.style ?
248
				// element within the document
249
				element.ownerDocument :
250
				// element is window or document
251
				element.document || element );
252
			this.window = $( this.document[0].defaultView || this.document[0].parentWindow );
253
		}
159 254

  
160 255
		this._create();
161
		this._trigger( "create" );
256
		this._trigger( "create", null, this._getCreateEventData() );
162 257
		this._init();
163 258
	},
164
	_getCreateOptions: function() {
165
		return $.metadata && $.metadata.get( this.element[0] )[ this.widgetName ];
166
	},
167
	_create: function() {},
168
	_init: function() {},
259
	_getCreateOptions: $.noop,
260
	_getCreateEventData: $.noop,
261
	_create: $.noop,
262
	_init: $.noop,
169 263

  
170 264
	destroy: function() {
265
		this._destroy();
266
		// we can probably remove the unbind calls in 2.0
267
		// all event bindings should go through this._on()
171 268
		this.element
172
			.unbind( "." + this.widgetName )
173
			.removeData( this.widgetName );
269
			.unbind( this.eventNamespace )
270
			// 1.9 BC for #7810
271
			// TODO remove dual storage
272
			.removeData( this.widgetName )
273
			.removeData( this.widgetFullName )
274
			// support: jquery <1.6.3
275
			// http://bugs.jquery.com/ticket/9413
276
			.removeData( $.camelCase( this.widgetFullName ) );
174 277
		this.widget()
175
			.unbind( "." + this.widgetName )
278
			.unbind( this.eventNamespace )
176 279
			.removeAttr( "aria-disabled" )
177 280
			.removeClass(
178
				this.widgetBaseClass + "-disabled " +
281
				this.widgetFullName + "-disabled " +
179 282
				"ui-state-disabled" );
283

  
284
		// clean up events and states
285
		this.bindings.unbind( this.eventNamespace );
286
		this.hoverable.removeClass( "ui-state-hover" );
287
		this.focusable.removeClass( "ui-state-focus" );
180 288
	},
289
	_destroy: $.noop,
181 290

  
182 291
	widget: function() {
183 292
		return this.element;
184 293
	},
185 294

  
186 295
	option: function( key, value ) {
187
		var options = key;
296
		var options = key,
297
			parts,
298
			curOption,
299
			i;
188 300

  
189 301
		if ( arguments.length === 0 ) {
190 302
			// don't return a reference to the internal hash
191
			return $.extend( {}, this.options );
303
			return $.widget.extend( {}, this.options );
192 304
		}
193 305

  
194
		if  (typeof key === "string" ) {
195
			if ( value === undefined ) {
196
				return this.options[ key ];
197
			}
306
		if ( typeof key === "string" ) {
307
			// handle nested keys, e.g., "foo.bar" => { foo: { bar: ___ } }
198 308
			options = {};
199
			options[ key ] = value;
309
			parts = key.split( "." );
310
			key = parts.shift();
311
			if ( parts.length ) {
312
				curOption = options[ key ] = $.widget.extend( {}, this.options[ key ] );
313
				for ( i = 0; i < parts.length - 1; i++ ) {
314
					curOption[ parts[ i ] ] = curOption[ parts[ i ] ] || {};
315
					curOption = curOption[ parts[ i ] ];
316
				}
317
				key = parts.pop();
318
				if ( value === undefined ) {
319
					return curOption[ key ] === undefined ? null : curOption[ key ];
320
				}
321
				curOption[ key ] = value;
322
			} else {
323
				if ( value === undefined ) {
324
					return this.options[ key ] === undefined ? null : this.options[ key ];
325
				}
326
				options[ key ] = value;
327
			}
200 328
		}
201 329

  
202 330
		this._setOptions( options );
......
204 332
		return this;
205 333
	},
206 334
	_setOptions: function( options ) {
207
		var self = this;
208
		$.each( options, function( key, value ) {
209
			self._setOption( key, value );
210
		});
335
		var key;
336

  
337
		for ( key in options ) {
338
			this._setOption( key, options[ key ] );
339
		}
211 340

  
212 341
		return this;
213 342
	},
......
216 345

  
217 346
		if ( key === "disabled" ) {
218 347
			this.widget()
219
				[ value ? "addClass" : "removeClass"](
220
					this.widgetBaseClass + "-disabled" + " " +
221
					"ui-state-disabled" )
348
				.toggleClass( this.widgetFullName + "-disabled ui-state-disabled", !!value )
222 349
				.attr( "aria-disabled", value );
350
			this.hoverable.removeClass( "ui-state-hover" );
351
			this.focusable.removeClass( "ui-state-focus" );
223 352
		}
224 353

  
225 354
		return this;
......
232 361
		return this._setOption( "disabled", true );
233 362
	},
234 363

  
364
	_on: function( suppressDisabledCheck, element, handlers ) {
365
		var delegateElement,
366
			instance = this;
367

  
368
		// no suppressDisabledCheck flag, shuffle arguments
369
		if ( typeof suppressDisabledCheck !== "boolean" ) {
370
			handlers = element;
371
			element = suppressDisabledCheck;
372
			suppressDisabledCheck = false;
373
		}
374

  
375
		// no element argument, shuffle and use this.element
376
		if ( !handlers ) {
377
			handlers = element;
378
			element = this.element;
379
			delegateElement = this.widget();
380
		} else {
381
			// accept selectors, DOM elements
382
			element = delegateElement = $( element );
383
			this.bindings = this.bindings.add( element );
384
		}
385

  
386
		$.each( handlers, function( event, handler ) {
387
			function handlerProxy() {
388
				// allow widgets to customize the disabled handling
389
				// - disabled as an array instead of boolean
390
				// - disabled class as method for disabling individual parts
391
				if ( !suppressDisabledCheck &&
392
						( 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

  
235 455
	_trigger: function( type, event, data ) {
236
		var callback = this.options[ type ];
456
		var prop, orig,
457
			callback = this.options[ type ];
237 458

  
459
		data = data || {};
238 460
		event = $.Event( event );
239 461
		event.type = ( type === this.widgetEventPrefix ?
240 462
			type :
241 463
			this.widgetEventPrefix + type ).toLowerCase();
242
		data = data || {};
464
		// the original event may come from any element
465
		// so we need to reset the target on the new event
466
		event.target = this.element[ 0 ];
243 467

  
244 468
		// copy original event properties over to the new event
245
		// this would happen if we could call $.event.fix instead of $.Event
246
		// but we don't have a way to force an event to be fixed multiple times
247
		if ( event.originalEvent ) {
248
			for ( var i = $.event.props.length, prop; i; ) {
249
				prop = $.event.props[ --i ];
250
				event[ prop ] = event.originalEvent[ prop ];
469
		orig = event.originalEvent;
470
		if ( orig ) {
471
			for ( prop in orig ) {
472
				if ( !( prop in event ) ) {
473
					event[ prop ] = orig[ prop ];
474
				}
251 475
			}
252 476
		}
253 477

  
254 478
		this.element.trigger( event, data );
255

  
256
		return !( $.isFunction(callback) &&
257
			callback.call( this.element[0], event, data ) === false ||
479
		return !( $.isFunction( callback ) &&
480
			callback.apply( this.element[0], [ event ].concat( data ) ) === false ||
258 481
			event.isDefaultPrevented() );
259 482
	}
260 483
};
261 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 ] ) {
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

  
262 521
})( jQuery );

Formats disponibles : Unified diff