github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

jquery / jquery-ui

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 364
    • 43
  • Source
  • Commits
  • Network (43)
  • Graphs
  • Branch: bind

click here to add a description

click here to add a homepage

  • Switch Branches (6)
    • bind ✓
    • formcontrols
    • master
    • menu
    • panel
    • tooltip
  • Switch Tags (15)
    • 1.8rc3
    • 1.8rc2
    • 1.8rc1
    • 1.8b1
    • 1.8a2
    • 1.8a1
    • 1.8
    • 1.7
    • 1.6rc6
    • 1.6rc5
    • 1.6rc3
    • 1.6rc2
    • 1.6
    • 1.5.2
    • 1.5.1
  • Branch List

Compare View

switch master...bind

Transform Comparison to Pull Request

Choose a ref to start at

Starting point can be a commit SHA, branch name or tag name.

Last commit Sat Mar 27 03:06:24 -0700 2010

Showing 5 unique commits by 1 author.

fd8d5d21 jzaefferer Placeholder for _bind prototype Mon Mar 22 07:24:23 -0700 2010
faf963c9 jzaefferer Extended placeholder for _bind with usage code and some TODOs Comment Mon Mar 22 07:50:09 -0700 2010
55937363 jzaefferer Unit tests and implementation for $.Widget.prototype._bind, handlin... Fri Mar 26 09:25:24 -0700 2010
015391f1 jzaefferer Merge branch 'master' into bind Fri Mar 26 09:45:00 -0700 2010
3599dd7e jzaefferer Merge branch 'master' into bind Sat Mar 27 03:06:24 -0700 2010

Showing 2 changed files with 98 additions and 0 deletions.

M tests/unit/widget/widget.js 72 •••••
M ui/jquery.ui.widget.js 26 •••••
Txt tests/unit/widget/widget.js
  • View file @ 3599dd7
... ...
@@ -146,12 +146,18 @@ test('merge multiple option arguments', function() {
146 146
   });
147 147
 });
148 148
 
  149
+function teardownWidget(name) {
  150
+  delete $.fn[name];
  151
+  delete $.ui[name];
  152
+}
  153
+
149 154
 test(".widget() - base", function() {
150 155
   $.widget("ui.testWidget", {
151 156
     _create: function() {}
152 157
   });
153 158
   var div = $("<div></div>").testWidget()
154 159
   same(div[0], div.testWidget("widget")[0]);
  160
+  teardownWidget("testWidget");
155 161
 });
156 162
 
157 163
 test(".widget() - overriden", function() {
... ...
@@ -163,6 +169,72 @@ test(".widget() - overriden", function() {
163 169
     }
164 170
   });
165 171
   same(wrapper[0], $("<div></div>").testWidget().testWidget("widget")[0]);
  172
+  teardownWidget("testWidget");
  173
+});
  174
+
  175
+test("_bind to element (default)", function() {
  176
+  expect(12);
  177
+  var self;
  178
+  $.widget("ui.testWidget", {
  179
+    _create: function() {
  180
+      self = this;
  181
+      this._bind({
  182
+        keyup: this.keyup,
  183
+        keydown: this.keydown
  184
+      });
  185
+    },
  186
+    keyup: function(event) {
  187
+      equals( self, this );
  188
+      equals( self.element[0], event.currentTarget );
  189
+      equals( "keyup", event.type );
  190
+    },
  191
+    keydown: function(event) {
  192
+      equals( self, this );
  193
+      equals( self.element[0], event.currentTarget );
  194
+      equals( "keydown", event.type );
  195
+    }
  196
+  });
  197
+  var widget = $("<div></div>").testWidget().trigger("keyup").trigger("keydown");
  198
+  widget.testWidget("disable").trigger("keyup").trigger("keydown");
  199
+  widget.testWidget("enable").trigger("keyup").trigger("keydown");
  200
+  widget.testWidget("destroy").trigger("keyup").trigger("keydown");
  201
+  teardownWidget("testWidget");
166 202
 });
167 203
 
  204
+test("_bind to descendent", function() {
  205
+  expect(12);
  206
+  var self;
  207
+  $.widget("ui.testWidget", {
  208
+    _create: function() {
  209
+      self = this;
  210
+      this._bind(this.element.find("strong"), {
  211
+        keyup: this.keyup,
  212
+        keydown: this.keydown
  213
+      });
  214
+    },
  215
+    keyup: function(event) {
  216
+      equals( self, this );
  217
+      equals( self.element.find("strong")[0], event.currentTarget );
  218
+      equals( "keyup", event.type );
  219
+    },
  220
+    keydown: function(event) {
  221
+      equals( self, this );
  222
+      equals( self.element.find("strong")[0], event.currentTarget );
  223
+      equals( "keydown", event.type );
  224
+    }
  225
+  });
  226
+  // trigger events on both widget and descendent to ensure that only descendent receives them
  227
+  var widget = $("<div><p><strong>hello</strong> world</p></div>").testWidget().trigger("keyup").trigger("keydown");
  228
+  var descendent = widget.find("strong").trigger("keyup").trigger("keydown");
  229
+  widget.testWidget("disable").trigger("keyup").trigger("keydown");
  230
+  descendent.trigger("keyup").trigger("keydown");
  231
+  widget.testWidget("enable").trigger("keyup").trigger("keydown");
  232
+  descendent.trigger("keyup").trigger("keydown");
  233
+  widget.testWidget("destroy").trigger("keyup").trigger("keydown");
  234
+  descendent.trigger("keyup").trigger("keydown");
  235
+  teardownWidget("testWidget");
  236
+});
  237
+
  238
+// test destroy and disabled
  239
+
168 240
 })(jQuery);
Txt ui/jquery.ui.widget.js
  • View file @ 3599dd7
... ...
@@ -139,6 +139,9 @@ $.Widget.prototype = {
139 139
     this.element.bind( "remove." + this.widgetName, function() {
140 140
       self.destroy();
141 141
     });
  142
+    
  143
+    // used by _bind
  144
+    this.bindings = $();
142 145
 
143 146
     this._create();
144 147
     this._init();
... ...
@@ -156,6 +159,8 @@ $.Widget.prototype = {
156 159
       .removeClass(
157 160
         this.widgetBaseClass + "-disabled " +
158 161
         this.namespace + "-state-disabled" );
  162
+    this.bindings
  163
+      .unbind( "." + this.widgetName );
159 164
   },
160 165
 
161 166
   widget: function() {
... ...
@@ -205,6 +210,27 @@ $.Widget.prototype = {
205 210
   disable: function() {
206 211
     return this._setOption( "disabled", true );
207 212
   },
  213
+  
  214
+  _bind: function( element, handlers ) {
  215
+    // no element argument, shuffle and use this.element
  216
+    if ( handlers == undefined ) {
  217
+      handlers = element;
  218
+      element = this.element;
  219
+    // if binding to something else then this.element, store for unbinding on destroy
  220
+    } else {
  221
+      this.bindings = this.bindings.add( element );
  222
+    }
  223
+    var instance = this;
  224
+    $.each( handlers, function(event, handler) {
  225
+      element.bind( event + "." + instance.widgetName, function() {
  226
+        if ( instance.options.disabled ) {
  227
+          return;
  228
+        }
  229
+        return handler.apply( instance, arguments );
  230
+      });
  231
+      
  232
+    });    
  233
+  },
208 234
 
209 235
   _trigger: function( type, event, data ) {
210 236
     var callback = this.options[ type ];

Showing you all comments on commits in this comparison.

scottgonzalez 29 days ago on faf963c9

How about this._bind( ".headers" ), { ... } ) -> this.widget().find( ".headers", { ... } )

Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server