forked from bitovi/jquerypp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreverse.js
More file actions
91 lines (79 loc) · 2.34 KB
/
reverse.js
File metadata and controls
91 lines (79 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
steal('jquery', function($) {
$.event.reverse = function(name, attributes) {
var bound = $(),
count = 0,
dispatch = $.event.handle || $.event.dispatch;
$.event.special[name] = {
setup: function() {
// add and sort the resizers array
// don't add window because it can't be compared easily
if ( this !== window ) {
bound.push(this);
$.unique(bound);
}
// returns false if the window
return this !== window;
},
teardown: function() {
// we shouldn't have to sort
bound = bound.not(this);
// returns false if the window
return this !== window;
},
add: function( handleObj ) {
var origHandler = handleObj.handler;
handleObj.origHandler = origHandler;
handleObj.handler = function( ev, data ) {
var isWindow = this === window;
if(attributes && attributes.handler) {
var result = attributes.handler.apply(this, arguments);
if(result === true) {
return;
}
}
// if this is the first handler for this event ...
if ( count === 0 ) {
// prevent others from doing what we are about to do
count++;
var where = data === false ? ev.target : this
// trigger all this element's handlers
dispatch.call(where, ev, data);
if ( ev.isPropagationStopped() ) {
count--;
return;
}
// get all other elements within this element that listen to move
// and trigger their resize events
var index = bound.index(this),
length = bound.length,
child, sub;
// if index == -1 it's the window
while (++index < length && (child = bound[index]) && (isWindow || $.contains(where, child)) ) {
// call the event
dispatch.call(child, ev, data);
if ( ev.isPropagationStopped() ) {
// move index until the item is not in the current child
while (++index < length && (sub = bound[index]) ) {
if (!$.contains(child, sub) ) {
// set index back one
index--;
break
}
}
}
}
// prevent others from responding
ev.stopImmediatePropagation();
count--;
} else {
handleObj.origHandler.call(this, ev, data);
}
}
}
};
// automatically bind on these
$([document, window]).bind(name, function() {});
return $.event.special[name];
}
return $;
})