1 /*! jQuery UI - v1.11.4+CommonJS - 2015-08-28
\r
2 * http://jqueryui.com
\r
3 * Includes: widget.js
\r
4 * Copyright 2015 jQuery Foundation and other contributors; Licensed MIT */
\r
6 (function( factory ) {
\r
7 if ( typeof define === "function" && define.amd ) {
\r
9 // AMD. Register as an anonymous module.
\r
10 define([ "jquery" ], factory );
\r
12 } else if ( typeof exports === "object" ) {
\r
15 factory( require( "jquery" ) );
\r
24 * jQuery UI Widget 1.11.4
\r
25 * http://jqueryui.com
\r
27 * Copyright jQuery Foundation and other contributors
\r
28 * Released under the MIT license.
\r
29 * http://jquery.org/license
\r
31 * http://api.jqueryui.com/jQuery.widget/
\r
35 var widget_uuid = 0,
\r
36 widget_slice = Array.prototype.slice;
\r
38 $.cleanData = (function( orig ) {
\r
39 return function( elems ) {
\r
40 var events, elem, i;
\r
41 for ( i = 0; (elem = elems[i]) != null; i++ ) {
\r
44 // Only trigger remove when necessary to save time
\r
45 events = $._data( elem, "events" );
\r
46 if ( events && events.remove ) {
\r
47 $( elem ).triggerHandler( "remove" );
\r
50 // http://bugs.jquery.com/ticket/8235
\r
57 $.widget = function( name, base, prototype ) {
\r
58 var fullName, existingConstructor, constructor, basePrototype,
\r
59 // proxiedPrototype allows the provided prototype to remain unmodified
\r
60 // so that it can be used as a mixin for multiple widgets (#8876)
\r
61 proxiedPrototype = {},
\r
62 namespace = name.split( "." )[ 0 ];
\r
64 name = name.split( "." )[ 1 ];
\r
65 fullName = namespace + "-" + name;
\r
72 // create selector for plugin
\r
73 $.expr[ ":" ][ fullName.toLowerCase() ] = function( elem ) {
\r
74 return !!$.data( elem, fullName );
\r
77 $[ namespace ] = $[ namespace ] || {};
\r
78 existingConstructor = $[ namespace ][ name ];
\r
79 constructor = $[ namespace ][ name ] = function( options, element ) {
\r
80 // allow instantiation without "new" keyword
\r
81 if ( !this._createWidget ) {
\r
82 return new constructor( options, element );
\r
85 // allow instantiation without initializing for simple inheritance
\r
86 // must use "new" keyword (the code above always passes args)
\r
87 if ( arguments.length ) {
\r
88 this._createWidget( options, element );
\r
91 // extend with the existing constructor to carry over any static properties
\r
92 $.extend( constructor, existingConstructor, {
\r
93 version: prototype.version,
\r
94 // copy the object used to create the prototype in case we need to
\r
95 // redefine the widget later
\r
96 _proto: $.extend( {}, prototype ),
\r
97 // track widgets that inherit from this widget in case this widget is
\r
98 // redefined after a widget inherits from it
\r
99 _childConstructors: []
\r
102 basePrototype = new base();
\r
103 // we need to make the options hash a property directly on the new instance
\r
104 // otherwise we'll modify the options hash on the prototype that we're
\r
106 basePrototype.options = $.widget.extend( {}, basePrototype.options );
\r
107 $.each( prototype, function( prop, value ) {
\r
108 if ( !$.isFunction( value ) ) {
\r
109 proxiedPrototype[ prop ] = value;
\r
112 proxiedPrototype[ prop ] = (function() {
\r
113 var _super = function() {
\r
114 return base.prototype[ prop ].apply( this, arguments );
\r
116 _superApply = function( args ) {
\r
117 return base.prototype[ prop ].apply( this, args );
\r
119 return function() {
\r
120 var __super = this._super,
\r
121 __superApply = this._superApply,
\r
124 this._super = _super;
\r
125 this._superApply = _superApply;
\r
127 returnValue = value.apply( this, arguments );
\r
129 this._super = __super;
\r
130 this._superApply = __superApply;
\r
132 return returnValue;
\r
136 constructor.prototype = $.widget.extend( basePrototype, {
\r
137 // TODO: remove support for widgetEventPrefix
\r
138 // always use the name + a colon as the prefix, e.g., draggable:start
\r
139 // don't prefix for widgets that aren't DOM-based
\r
140 widgetEventPrefix: existingConstructor ? (basePrototype.widgetEventPrefix || name) : name
\r
141 }, proxiedPrototype, {
\r
142 constructor: constructor,
\r
143 namespace: namespace,
\r
145 widgetFullName: fullName
\r
148 // If this widget is being redefined then we need to find all widgets that
\r
149 // are inheriting from it and redefine all of them so that they inherit from
\r
150 // the new version of this widget. We're essentially trying to replace one
\r
151 // level in the prototype chain.
\r
152 if ( existingConstructor ) {
\r
153 $.each( existingConstructor._childConstructors, function( i, child ) {
\r
154 var childPrototype = child.prototype;
\r
156 // redefine the child widget using the same prototype that was
\r
157 // originally used, but inherit from the new version of the base
\r
158 $.widget( childPrototype.namespace + "." + childPrototype.widgetName, constructor, child._proto );
\r
160 // remove the list of existing child constructors from the old constructor
\r
161 // so the old child constructors can be garbage collected
\r
162 delete existingConstructor._childConstructors;
\r
164 base._childConstructors.push( constructor );
\r
167 $.widget.bridge( name, constructor );
\r
169 return constructor;
\r
172 $.widget.extend = function( target ) {
\r
173 var input = widget_slice.call( arguments, 1 ),
\r
175 inputLength = input.length,
\r
178 for ( ; inputIndex < inputLength; inputIndex++ ) {
\r
179 for ( key in input[ inputIndex ] ) {
\r
180 value = input[ inputIndex ][ key ];
\r
181 if ( input[ inputIndex ].hasOwnProperty( key ) && value !== undefined ) {
\r
183 if ( $.isPlainObject( value ) ) {
\r
184 target[ key ] = $.isPlainObject( target[ key ] ) ?
\r
185 $.widget.extend( {}, target[ key ], value ) :
\r
186 // Don't extend strings, arrays, etc. with objects
\r
187 $.widget.extend( {}, value );
\r
188 // Copy everything else by reference
\r
190 target[ key ] = value;
\r
198 $.widget.bridge = function( name, object ) {
\r
199 var fullName = object.prototype.widgetFullName || name;
\r
200 $.fn[ name ] = function( options ) {
\r
201 var isMethodCall = typeof options === "string",
\r
202 args = widget_slice.call( arguments, 1 ),
\r
203 returnValue = this;
\r
205 if ( isMethodCall ) {
\r
206 this.each(function() {
\r
208 instance = $.data( this, fullName );
\r
209 if ( options === "instance" ) {
\r
210 returnValue = instance;
\r
214 return $.error( "cannot call methods on " + name + " prior to initialization; " +
\r
215 "attempted to call method '" + options + "'" );
\r
217 if ( !$.isFunction( instance[options] ) || options.charAt( 0 ) === "_" ) {
\r
218 return $.error( "no such method '" + options + "' for " + name + " widget instance" );
\r
220 methodValue = instance[ options ].apply( instance, args );
\r
221 if ( methodValue !== instance && methodValue !== undefined ) {
\r
222 returnValue = methodValue && methodValue.jquery ?
\r
223 returnValue.pushStack( methodValue.get() ) :
\r
230 // Allow multiple hashes to be passed on init
\r
231 if ( args.length ) {
\r
232 options = $.widget.extend.apply( null, [ options ].concat(args) );
\r
235 this.each(function() {
\r
236 var instance = $.data( this, fullName );
\r
238 instance.option( options || {} );
\r
239 if ( instance._init ) {
\r
243 $.data( this, fullName, new object( options, this ) );
\r
248 return returnValue;
\r
252 $.Widget = function( /* options, element */ ) {};
\r
253 $.Widget._childConstructors = [];
\r
255 $.Widget.prototype = {
\r
256 widgetName: "widget",
\r
257 widgetEventPrefix: "",
\r
258 defaultElement: "<div>",
\r
265 _createWidget: function( options, element ) {
\r
266 element = $( element || this.defaultElement || this )[ 0 ];
\r
267 this.element = $( element );
\r
268 this.uuid = widget_uuid++;
\r
269 this.eventNamespace = "." + this.widgetName + this.uuid;
\r
271 this.bindings = $();
\r
272 this.hoverable = $();
\r
273 this.focusable = $();
\r
275 if ( element !== this ) {
\r
276 $.data( element, this.widgetFullName, this );
\r
277 this._on( true, this.element, {
\r
278 remove: function( event ) {
\r
279 if ( event.target === element ) {
\r
284 this.document = $( element.style ?
\r
285 // element within the document
\r
286 element.ownerDocument :
\r
287 // element is window or document
\r
288 element.document || element );
\r
289 this.window = $( this.document[0].defaultView || this.document[0].parentWindow );
\r
292 this.options = $.widget.extend( {},
\r
294 this._getCreateOptions(),
\r
298 this._trigger( "create", null, this._getCreateEventData() );
\r
301 _getCreateOptions: $.noop,
\r
302 _getCreateEventData: $.noop,
\r
306 destroy: function() {
\r
308 // we can probably remove the unbind calls in 2.0
\r
309 // all event bindings should go through this._on()
\r
311 .unbind( this.eventNamespace )
\r
312 .removeData( this.widgetFullName )
\r
313 // support: jquery <1.6.3
\r
314 // http://bugs.jquery.com/ticket/9413
\r
315 .removeData( $.camelCase( this.widgetFullName ) );
\r
317 .unbind( this.eventNamespace )
\r
318 .removeAttr( "aria-disabled" )
\r
320 this.widgetFullName + "-disabled " +
\r
321 "ui-state-disabled" );
\r
323 // clean up events and states
\r
324 this.bindings.unbind( this.eventNamespace );
\r
325 this.hoverable.removeClass( "ui-state-hover" );
\r
326 this.focusable.removeClass( "ui-state-focus" );
\r
330 widget: function() {
\r
331 return this.element;
\r
334 option: function( key, value ) {
\r
340 if ( arguments.length === 0 ) {
\r
341 // don't return a reference to the internal hash
\r
342 return $.widget.extend( {}, this.options );
\r
345 if ( typeof key === "string" ) {
\r
346 // handle nested keys, e.g., "foo.bar" => { foo: { bar: ___ } }
\r
348 parts = key.split( "." );
\r
349 key = parts.shift();
\r
350 if ( parts.length ) {
\r
351 curOption = options[ key ] = $.widget.extend( {}, this.options[ key ] );
\r
352 for ( i = 0; i < parts.length - 1; i++ ) {
\r
353 curOption[ parts[ i ] ] = curOption[ parts[ i ] ] || {};
\r
354 curOption = curOption[ parts[ i ] ];
\r
357 if ( arguments.length === 1 ) {
\r
358 return curOption[ key ] === undefined ? null : curOption[ key ];
\r
360 curOption[ key ] = value;
\r
362 if ( arguments.length === 1 ) {
\r
363 return this.options[ key ] === undefined ? null : this.options[ key ];
\r
365 options[ key ] = value;
\r
369 this._setOptions( options );
\r
373 _setOptions: function( options ) {
\r
376 for ( key in options ) {
\r
377 this._setOption( key, options[ key ] );
\r
382 _setOption: function( key, value ) {
\r
383 this.options[ key ] = value;
\r
385 if ( key === "disabled" ) {
\r
387 .toggleClass( this.widgetFullName + "-disabled", !!value );
\r
389 // If the widget is becoming disabled, then nothing is interactive
\r
391 this.hoverable.removeClass( "ui-state-hover" );
\r
392 this.focusable.removeClass( "ui-state-focus" );
\r
399 enable: function() {
\r
400 return this._setOptions({ disabled: false });
\r
402 disable: function() {
\r
403 return this._setOptions({ disabled: true });
\r
406 _on: function( suppressDisabledCheck, element, handlers ) {
\r
407 var delegateElement,
\r
410 // no suppressDisabledCheck flag, shuffle arguments
\r
411 if ( typeof suppressDisabledCheck !== "boolean" ) {
\r
412 handlers = element;
\r
413 element = suppressDisabledCheck;
\r
414 suppressDisabledCheck = false;
\r
417 // no element argument, shuffle and use this.element
\r
419 handlers = element;
\r
420 element = this.element;
\r
421 delegateElement = this.widget();
\r
423 element = delegateElement = $( element );
\r
424 this.bindings = this.bindings.add( element );
\r
427 $.each( handlers, function( event, handler ) {
\r
428 function handlerProxy() {
\r
429 // allow widgets to customize the disabled handling
\r
430 // - disabled as an array instead of boolean
\r
431 // - disabled class as method for disabling individual parts
\r
432 if ( !suppressDisabledCheck &&
\r
433 ( instance.options.disabled === true ||
\r
434 $( this ).hasClass( "ui-state-disabled" ) ) ) {
\r
437 return ( typeof handler === "string" ? instance[ handler ] : handler )
\r
438 .apply( instance, arguments );
\r
441 // copy the guid so direct unbinding works
\r
442 if ( typeof handler !== "string" ) {
\r
443 handlerProxy.guid = handler.guid =
\r
444 handler.guid || handlerProxy.guid || $.guid++;
\r
447 var match = event.match( /^([\w:-]*)\s*(.*)$/ ),
\r
448 eventName = match[1] + instance.eventNamespace,
\r
449 selector = match[2];
\r
451 delegateElement.delegate( selector, eventName, handlerProxy );
\r
453 element.bind( eventName, handlerProxy );
\r
458 _off: function( element, eventName ) {
\r
459 eventName = (eventName || "").split( " " ).join( this.eventNamespace + " " ) +
\r
460 this.eventNamespace;
\r
461 element.unbind( eventName ).undelegate( eventName );
\r
463 // Clear the stack to avoid memory leaks (#10056)
\r
464 this.bindings = $( this.bindings.not( element ).get() );
\r
465 this.focusable = $( this.focusable.not( element ).get() );
\r
466 this.hoverable = $( this.hoverable.not( element ).get() );
\r
469 _delay: function( handler, delay ) {
\r
470 function handlerProxy() {
\r
471 return ( typeof handler === "string" ? instance[ handler ] : handler )
\r
472 .apply( instance, arguments );
\r
474 var instance = this;
\r
475 return setTimeout( handlerProxy, delay || 0 );
\r
478 _hoverable: function( element ) {
\r
479 this.hoverable = this.hoverable.add( element );
\r
480 this._on( element, {
\r
481 mouseenter: function( event ) {
\r
482 $( event.currentTarget ).addClass( "ui-state-hover" );
\r
484 mouseleave: function( event ) {
\r
485 $( event.currentTarget ).removeClass( "ui-state-hover" );
\r
490 _focusable: function( element ) {
\r
491 this.focusable = this.focusable.add( element );
\r
492 this._on( element, {
\r
493 focusin: function( event ) {
\r
494 $( event.currentTarget ).addClass( "ui-state-focus" );
\r
496 focusout: function( event ) {
\r
497 $( event.currentTarget ).removeClass( "ui-state-focus" );
\r
502 _trigger: function( type, event, data ) {
\r
504 callback = this.options[ type ];
\r
507 event = $.Event( event );
\r
508 event.type = ( type === this.widgetEventPrefix ?
\r
510 this.widgetEventPrefix + type ).toLowerCase();
\r
511 // the original event may come from any element
\r
512 // so we need to reset the target on the new event
\r
513 event.target = this.element[ 0 ];
\r
515 // copy original event properties over to the new event
\r
516 orig = event.originalEvent;
\r
518 for ( prop in orig ) {
\r
519 if ( !( prop in event ) ) {
\r
520 event[ prop ] = orig[ prop ];
\r
525 this.element.trigger( event, data );
\r
526 return !( $.isFunction( callback ) &&
\r
527 callback.apply( this.element[0], [ event ].concat( data ) ) === false ||
\r
528 event.isDefaultPrevented() );
\r
532 $.each( { show: "fadeIn", hide: "fadeOut" }, function( method, defaultEffect ) {
\r
533 $.Widget.prototype[ "_" + method ] = function( element, options, callback ) {
\r
534 if ( typeof options === "string" ) {
\r
535 options = { effect: options };
\r
538 effectName = !options ?
\r
540 options === true || typeof options === "number" ?
\r
542 options.effect || defaultEffect;
\r
543 options = options || {};
\r
544 if ( typeof options === "number" ) {
\r
545 options = { duration: options };
\r
547 hasOptions = !$.isEmptyObject( options );
\r
548 options.complete = callback;
\r
549 if ( options.delay ) {
\r
550 element.delay( options.delay );
\r
552 if ( hasOptions && $.effects && $.effects.effect[ effectName ] ) {
\r
553 element[ method ]( options );
\r
554 } else if ( effectName !== method && element[ effectName ] ) {
\r
555 element[ effectName ]( options.duration, options.easing, callback );
\r
557 element.queue(function( next ) {
\r
558 $( this )[ method ]();
\r
560 callback.call( element[ 0 ] );
\r
568 var widget = $.widget;
\r