2009-12-16 22:20:18 +00:00
|
|
|
/*!
|
2009-12-22 19:51:24 +00:00
|
|
|
* jQuery UI Widget @VERSION
|
2009-12-16 22:20:18 +00:00
|
|
|
*
|
2011-01-17 14:13:18 +00:00
|
|
|
* Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
|
2010-07-09 13:01:04 +00:00
|
|
|
* Dual licensed under the MIT or GPL Version 2 licenses.
|
|
|
|
* http://jquery.org/license
|
2009-12-16 22:20:18 +00:00
|
|
|
*
|
2009-12-22 19:51:24 +00:00
|
|
|
* http://docs.jquery.com/UI/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
|
|
|
|
2011-01-14 20:52:03 +00:00
|
|
|
var slice = Array.prototype.slice;
|
|
|
|
|
2011-01-14 00:26:52 +00:00
|
|
|
var _cleanData = $.cleanData;
|
|
|
|
$.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 ) {
|
|
|
|
var namespace = name.split( "." )[ 0 ],
|
2009-12-16 22:20:18 +00:00
|
|
|
fullName;
|
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
|
2010-01-15 20:47:41 +00:00
|
|
|
$.expr[ ":" ][ fullName ] = function( elem ) {
|
|
|
|
return !!$.data( elem, name );
|
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 ] || {};
|
2011-02-11 02:25:50 +00:00
|
|
|
// create the constructor using $.extend() so we can carry over any
|
|
|
|
// static properties stored on the existing constructor (if there is one)
|
|
|
|
$[ namespace ][ name ] = $.extend( function( options, element ) {
|
2011-01-23 01:39:37 +00:00
|
|
|
// allow instantiation without "new" keyword
|
|
|
|
if ( !this._createWidget ) {
|
|
|
|
return new $[ namespace ][ name ]( options, element );
|
|
|
|
}
|
|
|
|
|
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 );
|
|
|
|
}
|
2011-05-28 19:39:55 +00:00
|
|
|
}, $[ namespace ][ name ], { version: prototype.version } );
|
2010-01-07 03:19:50 +00:00
|
|
|
|
|
|
|
var basePrototype = new base();
|
|
|
|
// 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() {
|
|
|
|
var _super = function( method ) {
|
2011-02-11 02:25:50 +00:00
|
|
|
return base.prototype[ method ].apply( this, slice.call( arguments, 1 ) );
|
|
|
|
};
|
2011-02-11 02:32:33 +00:00
|
|
|
var _superApply = function( method, args ) {
|
2011-02-11 02:25:50 +00:00
|
|
|
return base.prototype[ method ].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
|
|
|
};
|
|
|
|
}());
|
2011-02-11 02:25:50 +00:00
|
|
|
}
|
|
|
|
});
|
2011-05-11 17:37:40 +00:00
|
|
|
$[ namespace ][ name ].prototype = $.widget.extend( basePrototype, {
|
2010-01-07 03:19:50 +00:00
|
|
|
namespace: namespace,
|
|
|
|
widgetName: name,
|
2011-01-14 00:32:08 +00:00
|
|
|
widgetEventPrefix: name,
|
2011-02-11 02:25:50 +00:00
|
|
|
widgetBaseClass: fullName
|
2010-01-15 20:47:41 +00:00
|
|
|
}, prototype );
|
2010-01-07 03:19:50 +00:00
|
|
|
|
2010-01-15 20:47:41 +00:00
|
|
|
$.widget.bridge( name, $[ namespace ][ name ] );
|
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 ) {
|
|
|
|
target[ key ] = $.isPlainObject( value ) ? $.widget.extend( {}, target[ key ], value ) : value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return target;
|
|
|
|
};
|
|
|
|
|
2010-01-15 20:47:41 +00:00
|
|
|
$.widget.bridge = function( name, object ) {
|
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() {
|
2010-12-10 19:11:20 +00:00
|
|
|
var instance = $.data( this, name );
|
|
|
|
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" );
|
|
|
|
}
|
|
|
|
var 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() {
|
2010-01-15 21:09:32 +00:00
|
|
|
var instance = $.data( this, name );
|
|
|
|
if ( instance ) {
|
2010-08-23 19:35:49 +00:00
|
|
|
instance.option( options || {} )._init();
|
2010-01-15 21:09:32 +00:00
|
|
|
} else {
|
2011-01-23 01:39:37 +00:00
|
|
|
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
|
|
|
|
2010-01-15 20:47:41 +00:00
|
|
|
$.Widget = function( options, element ) {
|
2011-01-23 01:39:37 +00:00
|
|
|
// allow instantiation without "new" keyword
|
|
|
|
if ( !this._createWidget ) {
|
|
|
|
return new $[ namespace ][ name ]( options, element );
|
|
|
|
}
|
|
|
|
|
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 );
|
|
|
|
}
|
2010-01-07 03:19:50 +00:00
|
|
|
};
|
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 );
|
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 ) {
|
|
|
|
$.data( element, this.widgetName, this );
|
|
|
|
this._bind({ remove: "destroy" });
|
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();
|
2010-09-30 00:36:45 +00:00
|
|
|
this._trigger( "create" );
|
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,
|
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
|
|
|
|
// all event bindings should go through this._bind()
|
2010-01-07 03:19:50 +00:00
|
|
|
this.element
|
2010-01-15 20:47:41 +00:00
|
|
|
.unbind( "." + this.widgetName )
|
|
|
|
.removeData( this.widgetName );
|
2010-01-07 03:19:50 +00:00
|
|
|
this.widget()
|
2010-01-15 20:47:41 +00:00
|
|
|
.unbind( "." + this.widgetName )
|
|
|
|
.removeAttr( "aria-disabled" )
|
2010-01-07 03:19:50 +00:00
|
|
|
.removeClass(
|
2010-01-15 20:47:41 +00:00
|
|
|
this.widgetBaseClass + "-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
|
2011-01-18 06:46:26 +00:00
|
|
|
this.bindings.unbind( "." + this.widgetName );
|
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 ) {
|
|
|
|
var self = this;
|
2010-01-15 20:47:41 +00:00
|
|
|
$.each( options, function( key, value ) {
|
|
|
|
self._setOption( key, value );
|
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()
|
2010-12-19 21:52:22 +00:00
|
|
|
.toggleClass( this.widgetBaseClass + "-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
|
|
|
},
|
|
|
|
|
2011-01-18 06:46:26 +00:00
|
|
|
_bind: function( element, handlers ) {
|
|
|
|
// 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
|
|
|
}
|
2011-06-20 20:31:28 +00:00
|
|
|
var match = event.match( /^(\w+)\s*(.*)$/ ),
|
|
|
|
eventName = match[1] + "." + instance.widgetName,
|
2011-06-08 20:14:37 +00:00
|
|
|
selector = match[2];
|
2011-07-28 19:55:38 +00:00
|
|
|
if ( selector ) {
|
2011-06-20 20:31:28 +00:00
|
|
|
element.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
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2011-01-21 20:37:18 +00:00
|
|
|
_hoverable: function( element ) {
|
|
|
|
this.hoverable = this.hoverable.add( element );
|
|
|
|
this._bind( element, {
|
|
|
|
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 );
|
|
|
|
this._bind( 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-02-01 11:57:48 +00:00
|
|
|
var callback = this.options[ type ],
|
|
|
|
args;
|
2009-12-16 22:20:18 +00:00
|
|
|
|
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();
|
2009-12-16 22:20:18 +00:00
|
|
|
data = data || {};
|
|
|
|
|
|
|
|
// copy original event properties over to the new event
|
|
|
|
// this would happen if we could call $.event.fix instead of $.Event
|
|
|
|
// but we don't have a way to force an event to be fixed multiple times
|
2010-01-15 20:47:41 +00:00
|
|
|
if ( event.originalEvent ) {
|
|
|
|
for ( var i = $.event.props.length, prop; i; ) {
|
|
|
|
prop = $.event.props[ --i ];
|
|
|
|
event[ prop ] = event.originalEvent[ prop ];
|
2009-12-16 22:20:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-15 20:47:41 +00:00
|
|
|
this.element.trigger( event, data );
|
2009-12-16 22:20:18 +00:00
|
|
|
|
2011-02-01 11:57:48 +00:00
|
|
|
args = $.isArray( data ) ?
|
|
|
|
[ event ].concat( data ) :
|
|
|
|
[ event, data ];
|
|
|
|
|
|
|
|
return !( $.isFunction( callback ) &&
|
|
|
|
callback.apply( this.element[0], args ) === 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 );
|