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

jquery / jquery

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 2,215
    • 202
  • Source
  • Commits
  • Network (202)
  • Graphs
  • Tree: 01f7202

click here to add a description

click here to add a homepage

  • Switch Branches (3)
    • master
    • mobile
    • omgrequire
  • Switch Tags (41)
    • 1.4rc1
    • 1.4a2
    • 1.4a1
    • 1.4.2
    • 1.4.1
    • 1.4
    • 1.3rc1
    • 1.3b2
    • 1.3b1
    • 1.3.2
    • 1.3.1rc1
    • 1.3.1
    • 1.3
    • 1.2.6
    • 1.2.5
    • 1.2.4b
    • 1.2.4a
    • 1.2.4
    • 1.2.3b
    • 1.2.3a
    • 1.2.3
    • 1.2.2b2
    • 1.2.2b
    • 1.2.2
    • 1.2.1
    • 1.2
    • 1.1b
    • 1.1a
    • 1.1.4
    • 1.1.3a
    • 1.1.3.1
    • 1.1.3
    • 1.1.2
    • 1.1.1
    • 1.1
    • 1.0a
    • 1.0.4
    • 1.0.3
    • 1.0.2
    • 1.0.1
    • 1.0
  • Comments
Sending Request…

jQuery JavaScript Library — Read more

  Cancel

http://jquery.com/

  Cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Added support for multiple live event handlers, live hover, and live 
focus/blur (mapped to focusin/focusout). Fixes #5804, #5801, #5852.
irae (author)
Sat Jan 23 08:56:24 -0800 2010
jeresig (committer)
Sat Jan 23 08:56:24 -0800 2010
commit  01f72026ec939e87da85a7afc1a5262872ea3ce5
tree    076e43e5ba77c42d155a1f873c4e5c1ffa9e279e
parent  b9ca1579987ab08a7db21a8a0b64f65727f54011
M src/event.js 33 ••••
M test/delegatetest.html 42 •••••
M test/unit/event.js 14 •••••
Txt src/event.js
  • View file @ 01f7202
... ...
@@ -838,23 +838,38 @@ jQuery.fn.extend({
838 838
 
839 839
   hover: function( fnOver, fnOut ) {
840 840
     return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver );
841  
-  },
  841
+  }
  842
+});
  843
+
  844
+jQuery.each(["live", "die"], function( i, name ) {
  845
+  jQuery.fn[ name ] = function( types, data, fn ) {
  846
+    var type, i = 0;
842 847
 
843  
-  live: function( type, data, fn ) {
844 848
     if ( jQuery.isFunction( data ) ) {
845 849
       fn = data;
846 850
       data = undefined;
847 851
     }
848 852
 
849  
-    jQuery( this.context ).bind( liveConvert( type, this.selector ), {
850  
-      data: data, selector: this.selector, live: type
851  
-    }, fn );
  853
+    types = types.split( /\s+/ );
852 854
 
853  
-    return this;
854  
-  },
  855
+    while ( (type = types[ i++ ]) ) {
  856
+      type = type === "focus" ? "focusin" : // focus --> focusin
  857
+          type === "blur" ? "focusout" : // blur --> focusout
  858
+          type === "hover" ? types.push("mouseleave") && "mouseenter" : // hover support
  859
+          type;
  860
+      
  861
+      if ( name === "live" ) {
  862
+        // bind live handler
  863
+        jQuery( this.context ).bind( liveConvert( type, this.selector ), {
  864
+          data: data, selector: this.selector, live: type
  865
+        }, fn );
855 866
 
856  
-  die: function( type, fn ) {
857  
-    jQuery( this.context ).unbind( liveConvert( type, this.selector ), fn ? { guid: fn.guid + this.selector + type } : null );
  867
+      } else {
  868
+        // unbind live handler
  869
+        jQuery( this.context ).unbind( liveConvert( type, this.selector ), fn ? { guid: fn.guid + this.selector + type } : null );
  870
+      }
  871
+    }
  872
+    
858 873
     return this;
859 874
   }
860 875
 });
Txt test/delegatetest.html
  • View file @ 01f7202
... ...
@@ -83,6 +83,7 @@
83 83
           <td id='radiofocus' class="red">RADIO</td>
84 84
           <td id='textfocus' class="red">TEXT</td>
85 85
           <td id='textareafocus' class="red">TEXTAREA</td>
  86
+          <td id='boundFocus' class="red">DOCUMENT</td>
86 87
       </tr>
87 88
       <tr>
88 89
           <td>Focusout:</td>
... ...
@@ -92,6 +93,25 @@
92 93
           <td id='radioblur' class="red">RADIO</td>
93 94
           <td id='textblur' class="red">TEXT</td>
94 95
           <td id='textareablur' class="red">TEXTAREA</td>
  96
+          <td id='boundBlur' class="red">DOCUMENT</td>
  97
+      </tr>
  98
+      <tr>
  99
+          <td>Live Focus:</td>
  100
+          <td id='selectlfocus' class="red">SELECT</td>
  101
+          <td id='mselectlfocus' class="red">MULTI</td>
  102
+          <td id='checkboxlfocus' class="red">CHECKBOX</td>
  103
+          <td id='radiolfocus' class="red">RADIO</td>
  104
+          <td id='textlfocus' class="red">TEXT</td>
  105
+          <td id='textarealfocus' class="red">TEXTAREA</td>
  106
+      </tr>
  107
+      <tr>
  108
+          <td>Live Blur:</td>
  109
+          <td id='selectlblur' class="red">SELECT</td>
  110
+          <td id='mselectlblur' class="red">MULTI</td>
  111
+          <td id='checkboxlblur' class="red">CHECKBOX</td>
  112
+          <td id='radiolblur' class="red">RADIO</td>
  113
+          <td id='textlblur' class="red">TEXT</td>
  114
+          <td id='textarealblur' class="red">TEXTAREA</td>
95 115
       </tr>
96 116
         </table>
97 117
         <h2>Submit Tests</h2>
... ...
@@ -136,6 +156,12 @@
136 156
       jQuery(id + "blur").blink();
137 157
     });
138 158
 
  159
+    this.bind("focus", function(){
  160
+      jQuery(id + "lfocus").blink();
  161
+    }).bind("blur", function(){
  162
+      jQuery(id + "lblur").blink();
  163
+    });
  164
+
139 165
     return this.bind("change", function(e){
140 166
       jQuery(id + "bind").blink();
141 167
     }).live("change", function(e){
... ...
@@ -163,7 +189,23 @@
163 189
       next();
164 190
        });
165 191
   };
  192
+
  193
+  $(document).bind("focusin", function() {
  194
+    jQuery("#boundFocus").blink();
  195
+  });
166 196
   
  197
+  $(document).bind("focusout", function() {
  198
+    jQuery("#boundBlur").blink();
  199
+  });
  200
+
  201
+  $("td.red").live("hover", function(e) {
  202
+    if ( e.type === "mouseenter" ) {
  203
+      $(this).css("backgroundColor","green");
  204
+    } else {
  205
+      $(this).css("backgroundColor","");
  206
+    }
  207
+  });
  208
+
167 209
   $(".select_test").addChangeTest("#select");
168 210
   $(".mselect_test").addChangeTest("#mselect");
169 211
   $(".checkbox_test").addChangeTest("#checkbox");
Txt test/unit/event.js
  • View file @ 01f7202
... ...
@@ -864,6 +864,20 @@ test(".live()/.die()", function() {
864 864
   jQuery("#nothiddendiv div").die("click");
865 865
 });
866 866
 
  867
+test("live with multiple events", function(){
  868
+  expect(1);
  869
+
  870
+  var count = 0;
  871
+  var div = jQuery("div#nothiddendivchild")
  872
+
  873
+  div.live("click submit", function(){ count++; });
  874
+
  875
+  div.trigger("click");
  876
+  div.trigger("submit");
  877
+
  878
+  equals( count, 2, "Make sure both the click and submit were triggered." );
  879
+});
  880
+
867 881
 test("live with change", function(){
868 882
   var selectChange = 0, checkboxChange = 0;
869 883
   

0 notes on commit 01f7202

Please log in to comment.
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