-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathjQuery.bindLast.js
More file actions
36 lines (29 loc) · 783 Bytes
/
Copy pathjQuery.bindLast.js
File metadata and controls
36 lines (29 loc) · 783 Bytes
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
;(function($) {
$.extend($.fn, {
bindLast: function(event, cbFunc){
return this.each(function(){
var highIndex = 1000000;
var eventData = event.split('.');
var eventName = eventData[0];
$(this).bind(event, cbFunc);
var events = $(this).data('events'),
ourIndex = false,
usedIndicies = {};
$.each(events[eventName], function(index, func){
if(func === cbFunc){
ourIndex = index;
}
usedIndicies[index] = 1;
});
if(ourIndex !== false){
while(usedIndicies[highIndex] == 1){
highIndex++;
}
events[eventName][highIndex] = events[eventName][ourIndex];
delete events[eventName][ourIndex]
$(this).data('events', events);
}
});
}
});
})(jQuery);