forked from BorisMoore/jsviews
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.bindall.js
26 lines (26 loc) · 1.02 KB
/
jquery.bindall.js
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
/*! jQuery BindAll see: http://github.com/BorisMoore/jsviews */
/*
* jQuery BindAll proposal, used in https://github.com/BorisMoore/jquery-ui/blob/grid/grid-spf-observable/grid-edit-tracker.html
*/
(function ( $, undefined ) {
$.fn.bindAll = function bindAll( type, fn ) {
// Bind a handler for multiple events on different objects,
// or on multiple calls to single event such as grouped propertyChange events.
// type is a single type, or, for case of different event types on each object, an array
// Example: $([ grid, dataview ]).bindAll( "afterChange", function( gridEventData, dataviewEventData ) { ... })
var timeout,
argArray = [],
typeArray = $.isArray( type );
function callHandler() {
fn.apply( this, argArray );
argArray = [];
timeout = undefined
}
this.each( function( index ) {
$( this ).bind( typeArray ? type[index] : type, function(){
timeout = timeout || setTimeout( callHandler, 0 );
( argArray[ index ] = argArray[ index ] || [] ).push( arguments );
});
});
};
})(jQuery);