[Zope-CVS] CVS: Packages/PDLib - pdlib.js:1.3 pdstyles.css:1.2

Shane Hathaway shane at zope.com
Thu Sep 18 13:39:58 EDT 2003


Update of /cvs-repository/Packages/PDLib
In directory cvs.zope.org:/tmp/cvs-serv9284

Modified Files:
	pdlib.js pdstyles.css 
Log Message:
Made it possible for drop targets to define their own highlight functions.


=== Packages/PDLib/pdlib.js 1.2 => 1.3 ===
--- Packages/PDLib/pdlib.js:1.2	Tue Jul  1 11:42:43 2003
+++ Packages/PDLib/pdlib.js	Thu Sep 18 13:39:57 2003
@@ -39,7 +39,7 @@
 // See the documentation for descriptions.
 // All other names are subject to change in future revisions.
 
-var pd_library_version = '0.1';  // The pdlib version.  Avoid using this!
+var pd_library_version = '0.2';  // The pdlib version.  Avoid using this!
 var pd_open_context_menu = null; // The context menu node being displayed
 var pd_drag_event = null;        // A pd_DragEvent object while dragging
 var pd_selected_items = null;    // List of selected items
@@ -49,10 +49,6 @@
 var pd_max_contextmenu_width = 250; // Threshold for faulty browsers
 var pd_invisible_targets = [];   // A list of normally invisible drop targets
 
-var pd_target_normal_border = "2px solid transparent";
-var pd_target_highlighted_border = "2px dotted red";
-var pd_target_loading_border = "2px solid green";
-
 
 function pd_hasAncestor(node, ancestor) {
   var p = node;
@@ -77,6 +73,8 @@
 function pd_findEventTarget(e, className, stop_className) {
   // Search for a node of the given class among the ancestors of the
   // target of an event, stopping if stop_className is encountered.
+  // Note that elements with multiple classes are not supported by
+  // this function.
   var node = e.target || e.srcElement;
   while (node) {
     if (node.className == className)
@@ -94,6 +92,15 @@
   node.style.backgroundColor = enabled ? "Highlight" : "";
 }
 
+function pd_defaultHighlightTarget(node, state) {
+  if (state == 0)
+    node.style.border = "2px solid transparent";
+  else if (state == 1)
+    node.style.border = "2px dotted red";
+  else if (state == 2)
+    node.style.border = "2px solid green";
+}
+
 //
 // Context menu functions
 //
@@ -189,6 +196,7 @@
   this.target = null;
   this.move_func = move_func;
   this.checkmove_func = checkmove_func;
+  this.highlight_func = null;
   this.start_x = e.pageX ? e.pageX : e.clientX + document.body.scrollLeft;
   this.start_y = e.pageY ? e.pageY : e.clientY + document.body.scrollTop;
   this.feedback_node = document.getElementById("drag-feedback-box");
@@ -196,13 +204,6 @@
   this.revealed = [];
 }
 
-function pd_unhighlightDropTarget() {
-  if (pd_drag_event && pd_drag_event.target) {
-    pd_drag_event.target.style.border = pd_target_normal_border;
-    pd_drag_event.target = null;
-  }
-}
-
 function pd_allowDrop(target) {
   if (!pd_drag_event)
     return false;
@@ -220,11 +221,21 @@
   return true;
 }
 
-function pd_highlightDropTarget(target) {
+function pd_unhighlightTarget() {
+  if (pd_drag_event && pd_drag_event.target) {
+    pd_drag_event.highlight_func(pd_drag_event.target, 0);
+    pd_drag_event.target = null;
+  }
+}
+
+function pd_setHighlightedTarget(target, highlight_func) {
   if (pd_allowDrop(target)) {
-    pd_unhighlightDropTarget();
-    target.style.border = pd_target_highlighted_border;
+    pd_unhighlightTarget();
+    if (!highlight_func)
+      highlight_func = pd_defaultHighlightTarget;
+    highlight_func(target, 1);
     pd_drag_event.target = target;
+    pd_drag_event.highlight_func = highlight_func;
   }
 }
 
@@ -288,7 +299,8 @@
   pd_drag_event = null;
 
   if (ev.target) {
-    ev.target.style.border = pd_target_loading_border;
+    if (ev.highlight_func)
+      ev.highlight_func(ev.target, 2);
     if (ev.move_func)
       ev.move_func(pd_selected_items, ev.target);
   }
@@ -468,12 +480,14 @@
   mo.onselectstart = pd_stopEvent;  // IE: Don't start a selection.
 }
 
-function pd_setupContextMenu(mo, contextMenuId, box) {
+function pd_setupContextMenu(mo, contextMenuId, box, onclick) {
   // Adds context menu functionality to an element
   function oncontextmenu(e) {
     return pd_itemOnContextMenu(mo, e, contextMenuId, box);
   }
   mo.oncontextmenu = oncontextmenu;
+  if (onclick)
+    mo.onclick = oncontextmenu;
 }
 
 function pd_documentOnMouseDown() {
@@ -482,11 +496,14 @@
 }
 
 function pd_setupNodeAndDescendants(node) {
-  var i, f;
+  var i, f, names;
   if (node.className) {
-    f = pd_node_setup[node.className];
-    if (f)
-      f(node);
+    names = node.className.split(" ");
+    for (i = 0; i < names.length; i++) {
+      f = pd_node_setup[names[i]];
+      if (f)
+        f(node);
+    }
   }
   for (i = 0; i < node.childNodes.length; i++) {
     pd_setupNodeAndDescendants(node.childNodes[i]);
@@ -501,12 +518,12 @@
   pd_setupNodeAndDescendants(node);
 }
 
-function pd_setupDropTarget(node, selectable) {
+function pd_setupDropTarget(node, selectable, highlight_func) {
   function call_highlight() {
-    return pd_highlightDropTarget(node);
+    return pd_setHighlightedTarget(node, highlight_func);
   }
   node.onmouseover = call_highlight;
-  node.onmouseout = pd_unhighlightDropTarget;
+  node.onmouseout = pd_unhighlightTarget;
   if (!selectable)
     node.onmousedown = pd_stopEvent; // Prevent accidental selection
 }


=== Packages/PDLib/pdstyles.css 1.1.1.1 => 1.2 ===
--- Packages/PDLib/pdstyles.css:1.1.1.1	Mon Dec  2 16:36:34 2002
+++ Packages/PDLib/pdstyles.css	Thu Sep 18 13:39:57 2003
@@ -9,7 +9,7 @@
 
 .context-menu {
   position: absolute;
-  border: 1px outset;
+  border: 1px outset Menu;
   background-color: Menu;
   color: MenuText;
   cursor: default;
@@ -25,3 +25,6 @@
   padding-bottom: 2px;
 }
 
+.separator {
+  border: 1px inset Menu;
+}




More information about the Zope-CVS mailing list