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
|
|
|
*
|
2012-07-04 13:08:08 +00:00
|
|
|
* Copyright 2012 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
|
|
|
*
|
2012-09-26 23:06:20 +00:00
|
|
|
* http://api.jqueryui.com/jQuery.widget/
|
2009-12-16 22:20:18 +00:00
|
|
|
*/
|
2010-07-13 13:57:58 +00:00
|
|
|
(function( $, undefined ) {
|
2009-12-22 19:51:24 +00:00
|
|
|
|
2012-06-10 18:55:04 +00:00
|
|
|
var uuid = 0,
|
|
|
|
slice = Array.prototype.slice,
|
2012-04-02 23:12:21 +00:00
|
|
|
_cleanData = $.cleanData;
|
2011-01-14 00:26:52 +00:00
|
|
|
$.cleanData = function( elems ) {
|
|
|
|
for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
|
2011-08-09 15:45:41 +00:00
|
|
|
try {
|
|
|
|
$( elem ).triggerHandler( "remove" );
|
|
|
|
// http://bugs.jquery.com/ticket/8235
|
|
|
|
} catch( e ) {}
|
2011-01-14 00:26:52 +00:00
|
|
|
}
|
|
|
|
_cleanData( elems );
|
|
|
|
};
|
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,
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-12-16 22:20:18 +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 ) {
|
2011-01-23 01:39:37 +00:00
|
|
|
// allow instantiation without "new" keyword
|
|
|
|
if ( !this._createWidget ) {
|
2012-02-01 21:59:26 +00:00
|
|
|
return new constructor( options, element );
|
2011-01-23 01:39:37 +00:00
|
|
|
}
|
|
|
|
|
2010-01-07 03:19:50 +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
|
|
|
};
|
|
|
|
// extend with the existing constructor to carry over any static properties
|
|
|
|
$.extend( constructor, existingConstructor, {
|
|
|
|
version: prototype.version,
|
|
|
|
// copy the object used to create the prototype in case we need to
|
|
|
|
// redefine the widget later
|
|
|
|
_proto: $.extend( {}, prototype ),
|
|
|
|
// track widgets that inherit from this widget in case this widget is
|
|
|
|
// redefined after a widget inherits from it
|
|
|
|
_childConstructors: []
|
|
|
|
});
|
2010-01-07 03:19:50 +00:00
|
|
|
|
2012-02-01 21:59:26 +00:00
|
|
|
basePrototype = new base();
|
2010-01-07 03:19:50 +00:00
|
|
|
// we need to make the options hash a property directly on the new instance
|
|
|
|
// 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 ) {
|
|
|
|
if ( $.isFunction( value ) ) {
|
2011-02-11 02:32:33 +00:00
|
|
|
prototype[ prop ] = (function() {
|
2011-11-18 11:19:32 +00:00
|
|
|
var _super = function() {
|
2012-04-02 23:12:21 +00:00
|
|
|
return base.prototype[ prop ].apply( this, arguments );
|
|
|
|
},
|
|
|
|
_superApply = function( args ) {
|
|
|
|
return base.prototype[ prop ].apply( this, args );
|
|
|
|
};
|
2011-02-11 02:32:33 +00:00
|
|
|
return function() {
|
2011-02-11 13:53:43 +00:00
|
|
|
var __super = this._super,
|
|
|
|
__superApply = this._superApply,
|
|
|
|
returnValue;
|
|
|
|
|
2011-02-11 02:32:33 +00:00
|
|
|
this._super = _super;
|
|
|
|
this._superApply = _superApply;
|
2011-02-11 13:53:43 +00:00
|
|
|
|
|
|
|
returnValue = value.apply( this, arguments );
|
|
|
|
|
|
|
|
this._super = __super;
|
|
|
|
this._superApply = __superApply;
|
|
|
|
|
|
|
|
return returnValue;
|
2011-02-11 02:32:33 +00:00
|
|
|
};
|
2012-02-01 21:59:26 +00:00
|
|
|
})();
|
2011-02-11 02:25:50 +00:00
|
|
|
}
|
|
|
|
});
|
2012-02-01 21:59:26 +00:00
|
|
|
constructor.prototype = $.widget.extend( basePrototype, {
|
|
|
|
// 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
|
|
|
|
widgetEventPrefix: name
|
|
|
|
}, prototype, {
|
|
|
|
constructor: constructor,
|
2010-01-07 03:19:50 +00:00
|
|
|
namespace: namespace,
|
|
|
|
widgetName: name,
|
2012-03-01 13:36:17 +00:00
|
|
|
// TODO remove widgetBaseClass, see #8155
|
|
|
|
widgetBaseClass: fullName,
|
|
|
|
widgetFullName: fullName
|
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;
|
|
|
|
|
|
|
|
// redefine the child widget using the same prototype that was
|
|
|
|
// originally used, but inherit from the new version of the base
|
|
|
|
$.widget( childPrototype.namespace + "." + childPrototype.widgetName, constructor, child._proto );
|
|
|
|
});
|
|
|
|
// remove the list of existing child constructors from the old constructor
|
|
|
|
// 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 );
|
2010-01-07 03:19:50 +00:00
|
|
|
};
|
|
|
|
|
2011-05-11 17:37:40 +00:00
|
|
|
$.widget.extend = function( target ) {
|
|
|
|
var input = slice.call( arguments, 1 ),
|
|
|
|
inputIndex = 0,
|
|
|
|
inputLength = input.length,
|
|
|
|
key,
|
|
|
|
value;
|
|
|
|
for ( ; inputIndex < inputLength; inputIndex++ ) {
|
|
|
|
for ( key in input[ inputIndex ] ) {
|
|
|
|
value = input[ inputIndex ][ key ];
|
|
|
|
if (input[ inputIndex ].hasOwnProperty( key ) && value !== undefined ) {
|
2012-10-22 19:33:57 +00:00
|
|
|
if ( $.isPlainObject( value ) && $.isPlainObject( target[ key ] ) ) {
|
|
|
|
target[ key ] = $.widget.extend( {}, target[ key ], value );
|
|
|
|
} 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-03-01 13:36:17 +00:00
|
|
|
var fullName = object.prototype.widgetFullName;
|
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",
|
2011-01-14 20:52:03 +00:00
|
|
|
args = slice.call( arguments, 1 ),
|
2009-12-16 22:20:18 +00:00
|
|
|
returnValue = this;
|
2010-01-15 20:47:41 +00:00
|
|
|
|
2009-12-16 22:20:18 +00:00
|
|
|
// allow multiple hashes to be passed on init
|
2010-01-15 22:15:18 +00:00
|
|
|
options = !isMethodCall && args.length ?
|
2011-05-11 17:37:40 +00:00
|
|
|
$.widget.extend.apply( null, [ options ].concat(args) ) :
|
2010-01-15 22:15:18 +00:00
|
|
|
options;
|
2009-12-16 22:20:18 +00:00
|
|
|
|
2010-01-15 20:47:41 +00:00
|
|
|
if ( isMethodCall ) {
|
|
|
|
this.each(function() {
|
2012-04-02 23:12:21 +00:00
|
|
|
var methodValue,
|
|
|
|
instance = $.data( this, fullName );
|
2010-12-10 19:11:20 +00:00
|
|
|
if ( !instance ) {
|
|
|
|
return $.error( "cannot call methods on " + name + " prior to initialization; " +
|
|
|
|
"attempted to call method '" + options + "'" );
|
|
|
|
}
|
2011-02-16 08:28:32 +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;
|
|
|
|
}
|
2010-01-15 20:47:41 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
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 ) {
|
2010-08-23 19:35:49 +00:00
|
|
|
instance.option( options || {} )._init();
|
2010-01-15 21:09:32 +00:00
|
|
|
} else {
|
2012-02-13 00:58:56 +00:00
|
|
|
new object( options, this );
|
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 02:54:05 +00:00
|
|
|
$.Widget = function() {};
|
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: {
|
2011-04-25 18:04:30 +00:00
|
|
|
disabled: false,
|
|
|
|
|
|
|
|
// callbacks
|
|
|
|
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 );
|
2012-06-14 14:51:29 +00:00
|
|
|
this.uuid = uuid++;
|
|
|
|
this.eventNamespace = "." + this.widgetName + this.uuid;
|
2011-05-11 17:37:40 +00:00
|
|
|
this.options = $.widget.extend( {},
|
2010-01-07 03:19:50 +00:00
|
|
|
this.options,
|
2010-10-06 19:11:49 +00:00
|
|
|
this._getCreateOptions(),
|
2010-01-15 20:47:41 +00:00
|
|
|
options );
|
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 = $();
|
2011-02-01 03:04:09 +00:00
|
|
|
|
|
|
|
if ( element !== this ) {
|
2012-03-01 13:30:02 +00:00
|
|
|
// 1.9 BC for #7810
|
|
|
|
// TODO remove dual storage
|
2011-02-01 03:04:09 +00:00
|
|
|
$.data( element, this.widgetName, this );
|
2012-03-01 13:36:17 +00:00
|
|
|
$.data( element, this.widgetFullName, this );
|
2012-06-13 12:00:45 +00:00
|
|
|
this._on({ remove: "destroy" });
|
2011-11-07 13:39:22 +00:00
|
|
|
this.document = $( element.style ?
|
|
|
|
// element within the document
|
|
|
|
element.ownerDocument :
|
|
|
|
// element is window or document
|
|
|
|
element.document || element );
|
2011-10-21 13:26:07 +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
|
|
|
|
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() {
|
2011-01-14 21:55:13 +00:00
|
|
|
this._destroy();
|
2011-01-21 20:37:18 +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
|
2012-06-14 14:51:29 +00:00
|
|
|
.unbind( this.eventNamespace )
|
2012-03-01 14:13:52 +00:00
|
|
|
// 1.9 BC for #7810
|
|
|
|
// TODO remove dual storage
|
|
|
|
.removeData( this.widgetName )
|
2012-06-11 17:30:03 +00:00
|
|
|
.removeData( this.widgetFullName )
|
|
|
|
// support: jquery <1.6.3
|
|
|
|
// http://bugs.jquery.com/ticket/9413
|
|
|
|
.removeData( $.camelCase( this.widgetFullName ) );
|
2010-01-07 03:19:50 +00:00
|
|
|
this.widget()
|
2012-06-14 14:51:29 +00:00
|
|
|
.unbind( this.eventNamespace )
|
2010-01-15 20:47:41 +00:00
|
|
|
.removeAttr( "aria-disabled" )
|
2010-01-07 03:19:50 +00:00
|
|
|
.removeClass(
|
2012-03-01 13:36:17 +00:00
|
|
|
this.widgetFullName + "-disabled " +
|
2010-03-29 14:00:26 +00:00
|
|
|
"ui-state-disabled" );
|
2011-01-21 20:37:18 +00:00
|
|
|
|
|
|
|
// clean up events and states
|
2012-06-14 14:51:29 +00:00
|
|
|
this.bindings.unbind( this.eventNamespace );
|
2011-01-21 20:37:18 +00:00
|
|
|
this.hoverable.removeClass( "ui-state-hover" );
|
|
|
|
this.focusable.removeClass( "ui-state-focus" );
|
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 ) {
|
2010-01-07 03:19:50 +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" ) {
|
|
|
|
// 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();
|
|
|
|
if ( value === undefined ) {
|
|
|
|
return curOption[ key ] === undefined ? null : curOption[ key ];
|
|
|
|
}
|
|
|
|
curOption[ key ] = value;
|
2011-03-24 13:21:53 +00:00
|
|
|
} else {
|
2011-06-09 13:47:18 +00:00
|
|
|
if ( value === undefined ) {
|
|
|
|
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 ) {
|
|
|
|
this.options[ key ] = value;
|
2009-12-16 22:20:18 +00:00
|
|
|
|
2010-01-15 20:47:41 +00:00
|
|
|
if ( key === "disabled" ) {
|
2010-01-07 03:19:50 +00:00
|
|
|
this.widget()
|
2012-03-01 13:36:17 +00:00
|
|
|
.toggleClass( this.widgetFullName + "-disabled ui-state-disabled", !!value )
|
2010-01-15 20:47:41 +00:00
|
|
|
.attr( "aria-disabled", value );
|
2011-01-21 20:37:18 +00:00
|
|
|
this.hoverable.removeClass( "ui-state-hover" );
|
|
|
|
this.focusable.removeClass( "ui-state-focus" );
|
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
|
|
|
},
|
|
|
|
|
|
|
|
enable: function() {
|
2010-01-15 20:47:41 +00:00
|
|
|
return this._setOption( "disabled", false );
|
2009-12-16 22:20:18 +00:00
|
|
|
},
|
|
|
|
disable: function() {
|
2010-01-15 20:47:41 +00:00
|
|
|
return this._setOption( "disabled", true );
|
2009-12-16 22:20:18 +00:00
|
|
|
},
|
|
|
|
|
2012-06-13 12:00:45 +00:00
|
|
|
_on: function( element, handlers ) {
|
2011-01-18 06:46:26 +00:00
|
|
|
// no element argument, shuffle and use this.element
|
|
|
|
if ( !handlers ) {
|
|
|
|
handlers = element;
|
|
|
|
element = this.element;
|
|
|
|
} else {
|
2011-03-17 10:59:32 +00:00
|
|
|
// accept selectors, DOM elements
|
|
|
|
element = $( 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
|
|
|
var instance = this;
|
|
|
|
$.each( handlers, function( event, handler ) {
|
2011-06-08 20:14:37 +00:00
|
|
|
function handlerProxy() {
|
2011-02-01 02:55:22 +00:00
|
|
|
// allow widgets to customize the disabled handling
|
|
|
|
// - disabled as an array instead of boolean
|
|
|
|
// - disabled class as method for disabling individual parts
|
|
|
|
if ( instance.options.disabled === true ||
|
|
|
|
$( 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
|
|
|
|
|
|
|
// copy the guid so direct unbinding works
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-06-20 20:31:28 +00:00
|
|
|
var match = event.match( /^(\w+)\s*(.*)$/ ),
|
2012-06-14 14:51:29 +00:00
|
|
|
eventName = match[1] + instance.eventNamespace,
|
2011-06-08 20:14:37 +00:00
|
|
|
selector = match[2];
|
2011-07-28 19:55:38 +00:00
|
|
|
if ( selector ) {
|
2011-08-13 02:10:31 +00:00
|
|
|
instance.widget().delegate( selector, eventName, handlerProxy );
|
2011-07-28 19:55:38 +00:00
|
|
|
} else {
|
|
|
|
element.bind( eventName, handlerProxy );
|
2011-06-20 20:31:28 +00:00
|
|
|
}
|
2011-01-18 06:46:26 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2012-06-14 16:33:16 +00:00
|
|
|
_off: function( element, eventName ) {
|
|
|
|
eventName = (eventName || "").split( " " ).join( this.eventNamespace + " " ) + this.eventNamespace;
|
|
|
|
element.unbind( eventName ).undelegate( eventName );
|
|
|
|
},
|
|
|
|
|
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 ) {
|
|
|
|
$( event.currentTarget ).addClass( "ui-state-hover" );
|
|
|
|
},
|
|
|
|
mouseleave: function( event ) {
|
|
|
|
$( event.currentTarget ).removeClass( "ui-state-hover" );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_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 ) {
|
2011-01-21 20:37:18 +00:00
|
|
|
$( event.currentTarget ).addClass( "ui-state-focus" );
|
|
|
|
},
|
2011-02-01 02:55:22 +00:00
|
|
|
focusout: function( event ) {
|
2011-01-21 20:37:18 +00:00
|
|
|
$( event.currentTarget ).removeClass( "ui-state-focus" );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
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();
|
2011-11-21 16:14:19 +00:00
|
|
|
// the original event may come from any element
|
|
|
|
// so we need to reset the target on the new event
|
|
|
|
event.target = this.element[ 0 ];
|
2009-12-16 22:20:18 +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 ) &&
|
2011-11-21 16:31:51 +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 );
|
|
|
|
}
|
2011-05-02 12:49:11 +00:00
|
|
|
if ( hasOptions && $.effects && ( $.effects.effect[ effectName ] || $.uiBackCompat !== false && $.effects[ 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 {
|
2011-05-30 22:27:48 +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();
|
2011-05-02 11:11:58 +00:00
|
|
|
});
|
2011-04-15 14:49:29 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2011-03-23 13:16:19 +00:00
|
|
|
// DEPRECATED
|
|
|
|
if ( $.uiBackCompat !== false ) {
|
|
|
|
$.Widget.prototype._getCreateOptions = function() {
|
|
|
|
return $.metadata && $.metadata.get( this.element[0] )[ this.widgetName ];
|
2011-05-02 12:49:11 +00:00
|
|
|
};
|
2011-03-23 13:16:19 +00:00
|
|
|
}
|
|
|
|
|
2010-01-15 20:47:41 +00:00
|
|
|
})( jQuery );
|