[ Index ] |
|
Code source de vtiger CRM 5.0.2 |
1 /************************************************** 2 * dom-drag.js 3 * 09.25.2001 4 * www.youngpup.net 5 * Script featured on Dynamic Drive (http://www.dynamicdrive.com) 12.08.2005 6 ************************************************** 7 * 10.28.2001 - fixed minor bug where events 8 * sometimes fired off the handle, not the root. 9 **************************************************/ 10 11 var Drag = { 12 13 obj : null, 14 15 init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper) 16 { 17 o.onmousedown = Drag.start; 18 19 o.hmode = bSwapHorzRef ? false : true ; 20 o.vmode = bSwapVertRef ? false : true ; 21 22 o.root = oRoot && oRoot != null ? oRoot : o ; 23 24 if (o.hmode && isNaN(parseInt(o.root.style.left ))) o.root.style.left = "0px"; 25 if (o.vmode && isNaN(parseInt(o.root.style.top ))) o.root.style.top = "0px"; 26 if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right = "0px"; 27 if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px"; 28 29 o.minX = typeof minX != 'undefined' ? minX : null; 30 o.minY = typeof minY != 'undefined' ? minY : null; 31 o.maxX = typeof maxX != 'undefined' ? maxX : null; 32 o.maxY = typeof maxY != 'undefined' ? maxY : null; 33 34 o.xMapper = fXMapper ? fXMapper : null; 35 o.yMapper = fYMapper ? fYMapper : null; 36 37 o.root.onDragStart = new Function(); 38 o.root.onDragEnd = new Function(); 39 o.root.onDrag = new Function(); 40 }, 41 42 start : function(e) 43 { 44 var o = Drag.obj = this; 45 e = Drag.fixE(e); 46 var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom); 47 var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right ); 48 o.root.onDragStart(x, y); 49 50 o.lastMouseX = e.clientX; 51 o.lastMouseY = e.clientY; 52 53 if (o.hmode) { 54 if (o.minX != null) o.minMouseX = e.clientX - x + o.minX; 55 if (o.maxX != null) o.maxMouseX = o.minMouseX + o.maxX - o.minX; 56 } else { 57 if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x; 58 if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x; 59 } 60 61 if (o.vmode) { 62 if (o.minY != null) o.minMouseY = e.clientY - y + o.minY; 63 if (o.maxY != null) o.maxMouseY = o.minMouseY + o.maxY - o.minY; 64 } else { 65 if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y; 66 if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y; 67 } 68 69 document.onmousemove = Drag.drag; 70 document.onmouseup = Drag.end; 71 72 return false; 73 }, 74 75 drag : function(e) 76 { 77 e = Drag.fixE(e); 78 var o = Drag.obj; 79 80 var ey = e.clientY; 81 var ex = e.clientX; 82 var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom); 83 var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right ); 84 var nx, ny; 85 86 if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX); 87 if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX); 88 if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY); 89 if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY); 90 91 nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1)); 92 ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1)); 93 94 if (o.xMapper) nx = o.xMapper(y) 95 else if (o.yMapper) ny = o.yMapper(x) 96 97 Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px"; 98 Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px"; 99 Drag.obj.lastMouseX = ex; 100 Drag.obj.lastMouseY = ey; 101 102 Drag.obj.root.onDrag(nx, ny); 103 return false; 104 }, 105 106 end : function() 107 { 108 document.onmousemove = null; 109 document.onmouseup = null; 110 Drag.obj.root.onDragEnd( parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), 111 parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"])); 112 Drag.obj = null; 113 }, 114 115 fixE : function(e) 116 { 117 if (typeof e == 'undefined') e = window.event; 118 if (typeof e.layerX == 'undefined') e.layerX = e.offsetX; 119 if (typeof e.layerY == 'undefined') e.layerY = e.offsetY; 120 return e; 121 } 122 }; 123
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 10:22:19 2007 | par Balluche grâce à PHPXref 0.7 |