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