source: extensions/EasyCaptcha/template/jquery.events/jquery.event.drop.live-2.2.js @ 24215

Last change on this file since 24215 was 24215, checked in by mistic100, 11 years ago

add extension EasyCaptcha

File size: 2.5 KB
Line 
1/*!
2 * jquery.event.drop.live - v 2.2
3 * Copyright (c) 2010 Three Dub Media - http://threedubmedia.com
4 * Open Source MIT License - http://threedubmedia.com/code/license
5 */
6// Created: 2010-06-07
7// Updated: 2012-05-21
8// REQUIRES: jquery 1.7.x, event.drag 2.2, event.drop 2.2
9
10;(function($){ // secure $ jQuery alias
11
12// local refs (increase compression)
13var $event = $.event,
14// ref the drop special event config
15drop = $event.special.drop,
16// old drop event add method
17origadd = drop.add,
18// old drop event teradown method
19origteardown = drop.teardown;
20
21// allow events to bubble for delegation
22drop.noBubble = false;
23
24// the namespace for internal live events
25drop.livekey = "livedrop";
26
27// new drop event add method
28drop.add = function( obj ){ 
29        // call the old method
30        origadd.apply( this, arguments );
31        // read the data
32        var data = $.data( this, drop.datakey );
33        // bind the live "dropinit" delegator
34        if ( !data.live && obj.selector ){
35                data.live = true;
36                $event.add( this, "dropinit."+ drop.livekey, drop.delegate );
37        }
38};
39
40// new drop event teardown method
41drop.teardown = function(){ 
42        // call the old method
43        origteardown.apply( this, arguments );
44        // read the data
45        var data = $.data( this, drop.datakey ) || {};
46        // remove the live "dropinit" delegator
47        if ( data.live ){
48                // remove the "live" delegation
49                $event.remove( this, "dropinit", drop.delegate );
50                data.live = false;
51        }
52};
53
54// identify potential delegate elements
55drop.delegate = function( event, dd ){
56        // local refs
57        var elems = [], $targets, 
58        // element event structure
59        events = $.data( this, "events" ) || {};
60        // query live events
61        $.each( events || [], function( key, arr ){
62                // no event type matches
63                if ( key.indexOf("drop") !== 0 )
64                        return;
65                $.each( arr, function( i, obj ){
66                        // locate the elements to delegate
67                        $targets = $( event.currentTarget ).find( obj.selector );
68                        // no element found
69                        if ( !$targets.length ) 
70                                return;
71                        // take each target...
72                        $targets.each(function(){
73                                // add an event handler
74                                $event.add( this, obj.origType +'.'+ drop.livekey, obj.origHandler || obj.handler, obj.data );
75                                // remember new elements
76                                if ( $.inArray( this, elems ) < 0 )
77                                        elems.push( this );     
78                        });     
79                });
80        });
81        // may not exist when artifically triggering dropinit event
82        if ( dd )
83                // clean-up after the interaction ends
84                $event.add( dd.drag, "dragend."+drop.livekey, function(){
85                        $.each( elems.concat( this ), function(){
86                                $event.remove( this, '.'+ drop.livekey );                                                       
87                        });
88                });
89        //drop.delegates.push( elems );
90        return elems.length ? $( elems ) : false;
91};
92
93})( jQuery );
Note: See TracBrowser for help on using the repository browser.