2 /* Copyright (c) 2006 Yahoo! Inc. All rights reserved. */
5 * @class a YAHOO.util.DDProxy implementation. During the drag over event, the
6 * dragged element is inserted before the dragged-over element.
8 * @extends YAHOO.util.DDProxy
10 * @param {String} id the id of the linked element
11 * @param {String} sGroup the group of related DragDrop objects
13 function ygDDList(id, sGroup) {
16 this.init(id, sGroup);
20 var s = this.getDragEl().style;
21 s.borderColor = "transparent";
22 s.backgroundColor = "#f6f5e5";
24 s.filter = "alpha(opacity=76)";
27 ygDDList.prototype = new YAHOO.util.DDProxy();
29 ygDDList.prototype.borderDiv = null;
30 ygDDList.prototype.originalDisplayProperties = Array();
32 // Bug #47097 : Dashlets not displayed after moving them
33 ygDDList.prototype.dashletID = null;
34 ygDDList.prototype.needsReloadAfterDrop = false;
36 ygDDList.prototype.startDrag = function(x, y) {
37 //this.logger.debug(this.id + " startDrag");
39 var dragEl = this.getDragEl();
40 var clickEl = this.getEl();
42 // Bug #47097 : Dashlets not displayed after moving them
43 this.needsReloadAfterDrop = false;
44 var chartContainer = YAHOO.util.Dom.getElementsByClassName('chartContainer', 'div', clickEl);
45 if ( chartContainer.length != 0 ) {
46 // try to find OBJECT tab in canvas if success - SWF used and it needs to be reloaded
47 var cee_canvas = YAHOO.util.Dom.get(this.dashletID+'-canvas');
48 if ( typeof cee_canvas != 'undefined' && cee_canvas ) {
49 // if there is object tag
50 var canvas_objects = YAHOO.util.Dom.getElementsBy(function(el){ return true;}, 'OBJECT', cee_canvas);
51 if ( canvas_objects.length != 0 ) {
52 this.needsReloadAfterDrop = true;
55 chartContainer.innerHTML = '';
58 dragEl.innerHTML = clickEl.innerHTML;
59 dragElObjects = dragEl.getElementsByTagName('object');
62 dragEl.className = clickEl.className;
63 dragEl.style.color = clickEl.style.color;
64 dragEl.style.border = "1px solid #aaa";
66 // save the style of the object
67 clickElRegion = YAHOO.util.Dom.getRegion(clickEl);
69 this.borderDiv = document.createElement('div'); // create a div to display border
70 this.borderDiv.style.height = (clickElRegion.bottom - clickElRegion.top) + 'px';
71 this.borderDiv.style.border = '2px dashed #cccccc';
73 for(i in clickEl.childNodes) { // hide contents of the target elements contents
74 if(typeof clickEl.childNodes[i].style != 'undefined') {
75 this.originalDisplayProperties[i] = clickEl.childNodes[i].style.display;
76 clickEl.childNodes[i].style.display = 'none';
80 clickEl.appendChild(this.borderDiv);
83 ygDDList.prototype.endDrag = function(e) {
84 // disable moving the linked element
85 var clickEl = this.getEl();
87 clickEl.removeChild(this.borderDiv); // remove border div
89 for(i in clickEl.childNodes) { // show target elements contents
90 if(typeof clickEl.childNodes[i].style != 'undefined') {
91 clickEl.childNodes[i].style.display = this.originalDisplayProperties[i];
96 clickEl.style.height = this.clickHeight;
98 clickEl.style.height = '';
101 clickEl.style.border = this.clickBorder;
103 clickEl.style.border = '';
105 dragEl = this.getDragEl();
106 dragEl.innerHTML = '';
108 this.afterEndDrag(e);
110 // Bug #47097 : Dashlets not displayed after moving them
111 if ( this.needsReloadAfterDrop && this.dashletID ) {
112 SUGAR.mySugar.retrieveDashlet(this.dashletID); //"predefined_chart"
116 ygDDList.prototype.afterEndDrag = function(e) {
120 ygDDList.prototype.onDrag = function(e, id) {
124 ygDDList.prototype.onDragOver = function(e, id) {
125 // this.logger.debug(this.id.toString() + " onDragOver " + id);
128 if ("string" == typeof id) {
129 el = YAHOO.util.DDM.getElement(id);
131 el = YAHOO.util.DDM.getBestMatch(id).getEl();
134 dragEl = this.getDragEl();
135 elRegion = YAHOO.util.Dom.getRegion(el);
137 // this.logger.debug('id: ' + el.id);
138 // this.logger.debug('size: ' + (elRegion.bottom - elRegion.top));
139 // this.logger.debug('getPosY: ' + YAHOO.util.DDM.getPosY(el));
140 var mid = YAHOO.util.DDM.getPosY(el) + (Math.floor((elRegion.bottom - elRegion.top) / 2));
141 // this.logger.debug('mid: ' + mid);
143 // this.logger.debug(YAHOO.util.DDM.getPosY(dragEl) + " < " + mid);
144 // this.logger.debug("Y: " + YAHOO.util.Event.getPageY(e));
146 if (YAHOO.util.DDM.getPosY(dragEl) < mid ) { // insert on top triggering item
147 var el2 = this.getEl();
148 var p = el.parentNode;
149 p.insertBefore(el2, el);
151 if (YAHOO.util.DDM.getPosY(dragEl) >= mid ) { // insert below triggered item
152 var el2 = this.getEl();
153 var p = el.parentNode;
154 p.insertBefore(el2, el.nextSibling);
158 ygDDList.prototype.onDragEnter = function(e, id) {
159 // this.logger.debug(this.id.toString() + " onDragEnter " + id);
160 // this.getDragEl().style.border = "1px solid #449629";
163 ygDDList.prototype.onDragOut = function(e, id) {
164 // I need to know when we are over nothing
165 // this.getDragEl().style.border = "1px solid #964428";
168 /////////////////////////////////////////////////////////////////////////////
170 function ygDDListBoundary(id, sGroup) {
172 this.init(id, sGroup);
173 //this.logger = new ygLogger("ygDDListBoundary");
174 this.isBoundary = true;
178 ygDDListBoundary.prototype = new YAHOO.util.DDTarget();