1 /*! jQuery UI - v1.11.1+CommonJS - 2014-09-17
4 * Copyright 2014 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") {
14 factory(require("jquery"));
23 * jQuery UI Widget 1.11.1
26 * Copyright 2014 jQuery Foundation and other contributors
27 * Released under the MIT license.
28 * http://jquery.org/license
30 * http://api.jqueryui.com/jQuery.widget/
35 widget_slice = Array.prototype.slice;
37 $.cleanData = (function( orig ) {
38 return function( elems ) {
40 for ( i = 0; (elem = elems[i]) != null; i++ ) {
43 // Only trigger remove when necessary to save time
44 events = $._data( elem, "events" );
45 if ( events && events.remove ) {
46 $( elem ).triggerHandler( "remove" );
49 // http://bugs.jquery.com/ticket/8235
56 $.widget = function( name, base, prototype ) {
57 var fullName, existingConstructor, constructor, basePrototype,
58 // proxiedPrototype allows the provided prototype to remain unmodified
59 // so that it can be used as a mixin for multiple widgets (#8876)
60 proxiedPrototype = {},
61 namespace = name.split( "." )[ 0 ];
63 name = name.split( "." )[ 1 ];
64 fullName = namespace + "-" + name;
71 // create selector for plugin
72 $.expr[ ":" ][ fullName.toLowerCase() ] = function( elem ) {
73 return !!$.data( elem, fullName );
76 $[ namespace ] = $[ namespace ] || {};
77 existingConstructor = $[ namespace ][ name ];
78 constructor = $[ namespace ][ name ] = function( options, element ) {
79 // allow instantiation without "new" keyword
80 if ( !this._createWidget ) {
81 return new constructor( options, element );
84 // allow instantiation without initializing for simple inheritance
85 // must use "new" keyword (the code above always passes args)
86 if ( arguments.length ) {
87 this._createWidget( options, element );
90 // extend with the existing constructor to carry over any static properties
91 $.extend( constructor, existingConstructor, {
92 version: prototype.version,
93 // copy the object used to create the prototype in case we need to
94 // redefine the widget later
95 _proto: $.extend( {}, prototype ),
96 // track widgets that inherit from this widget in case this widget is
97 // redefined after a widget inherits from it
98 _childConstructors: []
101 basePrototype = new base();
102 // we need to make the options hash a property directly on the new instance
103 // otherwise we'll modify the options hash on the prototype that we're
105 basePrototype.options = $.widget.extend( {}, basePrototype.options );
106 $.each( prototype, function( prop, value ) {
107 if ( !$.isFunction( value ) ) {
108 proxiedPrototype[ prop ] = value;
111 proxiedPrototype[ prop ] = (function() {
112 var _super = function() {
113 return base.prototype[ prop ].apply( this, arguments );
115 _superApply = function( args ) {
116 return base.prototype[ prop ].apply( this, args );
119 var __super = this._super,
120 __superApply = this._superApply,
123 this._super = _super;
124 this._superApply = _superApply;
126 returnValue = value.apply( this, arguments );
128 this._super = __super;
129 this._superApply = __superApply;
135 constructor.prototype = $.widget.extend( basePrototype, {
136 // TODO: remove support for widgetEventPrefix
137 // always use the name + a colon as the prefix, e.g., draggable:start
138 // don't prefix for widgets that aren't DOM-based
139 widgetEventPrefix: existingConstructor ? (basePrototype.widgetEventPrefix || name) : name
140 }, proxiedPrototype, {
141 constructor: constructor,
142 namespace: namespace,
144 widgetFullName: fullName
147 // If this widget is being redefined then we need to find all widgets that
148 // are inheriting from it and redefine all of them so that they inherit from
149 // the new version of this widget. We're essentially trying to replace one
150 // level in the prototype chain.
151 if ( existingConstructor ) {
152 $.each( existingConstructor._childConstructors, function( i, child ) {
153 var childPrototype = child.prototype;
155 // redefine the child widget using the same prototype that was
156 // originally used, but inherit from the new version of the base
157 $.widget( childPrototype.namespace + "." + childPrototype.widgetName, constructor, child._proto );
159 // remove the list of existing child constructors from the old constructor
160 // so the old child constructors can be garbage collected
161 delete existingConstructor._childConstructors;
163 base._childConstructors.push( constructor );
166 $.widget.bridge( name, constructor );
171 $.widget.extend = function( target ) {
172 var input = widget_slice.call( arguments, 1 ),
174 inputLength = input.length,
177 for ( ; inputIndex < inputLength; inputIndex++ ) {
178 for ( key in input[ inputIndex ] ) {
179 value = input[ inputIndex ][ key ];
180 if ( input[ inputIndex ].hasOwnProperty( key ) && value !== undefined ) {
182 if ( $.isPlainObject( value ) ) {
183 target[ key ] = $.isPlainObject( target[ key ] ) ?
184 $.widget.extend( {}, target[ key ], value ) :
185 // Don't extend strings, arrays, etc. with objects
186 $.widget.extend( {}, value );
187 // Copy everything else by reference
189 target[ key ] = value;
197 $.widget.bridge = function( name, object ) {
198 var fullName = object.prototype.widgetFullName || name;
199 $.fn[ name ] = function( options ) {
200 var isMethodCall = typeof options === "string",
201 args = widget_slice.call( arguments, 1 ),
204 // allow multiple hashes to be passed on init
205 options = !isMethodCall && args.length ?
206 $.widget.extend.apply( null, [ options ].concat(args) ) :
209 if ( isMethodCall ) {
210 this.each(function() {
212 instance = $.data( this, fullName );
213 if ( options === "instance" ) {
214 returnValue = instance;
218 return $.error( "cannot call methods on " + name + " prior to initialization; " +
219 "attempted to call method '" + options + "'" );
221 if ( !$.isFunction( instance[options] ) || options.charAt( 0 ) === "_" ) {
222 return $.error( "no such method '" + options + "' for " + name + " widget instance" );
224 methodValue = instance[ options ].apply( instance, args );
225 if ( methodValue !== instance && methodValue !== undefined ) {
226 returnValue = methodValue && methodValue.jquery ?
227 returnValue.pushStack( methodValue.get() ) :
233 this.each(function() {
234 var instance = $.data( this, fullName );
236 instance.option( options || {} );
237 if ( instance._init ) {
241 $.data( this, fullName, new object( options, this ) );
250 $.Widget = function( /* options, element */ ) {};
251 $.Widget._childConstructors = [];
253 $.Widget.prototype = {
254 widgetName: "widget",
255 widgetEventPrefix: "",
256 defaultElement: "<div>",
263 _createWidget: function( options, element ) {
264 element = $( element || this.defaultElement || this )[ 0 ];
265 this.element = $( element );
266 this.uuid = widget_uuid++;
267 this.eventNamespace = "." + this.widgetName + this.uuid;
268 this.options = $.widget.extend( {},
270 this._getCreateOptions(),
274 this.hoverable = $();
275 this.focusable = $();
277 if ( element !== this ) {
278 $.data( element, this.widgetFullName, this );
279 this._on( true, this.element, {
280 remove: function( event ) {
281 if ( event.target === element ) {
286 this.document = $( element.style ?
287 // element within the document
288 element.ownerDocument :
289 // element is window or document
290 element.document || element );
291 this.window = $( this.document[0].defaultView || this.document[0].parentWindow );
295 this._trigger( "create", null, this._getCreateEventData() );
298 _getCreateOptions: $.noop,
299 _getCreateEventData: $.noop,
303 destroy: function() {
305 // we can probably remove the unbind calls in 2.0
306 // all event bindings should go through this._on()
308 .unbind( this.eventNamespace )
309 .removeData( this.widgetFullName )
310 // support: jquery <1.6.3
311 // http://bugs.jquery.com/ticket/9413
312 .removeData( $.camelCase( this.widgetFullName ) );
314 .unbind( this.eventNamespace )
315 .removeAttr( "aria-disabled" )
317 this.widgetFullName + "-disabled " +
318 "ui-state-disabled" );
320 // clean up events and states
321 this.bindings.unbind( this.eventNamespace );
322 this.hoverable.removeClass( "ui-state-hover" );
323 this.focusable.removeClass( "ui-state-focus" );
331 option: function( key, value ) {
337 if ( arguments.length === 0 ) {
338 // don't return a reference to the internal hash
339 return $.widget.extend( {}, this.options );
342 if ( typeof key === "string" ) {
343 // handle nested keys, e.g., "foo.bar" => { foo: { bar: ___ } }
345 parts = key.split( "." );
347 if ( parts.length ) {
348 curOption = options[ key ] = $.widget.extend( {}, this.options[ key ] );
349 for ( i = 0; i < parts.length - 1; i++ ) {
350 curOption[ parts[ i ] ] = curOption[ parts[ i ] ] || {};
351 curOption = curOption[ parts[ i ] ];
354 if ( arguments.length === 1 ) {
355 return curOption[ key ] === undefined ? null : curOption[ key ];
357 curOption[ key ] = value;
359 if ( arguments.length === 1 ) {
360 return this.options[ key ] === undefined ? null : this.options[ key ];
362 options[ key ] = value;
366 this._setOptions( options );
370 _setOptions: function( options ) {
373 for ( key in options ) {
374 this._setOption( key, options[ key ] );
379 _setOption: function( key, value ) {
380 this.options[ key ] = value;
382 if ( key === "disabled" ) {
384 .toggleClass( this.widgetFullName + "-disabled", !!value );
386 // If the widget is becoming disabled, then nothing is interactive
388 this.hoverable.removeClass( "ui-state-hover" );
389 this.focusable.removeClass( "ui-state-focus" );
397 return this._setOptions({ disabled: false });
399 disable: function() {
400 return this._setOptions({ disabled: true });
403 _on: function( suppressDisabledCheck, element, handlers ) {
407 // no suppressDisabledCheck flag, shuffle arguments
408 if ( typeof suppressDisabledCheck !== "boolean" ) {
410 element = suppressDisabledCheck;
411 suppressDisabledCheck = false;
414 // no element argument, shuffle and use this.element
417 element = this.element;
418 delegateElement = this.widget();
420 element = delegateElement = $( element );
421 this.bindings = this.bindings.add( element );
424 $.each( handlers, function( event, handler ) {
425 function handlerProxy() {
426 // allow widgets to customize the disabled handling
427 // - disabled as an array instead of boolean
428 // - disabled class as method for disabling individual parts
429 if ( !suppressDisabledCheck &&
430 ( instance.options.disabled === true ||
431 $( this ).hasClass( "ui-state-disabled" ) ) ) {
434 return ( typeof handler === "string" ? instance[ handler ] : handler )
435 .apply( instance, arguments );
438 // copy the guid so direct unbinding works
439 if ( typeof handler !== "string" ) {
440 handlerProxy.guid = handler.guid =
441 handler.guid || handlerProxy.guid || $.guid++;
444 var match = event.match( /^([\w:-]*)\s*(.*)$/ ),
445 eventName = match[1] + instance.eventNamespace,
448 delegateElement.delegate( selector, eventName, handlerProxy );
450 element.bind( eventName, handlerProxy );
455 _off: function( element, eventName ) {
456 eventName = (eventName || "").split( " " ).join( this.eventNamespace + " " ) + this.eventNamespace;
457 element.unbind( eventName ).undelegate( eventName );
460 _delay: function( handler, delay ) {
461 function handlerProxy() {
462 return ( typeof handler === "string" ? instance[ handler ] : handler )
463 .apply( instance, arguments );
466 return setTimeout( handlerProxy, delay || 0 );
469 _hoverable: function( element ) {
470 this.hoverable = this.hoverable.add( element );
472 mouseenter: function( event ) {
473 $( event.currentTarget ).addClass( "ui-state-hover" );
475 mouseleave: function( event ) {
476 $( event.currentTarget ).removeClass( "ui-state-hover" );
481 _focusable: function( element ) {
482 this.focusable = this.focusable.add( element );
484 focusin: function( event ) {
485 $( event.currentTarget ).addClass( "ui-state-focus" );
487 focusout: function( event ) {
488 $( event.currentTarget ).removeClass( "ui-state-focus" );
493 _trigger: function( type, event, data ) {
495 callback = this.options[ type ];
498 event = $.Event( event );
499 event.type = ( type === this.widgetEventPrefix ?
501 this.widgetEventPrefix + type ).toLowerCase();
502 // the original event may come from any element
503 // so we need to reset the target on the new event
504 event.target = this.element[ 0 ];
506 // copy original event properties over to the new event
507 orig = event.originalEvent;
509 for ( prop in orig ) {
510 if ( !( prop in event ) ) {
511 event[ prop ] = orig[ prop ];
516 this.element.trigger( event, data );
517 return !( $.isFunction( callback ) &&
518 callback.apply( this.element[0], [ event ].concat( data ) ) === false ||
519 event.isDefaultPrevented() );
523 $.each( { show: "fadeIn", hide: "fadeOut" }, function( method, defaultEffect ) {
524 $.Widget.prototype[ "_" + method ] = function( element, options, callback ) {
525 if ( typeof options === "string" ) {
526 options = { effect: options };
529 effectName = !options ?
531 options === true || typeof options === "number" ?
533 options.effect || defaultEffect;
534 options = options || {};
535 if ( typeof options === "number" ) {
536 options = { duration: options };
538 hasOptions = !$.isEmptyObject( options );
539 options.complete = callback;
540 if ( options.delay ) {
541 element.delay( options.delay );
543 if ( hasOptions && $.effects && $.effects.effect[ effectName ] ) {
544 element[ method ]( options );
545 } else if ( effectName !== method && element[ effectName ] ) {
546 element[ effectName ]( options.duration, options.easing, callback );
548 element.queue(function( next ) {
549 $( this )[ method ]();
551 callback.call( element[ 0 ] );
559 var widget = $.widget;