aboutsummaryrefslogtreecommitdiffstats
path: root/ui/jquery.ui.widget.js
diff options
context:
space:
mode:
Diffstat (limited to 'ui/jquery.ui.widget.js')
-rw-r--r--ui/jquery.ui.widget.js50
1 files changed, 33 insertions, 17 deletions
diff --git a/ui/jquery.ui.widget.js b/ui/jquery.ui.widget.js
index 6b84f7a9c..10a25b611 100644
--- a/ui/jquery.ui.widget.js
+++ b/ui/jquery.ui.widget.js
@@ -36,7 +36,9 @@ $.widget = function( name, base, prototype ) {
};
$[ namespace ] = $[ namespace ] || {};
- $[ namespace ][ name ] = $[ namespace ][ name ] || function( options, element ) {
+ // 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 ) {
// allow instantiation without "new" keyword
if ( !this._createWidget ) {
return new $[ namespace ][ name ]( options, element );
@@ -47,19 +49,45 @@ $.widget = function( name, base, prototype ) {
if ( arguments.length ) {
this._createWidget( options, element );
}
- };
+ }, $[ namespace ][ name ] );
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
basePrototype.options = $.extend( true, {}, basePrototype.options );
+ $.each( prototype, function( prop, value ) {
+ if ( $.isFunction( value ) ) {
+ prototype[ prop ] = (function() {
+ var _super = function( method ) {
+ return base.prototype[ method ].apply( this, slice.call( arguments, 1 ) );
+ };
+ var _superApply = function( method, args ) {
+ return base.prototype[ method ].apply( this, args );
+ };
+ return function() {
+ var __super = this._super,
+ __superApply = this._superApply,
+ returnValue;
+
+ this._super = _super;
+ this._superApply = _superApply;
+
+ returnValue = value.apply( this, arguments );
+
+ this._super = __super;
+ this._superApply = __superApply;
+
+ return returnValue;
+ };
+ }());
+ }
+ });
$[ namespace ][ name ].prototype = $.extend( true, basePrototype, {
namespace: namespace,
widgetName: name,
widgetEventPrefix: name,
- widgetBaseClass: fullName,
- base: base.prototype
+ widgetBaseClass: fullName
}, prototype );
$.widget.bridge( name, $[ namespace ][ name ] );
@@ -76,11 +104,6 @@ $.widget.bridge = function( name, object ) {
$.extend.apply( null, [ true, options ].concat(args) ) :
options;
- // prevent calls to internal methods
- if ( isMethodCall && options.charAt( 0 ) === "_" ) {
- return returnValue;
- }
-
if ( isMethodCall ) {
this.each(function() {
var instance = $.data( this, name );
@@ -88,7 +111,7 @@ $.widget.bridge = function( name, object ) {
return $.error( "cannot call methods on " + name + " prior to initialization; " +
"attempted to call method '" + options + "'" );
}
- if ( !$.isFunction( instance[options] ) ) {
+ if ( !$.isFunction( instance[options] ) || options.charAt( 0 ) === "_" ) {
return $.error( "no such method '" + options + "' for " + name + " widget instance" );
}
var methodValue = instance[ options ].apply( instance, args );
@@ -159,13 +182,6 @@ $.Widget.prototype = {
_create: $.noop,
_init: $.noop,
- _super: function( method ) {
- return this.base[ method ].apply( this, slice.call( arguments, 1 ) );
- },
- _superApply: function( method, args ) {
- return this.base[ method ].apply( this, args );
- },
-
destroy: function() {
this._destroy();
// we can probably remove the unbind calls in 2.0