Skip to content

Commit 72ae3ee

Browse files
author
Kael
committed
dom/event: add delegate event support; improve stablility of funtion overloading of .off() method; fix a bug when trying to dispatch a live event;
1 parent c4143d5 commit 72ae3ee

File tree

2 files changed

+18
-296
lines changed

2 files changed

+18
-296
lines changed

lib/event/live.js

Lines changed: 0 additions & 289 deletions
This file was deleted.

lib/neuron/dom/event.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ function dispatch(event, type){
119119
handlers = storage[type];
120120

121121
// avoid non-left-click bubbling in Firefox (#3861)
122+
// TODO:
122123
if (event.button && type === 'click' || !handlers || !handlers.length){
123124
return;
124125
}
@@ -142,9 +143,9 @@ function dispatch(event, type){
142143

143144
// delegate events needs element traversing which takes huge costs,
144145
// so check them first
145-
if(live){
146+
if(live && event){
146147
for(cur = event.target; cur && cur !== el; cur = cur.parentNode){
147-
for(i = 0; i <= live; i ++ ){
148+
for(i = 0; i < live; i ++ ){
148149
handler = handlers[i];
149150

150151
if(
@@ -155,15 +156,15 @@ function dispatch(event, type){
155156

156157
(!condition || condition.call(cur, event))
157158
){
158-
if(handler.fn.call(cur, event)){
159+
if(handler.fn.call(cur, event) === false){
159160
event.stop();
160161
};
161162
}
162163
}
163164
}
164165
}
165166

166-
for(i = live + 1, len = handlers.length; i < len; i ++){
167+
for(i = live, len = handlers.length; i < len; i ++){
167168
handler = handlers[i];
168169

169170
if(!condition || condition.call(self, event)){
@@ -285,7 +286,7 @@ function addDOMEvent(el, type, selector, fn){
285286
* .off(type, selector) -> remove all delegated events which match the selector
286287
* .off(type, selector, fn) -> remove a live event handler
287288
* .off(type, '**') -> remove all live <type> events
288-
* .off(type, '**', fn) -> remove all live <type> events
289+
* .off(type, '**', fn) -> remove all live <type> events
289290
290291
* .off(type-map) -> remove several events
291292
* .off(type-map, selector) -> remove several live events
@@ -429,6 +430,9 @@ function removeDOMEvent(el, type, selector, fn){
429430
selector === false || selector === STR_WILD_SELECTORS || selector === handler.selector
430431
)
431432

433+
// reduce handlers.live
434+
&& handlers.live --
435+
432436
|| !handler.selector && selector === undef
433437
)
434438
){
@@ -438,6 +442,7 @@ function removeDOMEvent(el, type, selector, fn){
438442

439443
if(!handlers.length){
440444
removeEvent(el, handlers.base, handlers.handle, handlers.capture);
445+
delete storage[type];
441446
}
442447
}
443448
};
@@ -637,11 +642,11 @@ event_storage._clean = function(id){
637642

638643
DOM.extend({
639644
on : overloadAddEventArguments,
640-
off : overloadRemoveEventArguments,
645+
off : overloadRemoveEventArguments //,
641646

642647
/**
643648
* fire an event
644-
*/
649+
645650
fire: function(type){
646651
var el = this,
647652
storage = getStorage(el);
@@ -652,6 +657,7 @@ DOM.extend({
652657
});
653658
}
654659
}
660+
*/
655661

656662
}, 'iterator');
657663

@@ -665,6 +671,11 @@ DOM.Events = Events;
665671
/**
666672
change log:
667673
674+
2012-08-04 Kael:
675+
- add delegate event support
676+
- improve stablility of funtion overloading of .off() method
677+
- fix a bug when trying to dispatch a live event
678+
668679
2012-05-02 Kael:
669680
- fix mousewheel event for firefox
670681

0 commit comments

Comments
 (0)