public
Description: A jQuery plugin that provides method for copying events from one element to another.
Homepage: http://plugins.jquery.com/project/copyEvents
Clone URL: git://github.com/brandonaaron/copyevents.git
Click here to lend your support to: copyevents and make a donation at www.pledgie.com !
copyevents / jquery.copyEvents.js
100644 33 lines (27 sloc) 0.768 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
/*! Copyright (c) 2008 Brandon Aaron (http://brandonaaron.net)
* Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
* and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
*
* Version: 1.1.1-pre
*/
 
(function($) {
 
$.fn.extend({
copyEvents: function(from) {
$.event.copy( $(from), this );
return this;
},
 
copyEventsTo: function(to) {
$.event.copy( this, $(to) );
return this;
}
});
 
$.event.copy = function(from, to) {
var events = $.data(from[0], 'events');
if ( !from.size() || !events || !to.size() ) return;
 
to.each(function() {
for (var type in events)
for (var handler in events[type])
$.event.add(this, type, events[type][handler], events[type][handler].data);
});
};
 
})(jQuery);