aboutsummaryrefslogtreecommitdiffstats
path: root/ui/jquery.ui.widget.js
diff options
context:
space:
mode:
authorScott González <scott.gonzalez@gmail.com>2011-01-18 01:46:26 -0500
committerScott González <scott.gonzalez@gmail.com>2011-01-18 01:46:26 -0500
commit659db70caa2ff1e3a43e98f3895f0353ebcee154 (patch)
treef147fa26ce8db5c879f24582ac7bed93c96fa7fd /ui/jquery.ui.widget.js
parent67b070f97a6dc4907cbb5e69b8899c0b5c716684 (diff)
downloadjquery-ui-659db70caa2ff1e3a43e98f3895f0353ebcee154.tar.gz
jquery-ui-659db70caa2ff1e3a43e98f3895f0353ebcee154.zip
Widget: Added ._bind() for easily binding events with correct context and disabled checking. Pretty much a direct copy from the previous bind branch.
Diffstat (limited to 'ui/jquery.ui.widget.js')
-rw-r--r--ui/jquery.ui.widget.js22
1 files changed, 22 insertions, 0 deletions
diff --git a/ui/jquery.ui.widget.js b/ui/jquery.ui.widget.js
index 59c362838..4d786e5c6 100644
--- a/ui/jquery.ui.widget.js
+++ b/ui/jquery.ui.widget.js
@@ -129,6 +129,8 @@ $.Widget.prototype = {
this._getCreateOptions(),
options );
+ this.bindings = $();
+
var self = this;
this.element.bind( "remove." + this.widgetName, function() {
self.destroy();
@@ -162,6 +164,7 @@ $.Widget.prototype = {
.removeClass(
this.widgetBaseClass + "-disabled " +
"ui-state-disabled" );
+ this.bindings.unbind( "." + this.widgetName );
},
_destroy: $.noop,
@@ -216,6 +219,25 @@ $.Widget.prototype = {
return this._setOption( "disabled", true );
},
+ _bind: function( element, handlers ) {
+ // no element argument, shuffle and use this.element
+ if ( !handlers ) {
+ handlers = element;
+ element = this.element;
+ } else {
+ this.bindings = this.bindings.add( element );
+ }
+ var instance = this;
+ $.each( handlers, function( event, handler ) {
+ element.bind( event + "." + instance.widgetName, function() {
+ if ( instance.options.disabled ) {
+ return;
+ }
+ return handler.apply( instance, arguments );
+ });
+ });
+ },
+
_trigger: function( type, event, data ) {
var callback = this.options[ type ];