3 <title>The source code</title>
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
7 <body onload="prettyPrint();">
8 <pre class="prettyprint lang-js">/*!
10 * Copyright(c) 2006-2009 Ext JS, LLC
12 * http://www.extjs.com/license
14 <div id="cls-Ext.dd.Registry"></div>/**
\r
15 * @class Ext.dd.Registry
\r
16 * Provides easy access to all drag drop components that are registered on a page. Items can be retrieved either
\r
17 * directly by DOM node id, or by passing in the drag drop event that occurred and looking up the event target.
\r
20 Ext.dd.Registry = function(){
\r
25 var getId = function(el, autogen){
\r
26 if(typeof el == "string"){
\r
30 if(!id && autogen !== false){
\r
31 id = "extdd-" + (++autoIdSeed);
\r
38 <div id="method-Ext.dd.Registry-register"></div>/**
\r
39 * Resgister a drag drop element
\r
40 * @param {String/HTMLElement) element The id or DOM node to register
\r
41 * @param {Object} data (optional) An custom data object that will be passed between the elements that are involved
\r
42 * in drag drop operations. You can populate this object with any arbitrary properties that your own code
\r
43 * knows how to interpret, plus there are some specific properties known to the Registry that should be
\r
44 * populated in the data object (if applicable):
\r
46 Value Description<br />
\r
47 --------- ------------------------------------------<br />
\r
48 handles Array of DOM nodes that trigger dragging<br />
\r
49 for the element being registered<br />
\r
50 isHandle True if the element passed in triggers<br />
\r
51 dragging itself, else false
\r
54 register : function(el, data){
\r
56 if(typeof el == "string"){
\r
57 el = document.getElementById(el);
\r
60 elements[getId(el)] = data;
\r
61 if(data.isHandle !== false){
\r
62 handles[data.ddel.id] = data;
\r
65 var hs = data.handles;
\r
66 for(var i = 0, len = hs.length; i < len; i++){
\r
67 handles[getId(hs[i])] = data;
\r
72 <div id="method-Ext.dd.Registry-unregister"></div>/**
\r
73 * Unregister a drag drop element
\r
74 * @param {String/HTMLElement) element The id or DOM node to unregister
\r
76 unregister : function(el){
\r
77 var id = getId(el, false);
\r
78 var data = elements[id];
\r
80 delete elements[id];
\r
82 var hs = data.handles;
\r
83 for(var i = 0, len = hs.length; i < len; i++){
\r
84 delete handles[getId(hs[i], false)];
\r
90 <div id="method-Ext.dd.Registry-getHandle"></div>/**
\r
91 * Returns the handle registered for a DOM Node by id
\r
92 * @param {String/HTMLElement} id The DOM node or id to look up
\r
93 * @return {Object} handle The custom handle data
\r
95 getHandle : function(id){
\r
96 if(typeof id != "string"){ // must be element?
\r
102 <div id="method-Ext.dd.Registry-getHandleFromEvent"></div>/**
\r
103 * Returns the handle that is registered for the DOM node that is the target of the event
\r
104 * @param {Event} e The event
\r
105 * @return {Object} handle The custom handle data
\r
107 getHandleFromEvent : function(e){
\r
108 var t = Ext.lib.Event.getTarget(e);
\r
109 return t ? handles[t.id] : null;
\r
112 <div id="method-Ext.dd.Registry-getTarget"></div>/**
\r
113 * Returns a custom data object that is registered for a DOM node by id
\r
114 * @param {String/HTMLElement} id The DOM node or id to look up
\r
115 * @return {Object} data The custom data
\r
117 getTarget : function(id){
\r
118 if(typeof id != "string"){ // must be element?
\r
121 return elements[id];
\r
124 <div id="method-Ext.dd.Registry-getTargetFromEvent"></div>/**
\r
125 * Returns a custom data object that is registered for the DOM node that is the target of the event
\r
126 * @param {Event} e The event
\r
127 * @return {Object} data The custom data
\r
129 getTargetFromEvent : function(e){
\r
130 var t = Ext.lib.Event.getTarget(e);
\r
131 return t ? elements[t.id] || handles[t.id] : null;
\r