From: fschulze <svn...@pl...> - 2006-03-05 23:12:37
|
Author: fschulze Date: Sun Mar 5 23:11:32 2006 New Revision: 9275 Modified: CMFPlone/branches/fschulze-dragdropreordering/skins/plone_ecmascript/dragdropreorder.js Log: Make it work in IE. Modified: CMFPlone/branches/fschulze-dragdropreordering/skins/plone_ecmascript/dragdropreorder.js ============================================================================== --- CMFPlone/branches/fschulze-dragdropreordering/skins/plone_ecmascript/dragdropreorder.js (original) +++ CMFPlone/branches/fschulze-dragdropreordering/skins/plone_ecmascript/dragdropreorder.js Sun Mar 5 23:11:32 2006 @@ -1,31 +1,31 @@ -// no IE support yet. it shouldn't be hard to add, but it will make the -// code harder to understand. - var ploneDnDReorder = {} ploneDnDReorder.dragging = null; ploneDnDReorder.table = null; +ploneDnDReorder.rows = null; ploneDnDReorder.isDraggable = function(node) { return hasClassName(node, 'draggable'); }; ploneDnDReorder.doDown = function(e) { - ploneDnDReorder.table.onmousemove = ploneDnDReorder.doDrag; - var target = findContainer(e.target, ploneDnDReorder.isDraggable); + if (!e) var e = window.event; // IE compatibility + var target = this;//findContainer(e.target, ploneDnDReorder.isDraggable); if (target == null) return; + for (var i=0; i<ploneDnDReorder.rows.length; i++) + ploneDnDReorder.rows[i].onmousemove = ploneDnDReorder.doDrag; ploneDnDReorder.dragging = target; ploneDnDReorder.dragging._position = ploneDnDReorder.getPos(ploneDnDReorder.dragging); addClassName(ploneDnDReorder.dragging, "dragging"); return false; } -ploneDnDReorder.getPos = function(e) { - var children = e.parentNode.childNodes; +ploneDnDReorder.getPos = function(node) { + var children = node.parentNode.childNodes; var pos = 0; for (var i=0; i<children.length; i++) { - if (e == children[i]) + if (node == children[i]) return pos; if (hasClassName(children[i], "draggable")) pos++; @@ -34,9 +34,10 @@ } ploneDnDReorder.doDrag = function(e) { + if (!e) var e = window.event; // IE compatibility if (!ploneDnDReorder.dragging) return; - var target = findContainer(e.target, ploneDnDReorder.isDraggable); + var target = this;//findContainer(e.target, ploneDnDReorder.isDraggable); if (!target) return; if (target.id != ploneDnDReorder.dragging.id) { @@ -68,13 +69,15 @@ } ploneDnDReorder.doUp = function(e) { + if (!e) var e = window.event; // IE compatibility if (!ploneDnDReorder.dragging) return; removeClassName(ploneDnDReorder.dragging, "dragging"); ploneDnDReorder.updatePositionOnServer(); ploneDnDReorder.dragging._position = null; ploneDnDReorder.dragging = null; - ploneDnDReorder.table.onmousemove = null; + for (var i=0; i<ploneDnDReorder.rows.length; i++) + ploneDnDReorder.rows[i].onmousemove = null; return false; } @@ -91,8 +94,11 @@ ploneDnDReorder.table = cssQuery("table#sortable")[0]; if (!ploneDnDReorder.table) return; - ploneDnDReorder.table.onmousedown=ploneDnDReorder.doDown; - ploneDnDReorder.table.onmouseup=ploneDnDReorder.doUp; + ploneDnDReorder.rows = cssQuery("table#sortable tr"); + for (var i=0; i<ploneDnDReorder.rows.length; i++) { + ploneDnDReorder.rows[i].onmousedown=ploneDnDReorder.doDown; + ploneDnDReorder.rows[i].onmouseup=ploneDnDReorder.doUp; + } } registerPloneFunction(ploneDnDReorder.initializeDragDrop); |