public
Fork of danwrong/low-pro-for-jquery
Description: A jQuery plugin version of the Low Pro behavior framework.
Homepage: http://lowprojs.org
Clone URL: git://github.com/sudara/low-pro-for-jquery.git
added delegate method for easy event delegation
danwrong (author)
Fri Feb 08 05:18:51 -0800 2008
commit  7c3dd5c36ce5b9a5d8e9d332d016e7f76eba95e6
tree    4813e3877c66585bb42c2c16ce15c908cde54123
parent  9028f49d7608ef3c488b69482b0ec1ad8aa9c399
...
76
77
78
 
 
 
 
 
 
 
79
80
81
...
76
77
78
79
80
81
82
83
84
85
86
87
88
0
@@ -76,6 +76,13 @@
0
       klass.prototype.constructor = klass;
0
 
0
       return klass;
0
+ },
0
+ delegate: function(rules) {
0
+ return function(e) {
0
+ var target = $(e.target);
0
+ for (var selector in rules)
0
+ if (target.is(selector)) return rules[selector].apply(this, $.makeArray(arguments));
0
+ }
0
     }
0
   });
0
   
...
28
29
30
 
31
32
33
34
35
 
 
 
 
36
37
38
39
 
40
41
 
42
43
44
...
52
53
54
 
 
 
 
 
 
55
56
...
28
29
30
31
32
 
 
 
 
33
34
35
36
37
38
39
 
40
41
 
42
43
44
45
...
53
54
55
56
57
58
59
60
61
62
63
0
@@ -28,17 +28,18 @@
0
    Clicky = $.klass({
0
    initialize: function(arg) {
0
    console.log('Ive been applied with arg: ' + arg);
0
+ this.arg = arg;
0
    },
0
- onclick: function() {
0
- console.log('clicked');
0
- console.log(this.element);
0
- }
0
+ onclick: $.delegate({
0
+ '#woo': function() { alert(this.arg) },
0
+ '#yeah': function() { console.log(this, arguments) }
0
+ })
0
    })
0
   
0
    jQuery(function($) {
0
- $('p').attach(Clicky, 56);
0
+ $('#thing').attach(Clicky, 56);
0
    $('a').attach(Remote);
0
- $('form').attach(Remote)
0
+ $('form').attach(Remote);
0
    });
0
   </script>
0
 </head>
0
@@ -52,5 +53,11 @@
0
   <input name="thing4545" />
0
   <input type='submit' name="boo" value="thing" />
0
   <input type='submit' name="boo2" value="thing2" />
0
+</form>
0
+
0
+<div id="thing">
0
+ <span id="yeah">Yeah</p>
0
+ <span id="woo">woo</span>
0
+</div>
0
 </body>
0
 </html>

Comments

    No one has commented yet.