3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
16 * @class Ext.dd.Registry
17 * Provides easy access to all drag drop components that are registered on a page. Items can be retrieved either
18 * directly by DOM node id, or by passing in the drag drop event that occurred and looking up the event target.
21 Ext.define('Ext.dd.Registry', {
23 constructor: function() {
29 getId: function(el, autogen){
30 if(typeof el == "string"){
34 if(!id && autogen !== false){
35 id = "extdd-" + (++this.autoIdSeed);
42 * Resgister a drag drop element
43 * @param {String/HTMLElement} element The id or DOM node to register
44 * @param {Object} data (optional) An custom data object that will be passed between the elements that are involved
45 * in drag drop operations. You can populate this object with any arbitrary properties that your own code
46 * knows how to interpret, plus there are some specific properties known to the Registry that should be
47 * populated in the data object (if applicable):
49 Value Description<br />
50 --------- ------------------------------------------<br />
51 handles Array of DOM nodes that trigger dragging<br />
52 for the element being registered<br />
53 isHandle True if the element passed in triggers<br />
54 dragging itself, else false
57 register : function(el, data){
59 if (typeof el == "string") {
60 el = document.getElementById(el);
63 this.elements[this.getId(el)] = data;
64 if (data.isHandle !== false) {
65 this.handles[data.ddel.id] = data;
68 var hs = data.handles;
69 for (var i = 0, len = hs.length; i < len; i++) {
70 this.handles[this.getId(hs[i])] = data;
76 * Unregister a drag drop element
77 * @param {String/HTMLElement} element The id or DOM node to unregister
79 unregister : function(el){
80 var id = this.getId(el, false);
81 var data = this.elements[id];
83 delete this.elements[id];
85 var hs = data.handles;
86 for (var i = 0, len = hs.length; i < len; i++) {
87 delete this.handles[this.getId(hs[i], false)];
94 * Returns the handle registered for a DOM Node by id
95 * @param {String/HTMLElement} id The DOM node or id to look up
96 * @return {Object} handle The custom handle data
98 getHandle : function(id){
99 if(typeof id != "string"){ // must be element?
102 return this.handles[id];
106 * Returns the handle that is registered for the DOM node that is the target of the event
107 * @param {Event} e The event
108 * @return {Object} handle The custom handle data
110 getHandleFromEvent : function(e){
111 var t = e.getTarget();
112 return t ? this.handles[t.id] : null;
116 * Returns a custom data object that is registered for a DOM node by id
117 * @param {String/HTMLElement} id The DOM node or id to look up
118 * @return {Object} data The custom data
120 getTarget : function(id){
121 if(typeof id != "string"){ // must be element?
124 return this.elements[id];
128 * Returns a custom data object that is registered for the DOM node that is the target of the event
129 * @param {Event} e The event
130 * @return {Object} data The custom data
132 getTargetFromEvent : function(e){
133 var t = e.getTarget();
134 return t ? this.elements[t.id] || this.handles[t.id] : null;