123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- /*
- * Ext JS Library 2.0 Copyright(c) 2006-2007, Ext JS, LLC. licensing@extjs.com
- *
- * http://extjs.com/license
- */
- /**
- * @class Ext.dd.Registry Provides easy access to all drag drop components that
- * are registered on a page. Items can be retrieved either directly by
- * DOM node id, or by passing in the drag drop event that occurred and
- * looking up the event target.
- * @singleton
- */
- Ext.dd.Registry = function() {
- var elements = {};
- var handles = {};
- var autoIdSeed = 0;
- var getId = function(el, autogen) {
- if (typeof el == "string") {
- return el;
- }
- var id = el.id;
- if (!id && autogen !== false) {
- id = "extdd-" + (++autoIdSeed);
- el.id = id;
- }
- return id;
- };
- return {
- /**
- * Resgister a drag drop element
- *
- * @param {String/HTMLElement)
- * element The id or DOM node to register
- * @param {Object}
- * data (optional) An custom data object that will be passed
- * between the elements that are involved in drag drop
- * operations. You can populate this object with any
- * arbitrary properties that your own code knows how to
- * interpret, plus there are some specific properties known
- * to the Registry that should be populated in the data
- * object (if applicable):
- *
- * <pre>
- * Value Description
- * <br />
- * --------- ------------------------------------------
- * <br />
- * handles Array of DOM nodes that trigger dragging
- * <br />
- * for the element being registered
- * <br />
- * isHandle
- * True if the element passed in triggers
- * <br />
- * dragging itself, else false
- *
- * </pre>
- */
- register : function(el, data) {
- data = data || {};
- if (typeof el == "string") {
- el = document.getElementById(el);
- }
- data.ddel = el;
- elements[getId(el)] = data;
- if (data.isHandle !== false) {
- handles[data.ddel.id] = data;
- }
- if (data.handles) {
- var hs = data.handles;
- for (var i = 0, len = hs.length; i < len; i++) {
- handles[getId(hs[i])] = data;
- }
- }
- },
- /**
- * Unregister a drag drop element
- *
- * @param {String/HTMLElement)
- * element The id or DOM node to unregister
- */
- unregister : function(el) {
- var id = getId(el, false);
- var data = elements[id];
- if (data) {
- delete elements[id];
- if (data.handles) {
- var hs = data.handles;
- for (var i = 0, len = hs.length; i < len; i++) {
- delete handles[getId(hs[i], false)];
- }
- }
- }
- },
- /**
- * Returns the handle registered for a DOM Node by id
- *
- * @param {String/HTMLElement}
- * id The DOM node or id to look up
- * @return {Object} handle The custom handle data
- */
- getHandle : function(id) {
- if (typeof id != "string") { // must be element?
- id = id.id;
- }
- return handles[id];
- },
- /**
- * Returns the handle that is registered for the DOM node that is the
- * target of the event
- *
- * @param {Event}
- * e The event
- * @return {Object} handle The custom handle data
- */
- getHandleFromEvent : function(e) {
- var t = Ext.lib.Event.getTarget(e);
- return t ? handles[t.id] : null;
- },
- /**
- * Returns a custom data object that is registered for a DOM node by id
- *
- * @param {String/HTMLElement}
- * id The DOM node or id to look up
- * @return {Object} data The custom data
- */
- getTarget : function(id) {
- if (typeof id != "string") { // must be element?
- id = id.id;
- }
- return elements[id];
- },
- /**
- * Returns a custom data object that is registered for the DOM node that
- * is the target of the event
- *
- * @param {Event}
- * e The event
- * @return {Object} data The custom data
- */
- getTargetFromEvent : function(e) {
- var t = Ext.lib.Event.getTarget(e);
- return t ? elements[t.id] || handles[t.id] : null;
- }
- };
- }();
|