3 * Copyright(c) 2006-2010 Ext JS, Inc.
5 * http://www.extjs.com/license
8 * @class Ext.dd.Registry
9 * Provides easy access to all drag drop components that are registered on a page. Items can be retrieved either
10 * directly by DOM node id, or by passing in the drag drop event that occurred and looking up the event target.
13 Ext.dd.Registry = function(){
18 var getId = function(el, autogen){
19 if(typeof el == "string"){
23 if(!id && autogen !== false){
24 id = "extdd-" + (++autoIdSeed);
32 * Resgister a drag drop element
33 * @param {String/HTMLElement} element The id or DOM node to register
34 * @param {Object} data (optional) An custom data object that will be passed between the elements that are involved
35 * in drag drop operations. You can populate this object with any arbitrary properties that your own code
36 * knows how to interpret, plus there are some specific properties known to the Registry that should be
37 * populated in the data object (if applicable):
39 Value Description<br />
40 --------- ------------------------------------------<br />
41 handles Array of DOM nodes that trigger dragging<br />
42 for the element being registered<br />
43 isHandle True if the element passed in triggers<br />
44 dragging itself, else false
47 register : function(el, data){
49 if(typeof el == "string"){
50 el = document.getElementById(el);
53 elements[getId(el)] = data;
54 if(data.isHandle !== false){
55 handles[data.ddel.id] = data;
58 var hs = data.handles;
59 for(var i = 0, len = hs.length; i < len; i++){
60 handles[getId(hs[i])] = data;
66 * Unregister a drag drop element
67 * @param {String/HTMLElement} element The id or DOM node to unregister
69 unregister : function(el){
70 var id = getId(el, false);
71 var data = elements[id];
75 var hs = data.handles;
76 for(var i = 0, len = hs.length; i < len; i++){
77 delete handles[getId(hs[i], false)];
84 * Returns the handle registered for a DOM Node by id
85 * @param {String/HTMLElement} id The DOM node or id to look up
86 * @return {Object} handle The custom handle data
88 getHandle : function(id){
89 if(typeof id != "string"){ // must be element?
96 * Returns the handle that is registered for the DOM node that is the target of the event
97 * @param {Event} e The event
98 * @return {Object} handle The custom handle data
100 getHandleFromEvent : function(e){
101 var t = Ext.lib.Event.getTarget(e);
102 return t ? handles[t.id] : null;
106 * Returns a custom data object that is registered for a DOM node by id
107 * @param {String/HTMLElement} id The DOM node or id to look up
108 * @return {Object} data The custom data
110 getTarget : function(id){
111 if(typeof id != "string"){ // must be element?
118 * Returns a custom data object that is registered for the DOM node that is the target of the event
119 * @param {Event} e The event
120 * @return {Object} data The custom data
122 getTargetFromEvent : function(e){
123 var t = Ext.lib.Event.getTarget(e);
124 return t ? elements[t.id] || handles[t.id] : null;