]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/javascript/yui/ygDDList.js
Release 6.4.0
[Github/sugarcrm.git] / include / javascript / yui / ygDDList.js
1
2 /* Copyright (c) 2006 Yahoo! Inc. All rights reserved. */
3
4 /**
5  * @class a YAHOO.util.DDProxy implementation. During the drag over event, the
6  * dragged element is inserted before the dragged-over element.
7  *
8  * @extends YAHOO.util.DDProxy
9  * @constructor
10  * @param {String} id the id of the linked element
11  * @param {String} sGroup the group of related DragDrop objects
12  */
13 function ygDDList(id, sGroup) {
14
15         if (id) {
16                 this.init(id, sGroup);
17                 this.initFrame();
18         }
19
20         var s = this.getDragEl().style;
21         s.borderColor = "transparent";
22         s.backgroundColor = "#f6f5e5";
23         s.opacity = 0.76;
24         s.filter = "alpha(opacity=76)";
25 }
26
27 ygDDList.prototype = new YAHOO.util.DDProxy();
28
29 ygDDList.prototype.borderDiv = null;
30 ygDDList.prototype.originalDisplayProperties = Array();
31
32 ygDDList.prototype.startDrag = function(x, y) {
33         //this.logger.debug(this.id + " startDrag");
34
35         var dragEl = this.getDragEl();
36         var clickEl = this.getEl();
37
38         dragEl.innerHTML = clickEl.innerHTML;
39         dragElObjects = dragEl.getElementsByTagName('object');
40
41         
42         dragEl.className = clickEl.className;
43         dragEl.style.color = clickEl.style.color;
44         dragEl.style.border = "1px solid #aaa";
45
46         // save the style of the object 
47         clickElRegion = YAHOO.util.Dom.getRegion(clickEl);
48         
49         this.borderDiv = document.createElement('div'); // create a div to display border
50         this.borderDiv.style.height = (clickElRegion.bottom - clickElRegion.top) + 'px';
51         this.borderDiv.style.border = '2px dashed #cccccc';
52         
53         for(i in clickEl.childNodes) { // hide contents of the target elements contents
54                 if(typeof clickEl.childNodes[i].style != 'undefined') {
55                         this.originalDisplayProperties[i] = clickEl.childNodes[i].style.display;
56                         clickEl.childNodes[i].style.display = 'none';
57                 }
58
59         }
60         clickEl.appendChild(this.borderDiv);
61 };
62
63 ygDDList.prototype.endDrag = function(e) {
64         // disable moving the linked element
65         var clickEl = this.getEl();
66
67         clickEl.removeChild(this.borderDiv); // remove border div
68         
69         for(i in clickEl.childNodes) { // show target elements contents
70                 if(typeof clickEl.childNodes[i].style != 'undefined') {
71                         clickEl.childNodes[i].style.display = this.originalDisplayProperties[i];
72                 }
73         }
74         
75         if(this.clickHeight) 
76             clickEl.style.height = this.clickHeight;
77         else 
78                 clickEl.style.height = '';
79         
80         if(this.clickBorder) 
81             clickEl.style.border = this.clickBorder;
82         else 
83                 clickEl.style.border = '';
84                 
85         dragEl = this.getDragEl();
86         dragEl.innerHTML = '';
87
88         this.afterEndDrag(e);
89 };
90
91 ygDDList.prototype.afterEndDrag = function(e) {
92
93 }
94
95 ygDDList.prototype.onDrag = function(e, id) {
96     
97 };
98
99 ygDDList.prototype.onDragOver = function(e, id) {
100         // this.logger.debug(this.id.toString() + " onDragOver " + id);
101         var el;
102         
103     if ("string" == typeof id) {
104         el = YAHOO.util.DDM.getElement(id);
105     } else { 
106         el = YAHOO.util.DDM.getBestMatch(id).getEl();
107     }
108     
109         dragEl = this.getDragEl();
110         elRegion = YAHOO.util.Dom.getRegion(el);
111             
112 //    this.logger.debug('id: ' + el.id);
113 //    this.logger.debug('size: ' + (elRegion.bottom - elRegion.top));
114 //    this.logger.debug('getPosY: ' + YAHOO.util.DDM.getPosY(el));
115         var mid = YAHOO.util.DDM.getPosY(el) + (Math.floor((elRegion.bottom - elRegion.top) / 2));
116 //    this.logger.debug('mid: ' + mid);
117         
118 //    this.logger.debug(YAHOO.util.DDM.getPosY(dragEl) + " <  " + mid);
119 //    this.logger.debug("Y: " + YAHOO.util.Event.getPageY(e));
120         
121         if (YAHOO.util.DDM.getPosY(dragEl) < mid ) { // insert on top triggering item
122                 var el2 = this.getEl();
123                 var p = el.parentNode;
124                 p.insertBefore(el2, el);
125         }
126         if (YAHOO.util.DDM.getPosY(dragEl) >= mid ) { // insert below triggered item
127                 var el2 = this.getEl();
128                 var p = el.parentNode;
129                 p.insertBefore(el2, el.nextSibling);
130         }
131 };
132
133 ygDDList.prototype.onDragEnter = function(e, id) {
134         // this.logger.debug(this.id.toString() + " onDragEnter " + id);
135         // this.getDragEl().style.border = "1px solid #449629";
136 };
137
138 ygDDList.prototype.onDragOut = function(e, id) {
139     // I need to know when we are over nothing
140         // this.getDragEl().style.border = "1px solid #964428";
141 }
142
143 /////////////////////////////////////////////////////////////////////////////
144
145 function ygDDListBoundary(id, sGroup) {
146         if (id) {
147                 this.init(id, sGroup);
148                 //this.logger = new ygLogger("ygDDListBoundary");
149                 this.isBoundary = true;
150         }
151 }
152
153 ygDDListBoundary.prototype = new YAHOO.util.DDTarget();