ICAL: add conflict handling
[citadel.git] / webcit / static / ctdldragdrop.js
index d7c435e1b488d089912ed958d79b366b3dbceec0..aefd398fe6b93d582e8eaf2fad43ea991bf41087 100644 (file)
@@ -1,18 +1,22 @@
-/** Because scriptaculous DnD sucks..
-    Written by Mathew McBride <matt@mcbridematt.dhs.org> / <matt@comalies>
-*/
+/** 
+ * Because scriptaculous DnD sucks..
+ * Written by Mathew McBride <matt@mcbridematt.dhs.org> / <matt@comalies>
+ * 
+ * Copyright 2009 The Citadel Team
+ * Licensed under the GPL V3
+ */
 var draggedElement = null;
 var currentDropTargets = null;
 var dropTarget = null;
 var dragAndDropElement = null;
-
+var oldSelectHandler = null;
 function mouseDownHandler(event) {
   var target = event.target;
   var actualTarget = target;
   if (target.nodeName.toLowerCase() == "td") {
     actualTarget = target.parentNode;
   }
-  if (!actualTarget.dropEnabled) {
+  if (!actualTarget.dropEnabled && actualTarget.getAttribute("citadel:dropenabled") == null) {
     return;
   }
   turnOffTextSelect();
@@ -37,8 +41,9 @@ function mouseUpHandler(event) {
 function mouseMoveHandler(event) {
   if (draggedElement != null) {
     if (dragAndDropElement == null) {
-    dragAndDropElement = draggedElement.ctdlDnDElement();
-    dragAndDropElement.setAttribute("class", "draganddrop");
+      var dragAndDropElementFunction = (draggedElement.ctdlDnDElement) ? draggedElement.ctdlDndElement : eval(draggedElement.getAttribute("citadel:dndelement"));
+      dragAndDropElement = dragAndDropElementFunction.call();
+    dragAndDropElement.className = "draganddrop";
     document.body.appendChild(dragAndDropElement);
     }
     var clientX = event.clientX+5;
@@ -58,21 +63,21 @@ function mouseMoveOut(event) {
     dropTarget = null;
   }
 }
-document.observe("dom:loaded", setupDragDrop);
 function setupDragDrop() {
-if (document.addEventListener != undefined) {
-     $(document.body).observe('mousedown', mouseDownHandler);
+  $(document.body).observe('mousedown', mouseDownHandler);
     $(document.body).observe('mouseup',mouseUpHandler);
     $(document.body).observe('mousemove',mouseMoveHandler);
     $(document.body).observe('mouseover', mouseMoveOver);
-    $(document.body).observe('mouseout', mouseMoveOut);
-    } 
+    $(document.body).observe('mouseout', mouseMoveOut); 
 }
 function turnOffTextSelect() {
   document.onmousedown = new Function("return false");
-document.onmouseup = new Function("return true");
+  document.onmouseup = new Function("return true");
+ oldSelectHandler = document.onselectstart;
+ document.onselectstart = function() { return false; };
 }
 function turnOnTextSelect() {
   document.onmousedown = null;
   document.onmouseup = null;
+  document.onselectstart = oldSelectHandler;
 }