3 <title>The source code</title>
\r
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
7 <body onload="prettyPrint();">
\r
8 <pre class="prettyprint lang-js"><div id="cls-Ext.dd.Registry"></div>/**
\r
9 * @class Ext.dd.Registry
\r
10 * Provides easy access to all drag drop components that are registered on a page. Items can be retrieved either
\r
11 * directly by DOM node id, or by passing in the drag drop event that occurred and looking up the event target.
\r
14 Ext.dd.Registry = function(){
\r
19 var getId = function(el, autogen){
\r
20 if(typeof el == "string"){
\r
24 if(!id && autogen !== false){
\r
25 id = "extdd-" + (++autoIdSeed);
\r
32 <div id="method-Ext.dd.Registry-register"></div>/**
\r
33 * Resgister a drag drop element
\r
34 * @param {String/HTMLElement) element The id or DOM node to register
\r
35 * @param {Object} data (optional) An custom data object that will be passed between the elements that are involved
\r
36 * in drag drop operations. You can populate this object with any arbitrary properties that your own code
\r
37 * knows how to interpret, plus there are some specific properties known to the Registry that should be
\r
38 * populated in the data object (if applicable):
\r
40 Value Description<br />
\r
41 --------- ------------------------------------------<br />
\r
42 handles Array of DOM nodes that trigger dragging<br />
\r
43 for the element being registered<br />
\r
44 isHandle True if the element passed in triggers<br />
\r
45 dragging itself, else false
\r
48 register : function(el, data){
\r
50 if(typeof el == "string"){
\r
51 el = document.getElementById(el);
\r
54 elements[getId(el)] = data;
\r
55 if(data.isHandle !== false){
\r
56 handles[data.ddel.id] = data;
\r
59 var hs = data.handles;
\r
60 for(var i = 0, len = hs.length; i < len; i++){
\r
61 handles[getId(hs[i])] = data;
\r
66 <div id="method-Ext.dd.Registry-unregister"></div>/**
\r
67 * Unregister a drag drop element
\r
68 * @param {String/HTMLElement) element The id or DOM node to unregister
\r
70 unregister : function(el){
\r
71 var id = getId(el, false);
\r
72 var data = elements[id];
\r
74 delete elements[id];
\r
76 var hs = data.handles;
\r
77 for(var i = 0, len = hs.length; i < len; i++){
\r
78 delete handles[getId(hs[i], false)];
\r
84 <div id="method-Ext.dd.Registry-getHandle"></div>/**
\r
85 * Returns the handle registered for a DOM Node by id
\r
86 * @param {String/HTMLElement} id The DOM node or id to look up
\r
87 * @return {Object} handle The custom handle data
\r
89 getHandle : function(id){
\r
90 if(typeof id != "string"){ // must be element?
\r
96 <div id="method-Ext.dd.Registry-getHandleFromEvent"></div>/**
\r
97 * Returns the handle that is registered for the DOM node that is the target of the event
\r
98 * @param {Event} e The event
\r
99 * @return {Object} handle The custom handle data
\r
101 getHandleFromEvent : function(e){
\r
102 var t = Ext.lib.Event.getTarget(e);
\r
103 return t ? handles[t.id] : null;
\r
106 <div id="method-Ext.dd.Registry-getTarget"></div>/**
\r
107 * Returns a custom data object that is registered for a DOM node by id
\r
108 * @param {String/HTMLElement} id The DOM node or id to look up
\r
109 * @return {Object} data The custom data
\r
111 getTarget : function(id){
\r
112 if(typeof id != "string"){ // must be element?
\r
115 return elements[id];
\r
118 <div id="method-Ext.dd.Registry-getTargetFromEvent"></div>/**
\r
119 * Returns a custom data object that is registered for the DOM node that is the target of the event
\r
120 * @param {Event} e The event
\r
121 * @return {Object} data The custom data
\r
123 getTargetFromEvent : function(e){
\r
124 var t = Ext.lib.Event.getTarget(e);
\r
125 return t ? elements[t.id] || handles[t.id] : null;
\r