4 * Copyright(c) 2006-2007, Ext JS, LLC.
6 * Originally Released Under LGPL - original licence link has changed is not relivant.
9 * <script type="text/javascript">
14 * @class Roo.dd.Registry
15 * Provides easy access to all drag drop components that are registered on a page. Items can be retrieved either
16 * directly by DOM node id, or by passing in the drag drop event that occurred and looking up the event target.
19 Roo.dd.Registry = function(){
24 var getId = function(el, autogen){
25 if(typeof el == "string"){
29 if(!id && autogen !== false){
30 id = "roodd-" + (++autoIdSeed);
38 * Register a drag drop element
39 * @param {String|HTMLElement} element The id or DOM node to register
40 * @param {Object} data (optional) A custom data object that will be passed between the elements that are involved
41 * in drag drop operations. You can populate this object with any arbitrary properties that your own code
42 * knows how to interpret, plus there are some specific properties known to the Registry that should be
43 * populated in the data object (if applicable):
45 Value Description<br />
46 --------- ------------------------------------------<br />
47 handles Array of DOM nodes that trigger dragging<br />
48 for the element being registered<br />
49 isHandle True if the element passed in triggers<br />
50 dragging itself, else false
53 register : function(el, data){
55 if(typeof el == "string"){
56 el = document.getElementById(el);
59 elements[getId(el)] = data;
60 if(data.isHandle !== false){
61 handles[data.ddel.id] = data;
64 var hs = data.handles;
65 for(var i = 0, len = hs.length; i < len; i++){
66 handles[getId(hs[i])] = data;
72 * Unregister a drag drop element
73 * @param {String|HTMLElement} element The id or DOM node to unregister
75 unregister : function(el){
76 var id = getId(el, false);
77 var data = elements[id];
81 var hs = data.handles;
82 for(var i = 0, len = hs.length; i < len; i++){
83 delete handles[getId(hs[i], false)];
90 * Returns the handle registered for a DOM Node by id
91 * @param {String|HTMLElement} id The DOM node or id to look up
92 * @return {Object} handle The custom handle data
94 getHandle : function(id){
95 if(typeof id != "string"){ // must be element?
102 * Returns the handle that is registered for the DOM node that is the target of the event
103 * @param {Event} e The event
104 * @return {Object} handle The custom handle data
106 getHandleFromEvent : function(e){
107 var t = Roo.lib.Event.getTarget(e);
108 return t ? handles[t.id] : null;
112 * Returns a custom data object that is registered for a DOM node by id
113 * @param {String|HTMLElement} id The DOM node or id to look up
114 * @return {Object} data The custom data
116 getTarget : function(id){
117 if(typeof id != "string"){ // must be element?
124 * Returns a custom data object that is registered for the DOM node that is the target of the event
125 * @param {Event} e The event
126 * @return {Object} data The custom data
128 getTargetFromEvent : function(e){
129 var t = Roo.lib.Event.getTarget(e);
130 return t ? elements[t.id] || handles[t.id] : null;