2009-12-16 22:20:18 +00:00
|
|
|
/*!
|
2009-12-22 19:51:24 +00:00
|
|
|
* jQuery UI Widget @VERSION
|
2012-07-04 13:08:08 +00:00
|
|
|
* http://jqueryui.com
|
2009-12-16 22:20:18 +00:00
|
|
|
*
|
2014-12-21 18:27:43 +00:00
|
|
|
* Copyright jQuery Foundation and other contributors
|
2012-08-09 14:13:24 +00:00
|
|
|
* Released under the MIT license.
|
2010-07-09 13:01:04 +00:00
|
|
|
* http://jquery.org/license
|
2009-12-16 22:20:18 +00:00
|
|
|
*/
|
2014-10-30 19:55:08 +00:00
|
|
|
|
|
|
|
//>>label: Widget
|
|
|
|
//>>group: UI Core
|
|
|
|
//>>description: Provides a factory for creating stateful widgets with a common API.
|
|
|
|
//>>docs: http://api.jqueryui.com/jQuery.widget/
|
|
|
|
//>>demos: http://jqueryui.com/widget/
|
|
|
|
|
2015-03-14 11:37:03 +00:00
|
|
|
( function( factory ) {
|
2013-07-12 16:40:48 +00:00
|
|
|
if ( typeof define === "function" && define.amd ) {
|
|
|
|
|
|
|
|
// AMD. Register as an anonymous module.
|
2015-07-15 22:26:12 +00:00
|
|
|
define( [ "jquery", "./version" ], factory );
|
2013-07-12 16:40:48 +00:00
|
|
|
} else {
|
|
|
|
|
|
|
|
// Browser globals
|
|
|
|
factory( jQuery );
|
|
|
|
}
|
2015-03-14 11:37:03 +00:00
|
|
|
}( function( $ ) {
|
2009-12-22 19:51:24 +00:00
|
|
|
|
2013-10-23 12:14:49 +00:00
|
|
|
var widget_uuid = 0,
|
|
|
|
widget_slice = Array.prototype.slice;
|
|
|
|
|
2015-03-14 11:37:03 +00:00
|
|
|
$.cleanData = ( function( orig ) {
|
2013-10-23 12:14:49 +00:00
|
|
|
return function( elems ) {
|
2014-07-24 13:04:06 +00:00
|
|
|
var events, elem, i;
|
2015-03-14 11:37:03 +00:00
|
|
|
for ( i = 0; ( elem = elems[ i ] ) != null; i++ ) {
|
2013-10-23 12:14:49 +00:00
|
|
|
try {
|
2014-07-24 13:04:06 +00:00
|
|
|
|
|
|
|
// Only trigger remove when necessary to save time
|
|
|
|
events = $._data( elem, "events" );
|
|
|
|
if ( events && events.remove ) {
|
|
|
|
$( elem ).triggerHandler( "remove" );
|
|
|
|
}
|
|
|
|
|
2015-08-21 04:13:00 +00:00
|
|
|
// Http://bugs.jquery.com/ticket/8235
|
2014-08-13 16:29:28 +00:00
|
|
|
} catch ( e ) {}
|
2013-10-23 12:14:49 +00:00
|
|
|
}
|
|
|
|
orig( elems );
|
|
|
|
};
|
2015-03-14 11:37:03 +00:00
|
|
|
} )( $.cleanData );
|
2009-12-22 19:51:24 +00:00
|
|
|
|
2010-01-15 20:47:41 +00:00
|
|
|
$.widget = function( name, base, prototype ) {
|
2012-02-01 21:59:26 +00:00
|
|
|
var fullName, existingConstructor, constructor, basePrototype,
|
2015-08-21 04:13:00 +00:00
|
|
|
|
|
|
|
// ProxiedPrototype allows the provided prototype to remain unmodified
|
2012-12-03 19:18:24 +00:00
|
|
|
// so that it can be used as a mixin for multiple widgets (#8876)
|
|
|
|
proxiedPrototype = {},
|
2012-02-01 21:59:26 +00:00
|
|
|
namespace = name.split( "." )[ 0 ];
|
|
|
|
|
2010-01-15 20:47:41 +00:00
|
|
|
name = name.split( "." )[ 1 ];
|
|
|
|
fullName = namespace + "-" + name;
|
2009-12-16 22:20:18 +00:00
|
|
|
|
2010-01-15 20:47:41 +00:00
|
|
|
if ( !prototype ) {
|
2010-01-07 03:19:50 +00:00
|
|
|
prototype = base;
|
|
|
|
base = $.Widget;
|
|
|
|
}
|
|
|
|
|
2015-05-13 18:59:02 +00:00
|
|
|
if ( $.isArray( prototype ) ) {
|
|
|
|
prototype = $.extend.apply( null, [ {} ].concat( prototype ) );
|
|
|
|
}
|
|
|
|
|
2015-08-21 04:13:00 +00:00
|
|
|
// Create selector for plugin
|
2012-07-09 20:02:43 +00:00
|
|
|
$.expr[ ":" ][ fullName.toLowerCase() ] = function( elem ) {
|
2012-03-01 13:30:02 +00:00
|
|
|
return !!$.data( elem, fullName );
|
2009-12-16 22:20:18 +00:00
|
|
|
};
|
2010-01-07 03:19:50 +00:00
|
|
|
|
2010-01-15 20:47:41 +00:00
|
|
|
$[ namespace ] = $[ namespace ] || {};
|
2012-02-01 21:59:26 +00:00
|
|
|
existingConstructor = $[ namespace ][ name ];
|
|
|
|
constructor = $[ namespace ][ name ] = function( options, element ) {
|
2015-08-21 04:13:00 +00:00
|
|
|
|
|
|
|
// Allow instantiation without "new" keyword
|
2011-01-23 01:39:37 +00:00
|
|
|
if ( !this._createWidget ) {
|
2012-02-01 21:59:26 +00:00
|
|
|
return new constructor( options, element );
|
2011-01-23 01:39:37 +00:00
|
|
|
}
|
|
|
|
|
2015-08-21 04:13:00 +00:00
|
|
|
// Allow instantiation without initializing for simple inheritance
|
2011-01-23 01:39:37 +00:00
|
|
|
// must use "new" keyword (the code above always passes args)
|
2010-01-15 20:47:41 +00:00
|
|
|
if ( arguments.length ) {
|
|
|
|
this._createWidget( options, element );
|
|
|
|
}
|
2012-02-01 21:59:26 +00:00
|
|
|
};
|
2015-08-21 04:13:00 +00:00
|
|
|
|
|
|
|
// Extend with the existing constructor to carry over any static properties
|
2012-02-01 21:59:26 +00:00
|
|
|
$.extend( constructor, existingConstructor, {
|
|
|
|
version: prototype.version,
|
2015-08-21 04:13:00 +00:00
|
|
|
|
|
|
|
// Copy the object used to create the prototype in case we need to
|
2012-02-01 21:59:26 +00:00
|
|
|
// redefine the widget later
|
|
|
|
_proto: $.extend( {}, prototype ),
|
2015-08-21 04:13:00 +00:00
|
|
|
|
|
|
|
// Track widgets that inherit from this widget in case this widget is
|
2012-02-01 21:59:26 +00:00
|
|
|
// redefined after a widget inherits from it
|
|
|
|
_childConstructors: []
|
2015-03-14 11:37:03 +00:00
|
|
|
} );
|
2010-01-07 03:19:50 +00:00
|
|
|
|
2012-02-01 21:59:26 +00:00
|
|
|
basePrototype = new base();
|
2015-08-21 04:13:00 +00:00
|
|
|
|
|
|
|
// We need to make the options hash a property directly on the new instance
|
2010-01-07 03:19:50 +00:00
|
|
|
// otherwise we'll modify the options hash on the prototype that we're
|
|
|
|
// inheriting from
|
2011-05-11 17:37:40 +00:00
|
|
|
basePrototype.options = $.widget.extend( {}, basePrototype.options );
|
2011-02-11 02:25:50 +00:00
|
|
|
$.each( prototype, function( prop, value ) {
|
2012-12-03 19:18:24 +00:00
|
|
|
if ( !$.isFunction( value ) ) {
|
|
|
|
proxiedPrototype[ prop ] = value;
|
|
|
|
return;
|
|
|
|
}
|
2015-03-14 11:37:03 +00:00
|
|
|
proxiedPrototype[ prop ] = ( function() {
|
2012-12-03 19:18:24 +00:00
|
|
|
var _super = function() {
|
|
|
|
return base.prototype[ prop ].apply( this, arguments );
|
|
|
|
},
|
|
|
|
_superApply = function( args ) {
|
|
|
|
return base.prototype[ prop ].apply( this, args );
|
|
|
|
};
|
|
|
|
return function() {
|
|
|
|
var __super = this._super,
|
|
|
|
__superApply = this._superApply,
|
|
|
|
returnValue;
|
2011-02-11 13:53:43 +00:00
|
|
|
|
2012-12-03 19:18:24 +00:00
|
|
|
this._super = _super;
|
|
|
|
this._superApply = _superApply;
|
2011-02-11 13:53:43 +00:00
|
|
|
|
2012-12-03 19:18:24 +00:00
|
|
|
returnValue = value.apply( this, arguments );
|
2011-02-11 13:53:43 +00:00
|
|
|
|
2012-12-03 19:18:24 +00:00
|
|
|
this._super = __super;
|
|
|
|
this._superApply = __superApply;
|
2011-02-11 13:53:43 +00:00
|
|
|
|
2012-12-03 19:18:24 +00:00
|
|
|
return returnValue;
|
|
|
|
};
|
2015-03-14 11:37:03 +00:00
|
|
|
} )();
|
|
|
|
} );
|
2012-02-01 21:59:26 +00:00
|
|
|
constructor.prototype = $.widget.extend( basePrototype, {
|
2015-08-21 04:13:00 +00:00
|
|
|
|
2012-02-01 21:59:26 +00:00
|
|
|
// TODO: remove support for widgetEventPrefix
|
|
|
|
// always use the name + a colon as the prefix, e.g., draggable:start
|
|
|
|
// don't prefix for widgets that aren't DOM-based
|
2015-03-14 11:37:03 +00:00
|
|
|
widgetEventPrefix: existingConstructor ? ( basePrototype.widgetEventPrefix || name ) : name
|
2012-12-03 19:18:24 +00:00
|
|
|
}, proxiedPrototype, {
|
2012-02-01 21:59:26 +00:00
|
|
|
constructor: constructor,
|
2010-01-07 03:19:50 +00:00
|
|
|
namespace: namespace,
|
|
|
|
widgetName: name,
|
2012-03-01 13:36:17 +00:00
|
|
|
widgetFullName: fullName
|
2015-03-14 11:37:03 +00:00
|
|
|
} );
|
2012-02-01 21:59:26 +00:00
|
|
|
|
|
|
|
// If this widget is being redefined then we need to find all widgets that
|
|
|
|
// are inheriting from it and redefine all of them so that they inherit from
|
|
|
|
// the new version of this widget. We're essentially trying to replace one
|
|
|
|
// level in the prototype chain.
|
|
|
|
if ( existingConstructor ) {
|
|
|
|
$.each( existingConstructor._childConstructors, function( i, child ) {
|
|
|
|
var childPrototype = child.prototype;
|
|
|
|
|
2015-08-21 04:13:00 +00:00
|
|
|
// Redefine the child widget using the same prototype that was
|
2012-02-01 21:59:26 +00:00
|
|
|
// originally used, but inherit from the new version of the base
|
|
|
|
$.widget( childPrototype.namespace + "." + childPrototype.widgetName, constructor, child._proto );
|
2015-03-14 11:37:03 +00:00
|
|
|
} );
|
2015-08-21 04:13:00 +00:00
|
|
|
|
|
|
|
// Remove the list of existing child constructors from the old constructor
|
2012-02-01 21:59:26 +00:00
|
|
|
// so the old child constructors can be garbage collected
|
|
|
|
delete existingConstructor._childConstructors;
|
|
|
|
} else {
|
|
|
|
base._childConstructors.push( constructor );
|
|
|
|
}
|
2010-01-07 03:19:50 +00:00
|
|
|
|
2012-02-01 21:59:26 +00:00
|
|
|
$.widget.bridge( name, constructor );
|
2013-07-31 19:56:04 +00:00
|
|
|
|
|
|
|
return constructor;
|
2010-01-07 03:19:50 +00:00
|
|
|
};
|
|
|
|
|
2011-05-11 17:37:40 +00:00
|
|
|
$.widget.extend = function( target ) {
|
2013-10-23 12:14:49 +00:00
|
|
|
var input = widget_slice.call( arguments, 1 ),
|
2011-05-11 17:37:40 +00:00
|
|
|
inputIndex = 0,
|
|
|
|
inputLength = input.length,
|
|
|
|
key,
|
|
|
|
value;
|
|
|
|
for ( ; inputIndex < inputLength; inputIndex++ ) {
|
|
|
|
for ( key in input[ inputIndex ] ) {
|
|
|
|
value = input[ inputIndex ][ key ];
|
2012-10-23 15:45:16 +00:00
|
|
|
if ( input[ inputIndex ].hasOwnProperty( key ) && value !== undefined ) {
|
2015-08-21 04:13:00 +00:00
|
|
|
|
2012-10-23 15:45:16 +00:00
|
|
|
// Clone objects
|
|
|
|
if ( $.isPlainObject( value ) ) {
|
|
|
|
target[ key ] = $.isPlainObject( target[ key ] ) ?
|
|
|
|
$.widget.extend( {}, target[ key ], value ) :
|
2015-08-21 04:13:00 +00:00
|
|
|
|
2012-10-23 15:45:16 +00:00
|
|
|
// Don't extend strings, arrays, etc. with objects
|
|
|
|
$.widget.extend( {}, value );
|
2015-08-21 04:13:00 +00:00
|
|
|
|
2012-10-23 15:45:16 +00:00
|
|
|
// Copy everything else by reference
|
2012-10-22 19:33:57 +00:00
|
|
|
} else {
|
|
|
|
target[ key ] = value;
|
|
|
|
}
|
2011-05-11 17:37:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return target;
|
|
|
|
};
|
|
|
|
|
2010-01-15 20:47:41 +00:00
|
|
|
$.widget.bridge = function( name, object ) {
|
2012-11-07 15:05:00 +00:00
|
|
|
var fullName = object.prototype.widgetFullName || name;
|
2010-01-15 22:15:18 +00:00
|
|
|
$.fn[ name ] = function( options ) {
|
2010-01-15 20:47:41 +00:00
|
|
|
var isMethodCall = typeof options === "string",
|
2013-10-23 12:14:49 +00:00
|
|
|
args = widget_slice.call( arguments, 1 ),
|
2009-12-16 22:20:18 +00:00
|
|
|
returnValue = this;
|
2010-01-15 20:47:41 +00:00
|
|
|
|
|
|
|
if ( isMethodCall ) {
|
2015-03-14 11:37:03 +00:00
|
|
|
this.each( function() {
|
2012-04-02 23:12:21 +00:00
|
|
|
var methodValue,
|
|
|
|
instance = $.data( this, fullName );
|
2013-01-30 14:11:22 +00:00
|
|
|
if ( options === "instance" ) {
|
|
|
|
returnValue = instance;
|
|
|
|
return false;
|
|
|
|
}
|
2013-01-30 14:32:48 +00:00
|
|
|
if ( !instance ) {
|
|
|
|
return $.error( "cannot call methods on " + name + " prior to initialization; " +
|
|
|
|
"attempted to call method '" + options + "'" );
|
|
|
|
}
|
2015-03-14 11:37:03 +00:00
|
|
|
if ( !$.isFunction( instance[ options ] ) || options.charAt( 0 ) === "_" ) {
|
2010-12-10 19:11:20 +00:00
|
|
|
return $.error( "no such method '" + options + "' for " + name + " widget instance" );
|
|
|
|
}
|
2012-04-02 23:12:21 +00:00
|
|
|
methodValue = instance[ options ].apply( instance, args );
|
2010-01-15 20:47:41 +00:00
|
|
|
if ( methodValue !== instance && methodValue !== undefined ) {
|
2011-06-09 13:47:18 +00:00
|
|
|
returnValue = methodValue && methodValue.jquery ?
|
2011-03-22 18:35:18 +00:00
|
|
|
returnValue.pushStack( methodValue.get() ) :
|
|
|
|
methodValue;
|
2009-12-16 22:20:18 +00:00
|
|
|
return false;
|
|
|
|
}
|
2015-03-14 11:37:03 +00:00
|
|
|
} );
|
2010-01-15 20:47:41 +00:00
|
|
|
} else {
|
2014-12-21 23:35:24 +00:00
|
|
|
|
|
|
|
// Allow multiple hashes to be passed on init
|
|
|
|
if ( args.length ) {
|
2015-03-14 11:37:03 +00:00
|
|
|
options = $.widget.extend.apply( null, [ options ].concat( args ) );
|
2014-12-21 23:35:24 +00:00
|
|
|
}
|
|
|
|
|
2015-03-14 11:37:03 +00:00
|
|
|
this.each( function() {
|
2012-03-01 14:03:30 +00:00
|
|
|
var instance = $.data( this, fullName );
|
2010-01-15 21:09:32 +00:00
|
|
|
if ( instance ) {
|
2013-09-11 20:11:58 +00:00
|
|
|
instance.option( options || {} );
|
|
|
|
if ( instance._init ) {
|
|
|
|
instance._init();
|
|
|
|
}
|
2010-01-15 21:09:32 +00:00
|
|
|
} else {
|
2012-11-07 15:05:00 +00:00
|
|
|
$.data( this, fullName, new object( options, this ) );
|
2010-01-15 20:47:41 +00:00
|
|
|
}
|
2015-03-14 11:37:03 +00:00
|
|
|
} );
|
2010-01-15 20:47:41 +00:00
|
|
|
}
|
2009-12-16 22:20:18 +00:00
|
|
|
|
|
|
|
return returnValue;
|
|
|
|
};
|
2010-01-07 03:19:50 +00:00
|
|
|
};
|
2009-12-16 22:20:18 +00:00
|
|
|
|
2012-10-23 14:36:42 +00:00
|
|
|
$.Widget = function( /* options, element */ ) {};
|
2012-02-01 21:59:26 +00:00
|
|
|
$.Widget._childConstructors = [];
|
2009-12-16 22:20:18 +00:00
|
|
|
|
2010-01-07 03:19:50 +00:00
|
|
|
$.Widget.prototype = {
|
2010-01-15 20:47:41 +00:00
|
|
|
widgetName: "widget",
|
|
|
|
widgetEventPrefix: "",
|
2011-01-23 01:30:40 +00:00
|
|
|
defaultElement: "<div>",
|
2010-01-07 03:19:50 +00:00
|
|
|
options: {
|
2014-12-03 16:20:20 +00:00
|
|
|
classes: {},
|
2011-04-25 18:04:30 +00:00
|
|
|
disabled: false,
|
|
|
|
|
2015-08-21 04:13:00 +00:00
|
|
|
// Callbacks
|
2011-04-25 18:04:30 +00:00
|
|
|
create: null
|
2010-01-07 03:19:50 +00:00
|
|
|
},
|
2010-01-15 20:47:41 +00:00
|
|
|
_createWidget: function( options, element ) {
|
2011-01-24 18:33:24 +00:00
|
|
|
element = $( element || this.defaultElement || this )[ 0 ];
|
2010-07-30 12:04:11 +00:00
|
|
|
this.element = $( element );
|
2013-10-23 12:14:49 +00:00
|
|
|
this.uuid = widget_uuid++;
|
2012-06-14 14:51:29 +00:00
|
|
|
this.eventNamespace = "." + this.widgetName + this.uuid;
|
2009-12-16 22:20:18 +00:00
|
|
|
|
2011-01-18 06:46:26 +00:00
|
|
|
this.bindings = $();
|
2011-01-21 20:37:18 +00:00
|
|
|
this.hoverable = $();
|
|
|
|
this.focusable = $();
|
2014-12-03 16:20:20 +00:00
|
|
|
this.classesElementLookup = {};
|
2011-02-01 03:04:09 +00:00
|
|
|
|
|
|
|
if ( element !== this ) {
|
2012-03-01 13:36:17 +00:00
|
|
|
$.data( element, this.widgetFullName, this );
|
2012-11-09 17:54:33 +00:00
|
|
|
this._on( true, this.element, {
|
2012-10-07 06:35:01 +00:00
|
|
|
remove: function( event ) {
|
|
|
|
if ( event.target === element ) {
|
|
|
|
this.destroy();
|
|
|
|
}
|
|
|
|
}
|
2015-03-14 11:37:03 +00:00
|
|
|
} );
|
2011-11-07 13:39:22 +00:00
|
|
|
this.document = $( element.style ?
|
2015-08-21 04:13:00 +00:00
|
|
|
|
|
|
|
// Element within the document
|
2011-11-07 13:39:22 +00:00
|
|
|
element.ownerDocument :
|
2015-08-21 04:13:00 +00:00
|
|
|
|
|
|
|
// Element is window or document
|
2011-11-07 13:39:22 +00:00
|
|
|
element.document || element );
|
2015-03-14 11:37:03 +00:00
|
|
|
this.window = $( this.document[ 0 ].defaultView || this.document[ 0 ].parentWindow );
|
2011-01-31 15:33:45 +00:00
|
|
|
}
|
2009-12-16 22:20:18 +00:00
|
|
|
|
2014-08-21 13:02:45 +00:00
|
|
|
this.options = $.widget.extend( {},
|
|
|
|
this.options,
|
|
|
|
this._getCreateOptions(),
|
|
|
|
options );
|
|
|
|
|
2010-01-17 17:36:56 +00:00
|
|
|
this._create();
|
2012-01-21 13:45:41 +00:00
|
|
|
this._trigger( "create", null, this._getCreateEventData() );
|
2010-01-15 21:09:32 +00:00
|
|
|
this._init();
|
2010-01-07 03:19:50 +00:00
|
|
|
},
|
2011-03-23 13:16:19 +00:00
|
|
|
_getCreateOptions: $.noop,
|
2012-01-21 13:45:41 +00:00
|
|
|
_getCreateEventData: $.noop,
|
2011-01-14 21:55:13 +00:00
|
|
|
_create: $.noop,
|
|
|
|
_init: $.noop,
|
2009-12-16 22:20:18 +00:00
|
|
|
|
|
|
|
destroy: function() {
|
2014-12-03 16:20:20 +00:00
|
|
|
var that = this;
|
|
|
|
|
2011-01-14 21:55:13 +00:00
|
|
|
this._destroy();
|
2014-12-03 16:20:20 +00:00
|
|
|
$.each( this.classesElementLookup, function( key, value ) {
|
|
|
|
that._removeClass( value, key );
|
2015-03-14 11:37:03 +00:00
|
|
|
} );
|
2014-12-03 16:20:20 +00:00
|
|
|
|
2015-08-21 04:13:00 +00:00
|
|
|
// We can probably remove the unbind calls in 2.0
|
2012-06-13 12:00:45 +00:00
|
|
|
// all event bindings should go through this._on()
|
2010-01-07 03:19:50 +00:00
|
|
|
this.element
|
2015-05-14 02:02:32 +00:00
|
|
|
.off( this.eventNamespace )
|
2015-01-12 16:19:46 +00:00
|
|
|
.removeData( this.widgetFullName );
|
2010-01-07 03:19:50 +00:00
|
|
|
this.widget()
|
2015-05-14 02:02:32 +00:00
|
|
|
.off( this.eventNamespace )
|
2014-12-03 16:20:20 +00:00
|
|
|
.removeAttr( "aria-disabled" );
|
2011-01-21 20:37:18 +00:00
|
|
|
|
2015-08-21 04:13:00 +00:00
|
|
|
// Clean up events and states
|
2015-05-14 02:02:32 +00:00
|
|
|
this.bindings.off( this.eventNamespace );
|
2010-01-07 03:19:50 +00:00
|
|
|
},
|
2011-01-14 21:55:13 +00:00
|
|
|
_destroy: $.noop,
|
2009-12-16 22:20:18 +00:00
|
|
|
|
2010-01-07 03:19:50 +00:00
|
|
|
widget: function() {
|
2010-07-30 16:38:18 +00:00
|
|
|
return this.element;
|
2009-12-16 22:20:18 +00:00
|
|
|
},
|
|
|
|
|
2010-01-15 20:47:41 +00:00
|
|
|
option: function( key, value ) {
|
2011-03-24 13:21:53 +00:00
|
|
|
var options = key,
|
|
|
|
parts,
|
|
|
|
curOption,
|
|
|
|
i;
|
2009-12-16 22:20:18 +00:00
|
|
|
|
2010-01-15 20:47:41 +00:00
|
|
|
if ( arguments.length === 0 ) {
|
2015-08-21 04:13:00 +00:00
|
|
|
|
|
|
|
// Don't return a reference to the internal hash
|
2011-05-11 17:37:40 +00:00
|
|
|
return $.widget.extend( {}, this.options );
|
2010-01-07 03:19:50 +00:00
|
|
|
}
|
|
|
|
|
2011-03-24 13:21:53 +00:00
|
|
|
if ( typeof key === "string" ) {
|
2015-08-21 04:13:00 +00:00
|
|
|
|
|
|
|
// Handle nested keys, e.g., "foo.bar" => { foo: { bar: ___ } }
|
2009-12-16 22:20:18 +00:00
|
|
|
options = {};
|
2011-03-24 13:21:53 +00:00
|
|
|
parts = key.split( "." );
|
|
|
|
key = parts.shift();
|
|
|
|
if ( parts.length ) {
|
2011-05-11 17:37:40 +00:00
|
|
|
curOption = options[ key ] = $.widget.extend( {}, this.options[ key ] );
|
2011-03-24 13:21:53 +00:00
|
|
|
for ( i = 0; i < parts.length - 1; i++ ) {
|
|
|
|
curOption[ parts[ i ] ] = curOption[ parts[ i ] ] || {};
|
|
|
|
curOption = curOption[ parts[ i ] ];
|
|
|
|
}
|
2011-06-09 13:47:18 +00:00
|
|
|
key = parts.pop();
|
2013-10-15 03:43:06 +00:00
|
|
|
if ( arguments.length === 1 ) {
|
2011-06-09 13:47:18 +00:00
|
|
|
return curOption[ key ] === undefined ? null : curOption[ key ];
|
|
|
|
}
|
|
|
|
curOption[ key ] = value;
|
2011-03-24 13:21:53 +00:00
|
|
|
} else {
|
2013-10-15 03:43:06 +00:00
|
|
|
if ( arguments.length === 1 ) {
|
2011-06-09 13:47:18 +00:00
|
|
|
return this.options[ key ] === undefined ? null : this.options[ key ];
|
|
|
|
}
|
2011-03-24 13:21:53 +00:00
|
|
|
options[ key ] = value;
|
|
|
|
}
|
2009-12-16 22:20:18 +00:00
|
|
|
}
|
|
|
|
|
2010-09-27 15:21:09 +00:00
|
|
|
this._setOptions( options );
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
_setOptions: function( options ) {
|
2011-10-19 17:54:08 +00:00
|
|
|
var key;
|
|
|
|
|
|
|
|
for ( key in options ) {
|
|
|
|
this._setOption( key, options[ key ] );
|
|
|
|
}
|
2009-12-16 22:20:18 +00:00
|
|
|
|
2010-09-27 15:21:09 +00:00
|
|
|
return this;
|
2009-12-16 22:20:18 +00:00
|
|
|
},
|
2010-01-15 20:47:41 +00:00
|
|
|
_setOption: function( key, value ) {
|
2014-12-03 16:20:20 +00:00
|
|
|
if ( key === "classes" ) {
|
|
|
|
this._setOptionClasses( value );
|
|
|
|
}
|
|
|
|
|
2010-01-15 20:47:41 +00:00
|
|
|
this.options[ key ] = value;
|
2009-12-16 22:20:18 +00:00
|
|
|
|
2010-01-15 20:47:41 +00:00
|
|
|
if ( key === "disabled" ) {
|
2014-12-03 16:20:20 +00:00
|
|
|
this._toggleClass( this.widget(), this.widgetFullName + "-disabled", null, !!value );
|
2013-09-16 15:57:35 +00:00
|
|
|
|
|
|
|
// If the widget is becoming disabled, then nothing is interactive
|
|
|
|
if ( value ) {
|
2014-12-03 16:20:20 +00:00
|
|
|
this._removeClass( this.hoverable, null, "ui-state-hover" );
|
|
|
|
this._removeClass( this.focusable, null, "ui-state-focus" );
|
2013-09-16 15:57:35 +00:00
|
|
|
}
|
2009-12-16 22:20:18 +00:00
|
|
|
}
|
2010-01-07 03:19:50 +00:00
|
|
|
|
|
|
|
return this;
|
2009-12-16 22:20:18 +00:00
|
|
|
},
|
2014-12-03 16:20:20 +00:00
|
|
|
_setOptionClasses: function( value ) {
|
|
|
|
var classKey, elements, currentElements;
|
|
|
|
|
|
|
|
for ( classKey in value ) {
|
|
|
|
currentElements = this.classesElementLookup[ classKey ];
|
|
|
|
if ( value[ classKey ] === this.options.classes[ classKey ] ||
|
|
|
|
!currentElements ||
|
|
|
|
!currentElements.length ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We are doing this to create a new jQuery object because the _removeClass() call
|
|
|
|
// on the next line is going to destroy the reference to the current elements being
|
|
|
|
// tracked. We need to save a copy of this collection so that we can add the new classes
|
|
|
|
// below.
|
|
|
|
elements = $( currentElements.get() );
|
|
|
|
this._removeClass( currentElements, classKey );
|
|
|
|
|
|
|
|
// We don't use _addClass() here, because that uses this.options.classes
|
|
|
|
// for generating the string of classes. We want to use the value passed in from
|
|
|
|
// _setOption(), this is the new value of the classes option which was passed to
|
|
|
|
// _setOption(). We pass this value directly to _classes().
|
2015-03-14 11:37:03 +00:00
|
|
|
elements.addClass( this._classes( {
|
2014-12-03 16:20:20 +00:00
|
|
|
element: elements,
|
|
|
|
keys: classKey,
|
|
|
|
classes: value,
|
|
|
|
add: true
|
2015-03-14 11:37:03 +00:00
|
|
|
} ) );
|
2014-12-03 16:20:20 +00:00
|
|
|
}
|
|
|
|
},
|
2009-12-16 22:20:18 +00:00
|
|
|
|
|
|
|
enable: function() {
|
2015-03-14 11:37:03 +00:00
|
|
|
return this._setOptions( { disabled: false } );
|
2009-12-16 22:20:18 +00:00
|
|
|
},
|
|
|
|
disable: function() {
|
2015-03-14 11:37:03 +00:00
|
|
|
return this._setOptions( { disabled: true } );
|
2009-12-16 22:20:18 +00:00
|
|
|
},
|
|
|
|
|
2014-12-03 16:20:20 +00:00
|
|
|
_classes: function( options ) {
|
|
|
|
var full = [],
|
|
|
|
that = this;
|
|
|
|
|
2015-03-14 11:37:03 +00:00
|
|
|
options = $.extend( {
|
2014-12-03 16:20:20 +00:00
|
|
|
element: this.element,
|
|
|
|
classes: this.options.classes || {}
|
|
|
|
}, options );
|
|
|
|
|
|
|
|
function processClassString( classes, checkOption ) {
|
|
|
|
var current, i;
|
|
|
|
for ( i = 0; i < classes.length; i++ ) {
|
|
|
|
current = that.classesElementLookup[ classes[ i ] ] || $();
|
|
|
|
if ( options.add ) {
|
|
|
|
current = $( $.unique( current.get().concat( options.element.get() ) ) );
|
|
|
|
} else {
|
|
|
|
current = $( current.not( options.element ).get() );
|
|
|
|
}
|
|
|
|
that.classesElementLookup[ classes[ i ] ] = current;
|
|
|
|
full.push( classes[ i ] );
|
|
|
|
if ( checkOption && options.classes[ classes[ i ] ] ) {
|
|
|
|
full.push( options.classes[ classes[ i ] ] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( options.keys ) {
|
|
|
|
processClassString( options.keys.match( /\S+/g ) || [], true );
|
|
|
|
}
|
|
|
|
if ( options.extra ) {
|
|
|
|
processClassString( options.extra.match( /\S+/g ) || [] );
|
|
|
|
}
|
|
|
|
|
|
|
|
return full.join( " " );
|
|
|
|
},
|
|
|
|
|
|
|
|
_removeClass: function( element, keys, extra ) {
|
|
|
|
return this._toggleClass( element, keys, extra, false );
|
|
|
|
},
|
|
|
|
|
|
|
|
_addClass: function( element, keys, extra ) {
|
|
|
|
return this._toggleClass( element, keys, extra, true );
|
|
|
|
},
|
|
|
|
|
|
|
|
_toggleClass: function( element, keys, extra, add ) {
|
|
|
|
add = ( typeof add === "boolean" ) ? add : extra;
|
|
|
|
var shift = ( typeof element === "string" || element === null ),
|
|
|
|
options = {
|
|
|
|
extra: shift ? keys : extra,
|
|
|
|
keys: shift ? element : keys,
|
|
|
|
element: shift ? this.element : element,
|
|
|
|
add: add
|
|
|
|
};
|
|
|
|
options.element.toggleClass( this._classes( options ), add );
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2012-11-09 17:39:41 +00:00
|
|
|
_on: function( suppressDisabledCheck, element, handlers ) {
|
2012-10-24 14:41:48 +00:00
|
|
|
var delegateElement,
|
|
|
|
instance = this;
|
2012-11-09 17:39:41 +00:00
|
|
|
|
2015-08-21 04:13:00 +00:00
|
|
|
// No suppressDisabledCheck flag, shuffle arguments
|
2012-11-09 17:39:41 +00:00
|
|
|
if ( typeof suppressDisabledCheck !== "boolean" ) {
|
|
|
|
handlers = element;
|
|
|
|
element = suppressDisabledCheck;
|
|
|
|
suppressDisabledCheck = false;
|
|
|
|
}
|
|
|
|
|
2015-08-21 04:13:00 +00:00
|
|
|
// No element argument, shuffle and use this.element
|
2011-01-18 06:46:26 +00:00
|
|
|
if ( !handlers ) {
|
|
|
|
handlers = element;
|
|
|
|
element = this.element;
|
2012-10-24 14:41:48 +00:00
|
|
|
delegateElement = this.widget();
|
2011-01-18 06:46:26 +00:00
|
|
|
} else {
|
2012-10-24 14:41:48 +00:00
|
|
|
element = delegateElement = $( element );
|
2011-01-18 06:46:26 +00:00
|
|
|
this.bindings = this.bindings.add( element );
|
|
|
|
}
|
2011-06-08 20:14:37 +00:00
|
|
|
|
2011-01-18 06:46:26 +00:00
|
|
|
$.each( handlers, function( event, handler ) {
|
2011-06-08 20:14:37 +00:00
|
|
|
function handlerProxy() {
|
2015-08-21 04:13:00 +00:00
|
|
|
|
|
|
|
// Allow widgets to customize the disabled handling
|
2011-02-01 02:55:22 +00:00
|
|
|
// - disabled as an array instead of boolean
|
|
|
|
// - disabled class as method for disabling individual parts
|
2012-11-09 17:39:41 +00:00
|
|
|
if ( !suppressDisabledCheck &&
|
|
|
|
( instance.options.disabled === true ||
|
2015-03-14 11:37:03 +00:00
|
|
|
$( this ).hasClass( "ui-state-disabled" ) ) ) {
|
2011-01-18 06:46:26 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-01-18 06:53:20 +00:00
|
|
|
return ( typeof handler === "string" ? instance[ handler ] : handler )
|
|
|
|
.apply( instance, arguments );
|
2011-06-08 20:14:37 +00:00
|
|
|
}
|
2012-01-08 01:48:42 +00:00
|
|
|
|
2015-08-21 04:13:00 +00:00
|
|
|
// Copy the guid so direct unbinding works
|
2012-01-08 01:48:42 +00:00
|
|
|
if ( typeof handler !== "string" ) {
|
|
|
|
handlerProxy.guid = handler.guid =
|
2012-06-18 22:09:28 +00:00
|
|
|
handler.guid || handlerProxy.guid || $.guid++;
|
2012-01-08 01:48:42 +00:00
|
|
|
}
|
|
|
|
|
2014-01-03 17:19:32 +00:00
|
|
|
var match = event.match( /^([\w:-]*)\s*(.*)$/ ),
|
2015-03-14 11:37:03 +00:00
|
|
|
eventName = match[ 1 ] + instance.eventNamespace,
|
|
|
|
selector = match[ 2 ];
|
2011-07-28 19:55:38 +00:00
|
|
|
if ( selector ) {
|
2015-05-14 02:02:32 +00:00
|
|
|
delegateElement.on( eventName, selector, handlerProxy );
|
2011-07-28 19:55:38 +00:00
|
|
|
} else {
|
2015-05-14 02:02:32 +00:00
|
|
|
element.on( eventName, handlerProxy );
|
2011-06-20 20:31:28 +00:00
|
|
|
}
|
2015-03-14 11:37:03 +00:00
|
|
|
} );
|
2011-01-18 06:46:26 +00:00
|
|
|
},
|
|
|
|
|
2012-06-14 16:33:16 +00:00
|
|
|
_off: function( element, eventName ) {
|
2015-03-14 11:37:03 +00:00
|
|
|
eventName = ( eventName || "" ).split( " " ).join( this.eventNamespace + " " ) +
|
2014-08-20 19:54:31 +00:00
|
|
|
this.eventNamespace;
|
2015-05-14 02:02:32 +00:00
|
|
|
element.off( eventName ).off( eventName );
|
2014-08-20 19:54:31 +00:00
|
|
|
|
|
|
|
// Clear the stack to avoid memory leaks (#10056)
|
|
|
|
this.bindings = $( this.bindings.not( element ).get() );
|
|
|
|
this.focusable = $( this.focusable.not( element ).get() );
|
|
|
|
this.hoverable = $( this.hoverable.not( element ).get() );
|
2012-06-14 16:33:16 +00:00
|
|
|
},
|
|
|
|
|
2011-09-12 21:37:14 +00:00
|
|
|
_delay: function( handler, delay ) {
|
|
|
|
function handlerProxy() {
|
|
|
|
return ( typeof handler === "string" ? instance[ handler ] : handler )
|
|
|
|
.apply( instance, arguments );
|
|
|
|
}
|
|
|
|
var instance = this;
|
2011-09-12 21:47:09 +00:00
|
|
|
return setTimeout( handlerProxy, delay || 0 );
|
2011-09-12 21:37:14 +00:00
|
|
|
},
|
|
|
|
|
2011-01-21 20:37:18 +00:00
|
|
|
_hoverable: function( element ) {
|
|
|
|
this.hoverable = this.hoverable.add( element );
|
2012-06-13 12:00:45 +00:00
|
|
|
this._on( element, {
|
2011-01-21 20:37:18 +00:00
|
|
|
mouseenter: function( event ) {
|
2014-12-03 16:20:20 +00:00
|
|
|
this._addClass( $( event.currentTarget ), null, "ui-state-hover" );
|
2011-01-21 20:37:18 +00:00
|
|
|
},
|
|
|
|
mouseleave: function( event ) {
|
2014-12-03 16:20:20 +00:00
|
|
|
this._removeClass( $( event.currentTarget ), null, "ui-state-hover" );
|
2011-01-21 20:37:18 +00:00
|
|
|
}
|
2015-03-14 11:37:03 +00:00
|
|
|
} );
|
2011-01-21 20:37:18 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_focusable: function( element ) {
|
|
|
|
this.focusable = this.focusable.add( element );
|
2012-06-13 12:00:45 +00:00
|
|
|
this._on( element, {
|
2011-02-01 02:55:22 +00:00
|
|
|
focusin: function( event ) {
|
2014-12-03 16:20:20 +00:00
|
|
|
this._addClass( $( event.currentTarget ), null, "ui-state-focus" );
|
2011-01-21 20:37:18 +00:00
|
|
|
},
|
2011-02-01 02:55:22 +00:00
|
|
|
focusout: function( event ) {
|
2014-12-03 16:20:20 +00:00
|
|
|
this._removeClass( $( event.currentTarget ), null, "ui-state-focus" );
|
2011-01-21 20:37:18 +00:00
|
|
|
}
|
2015-03-14 11:37:03 +00:00
|
|
|
} );
|
2011-01-21 20:37:18 +00:00
|
|
|
},
|
|
|
|
|
2010-01-15 20:47:41 +00:00
|
|
|
_trigger: function( type, event, data ) {
|
2011-11-21 16:31:51 +00:00
|
|
|
var prop, orig,
|
2011-11-21 16:14:19 +00:00
|
|
|
callback = this.options[ type ];
|
2009-12-16 22:20:18 +00:00
|
|
|
|
2011-11-21 16:14:19 +00:00
|
|
|
data = data || {};
|
2010-01-15 20:47:41 +00:00
|
|
|
event = $.Event( event );
|
|
|
|
event.type = ( type === this.widgetEventPrefix ?
|
2010-01-15 22:15:18 +00:00
|
|
|
type :
|
|
|
|
this.widgetEventPrefix + type ).toLowerCase();
|
2015-08-21 04:13:00 +00:00
|
|
|
|
|
|
|
// The original event may come from any element
|
2011-11-21 16:14:19 +00:00
|
|
|
// so we need to reset the target on the new event
|
|
|
|
event.target = this.element[ 0 ];
|
2009-12-16 22:20:18 +00:00
|
|
|
|
2015-08-21 04:13:00 +00:00
|
|
|
// Copy original event properties over to the new event
|
2011-11-21 16:14:19 +00:00
|
|
|
orig = event.originalEvent;
|
|
|
|
if ( orig ) {
|
|
|
|
for ( prop in orig ) {
|
|
|
|
if ( !( prop in event ) ) {
|
|
|
|
event[ prop ] = orig[ prop ];
|
|
|
|
}
|
2009-12-16 22:20:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-15 20:47:41 +00:00
|
|
|
this.element.trigger( event, data );
|
2011-02-01 11:57:48 +00:00
|
|
|
return !( $.isFunction( callback ) &&
|
2015-03-14 11:37:03 +00:00
|
|
|
callback.apply( this.element[ 0 ], [ event ].concat( data ) ) === false ||
|
2010-01-15 22:15:18 +00:00
|
|
|
event.isDefaultPrevented() );
|
2009-12-16 22:20:18 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-04-15 14:49:29 +00:00
|
|
|
$.each( { show: "fadeIn", hide: "fadeOut" }, function( method, defaultEffect ) {
|
|
|
|
$.Widget.prototype[ "_" + method ] = function( element, options, callback ) {
|
2011-05-30 22:27:48 +00:00
|
|
|
if ( typeof options === "string" ) {
|
|
|
|
options = { effect: options };
|
|
|
|
}
|
|
|
|
var hasOptions,
|
|
|
|
effectName = !options ?
|
|
|
|
method :
|
|
|
|
options === true || typeof options === "number" ?
|
|
|
|
defaultEffect :
|
|
|
|
options.effect || defaultEffect;
|
2011-04-15 14:49:29 +00:00
|
|
|
options = options || {};
|
2011-05-30 22:27:48 +00:00
|
|
|
if ( typeof options === "number" ) {
|
|
|
|
options = { duration: options };
|
|
|
|
}
|
|
|
|
hasOptions = !$.isEmptyObject( options );
|
2011-04-15 14:49:29 +00:00
|
|
|
options.complete = callback;
|
2011-05-28 14:18:39 +00:00
|
|
|
if ( options.delay ) {
|
2011-04-21 12:30:42 +00:00
|
|
|
element.delay( options.delay );
|
|
|
|
}
|
2012-10-25 13:25:40 +00:00
|
|
|
if ( hasOptions && $.effects && $.effects.effect[ effectName ] ) {
|
2011-04-15 14:49:29 +00:00
|
|
|
element[ method ]( options );
|
2011-05-02 11:49:59 +00:00
|
|
|
} else if ( effectName !== method && element[ effectName ] ) {
|
|
|
|
element[ effectName ]( options.duration, options.easing, callback );
|
2011-05-02 11:11:58 +00:00
|
|
|
} else {
|
2015-03-14 11:37:03 +00:00
|
|
|
element.queue( function( next ) {
|
2011-05-02 11:11:58 +00:00
|
|
|
$( this )[ method ]();
|
|
|
|
if ( callback ) {
|
|
|
|
callback.call( element[ 0 ] );
|
|
|
|
}
|
2011-05-30 22:27:48 +00:00
|
|
|
next();
|
2015-03-14 11:37:03 +00:00
|
|
|
} );
|
2011-04-15 14:49:29 +00:00
|
|
|
}
|
|
|
|
};
|
2015-03-14 11:37:03 +00:00
|
|
|
} );
|
2011-04-15 14:49:29 +00:00
|
|
|
|
2013-07-12 16:40:48 +00:00
|
|
|
return $.widget;
|
|
|
|
|
2015-03-14 11:37:03 +00:00
|
|
|
} ) );
|