1/************************************************** 2 * dom-drag.js 3 * 09.25.2001 4 * www.youngpup.net 5 ************************************************** 6 * 10.28.2001 - fixed minor bug where events 7 * sometimes fired off the handle, not the root. 8 ************************************************** 9 * IPS CHANGES 10 * 06.01.2005 - Added "cursorchange" to change 11 * 07.18.2005 - Added cookie to store values 12 * 07.18.2005 - Made it impossible to drag < 0 height (keeponscreen) 13 * mouse cursor when over drag handle 14 **************************************************/ 15 16 17var Drag = { 18 19 obj : null, 20 fx : null, 21 fy : null, 22 cookiename : null, 23 keeponscreen: true, 24 25 init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper) 26 { 27 o.onmousedown = Drag.start; 28 o.onmouseover = Drag.cursorchange; 29 30 o.hmode = bSwapHorzRef ? false : true ; 31 o.vmode = bSwapVertRef ? false : true ; 32 33 o.root = oRoot && oRoot != null ? oRoot : o ; 34 35 if (o.hmode && isNaN(parseInt(o.root.style.left ))) o.root.style.left = "0px"; 36 if (o.vmode && isNaN(parseInt(o.root.style.top ))) o.root.style.top = "0px"; 37 if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right = "0px"; 38 if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px"; 39 40 o.minX = typeof minX != 'undefined' ? minX : null; 41 o.minY = typeof minY != 'undefined' ? minY : null; 42 o.maxX = typeof maxX != 'undefined' ? maxX : null; 43 o.maxY = typeof maxY != 'undefined' ? maxY : null; 44 45 o.xMapper = fXMapper ? fXMapper : null; 46 o.yMapper = fYMapper ? fYMapper : null; 47 48 //---------------------------------- 49 // Figure width and height 50 //---------------------------------- 51 52 if ( Drag.keeponscreen ) 53 { 54 Drag.my_width = 0; 55 Drag.my_height = 0; 56 57 if ( typeof( window.innerWidth ) == 'number' ) 58 { 59 //---------------------------------- 60 // Non IE 61 //---------------------------------- 62 63 Drag.my_width = window.innerWidth; 64 Drag.my_height = window.innerHeight; 65 } 66 else if ( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 67 { 68 //---------------------------------- 69 // IE 6+ 70 //---------------------------------- 71 72 Drag.my_width = document.documentElement.clientWidth; 73 Drag.my_height = document.documentElement.clientHeight; 74 } 75 else if ( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 76 { 77 //---------------------------------- 78 // Old IE 79 //---------------------------------- 80 81 Drag.my_width = document.body.clientWidth; 82 Drag.my_height = document.body.clientHeight; 83 } 84 } 85 86 o.root.onDragStart = new Function(); 87 o.root.onDragEnd = new Function(); 88 o.root.onDrag = new Function(); 89 }, 90 91 cursorchange : function(e) 92 { 93 var o = Drag.obj = this; 94 o.style.cursor = 'move'; 95 }, 96 97 start : function(e) 98 { 99 var o = Drag.obj = this; 100 e = Drag.fixE(e); 101 var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom); 102 var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right ); 103 o.root.onDragStart(x, y); 104 105 o.lastMouseX = e.clientX; 106 o.lastMouseY = e.clientY; 107 108 if (o.hmode) { 109 if (o.minX != null) o.minMouseX = e.clientX - x + o.minX; 110 if (o.maxX != null) o.maxMouseX = o.minMouseX + o.maxX - o.minX; 111 } else { 112 if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x; 113 if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x; 114 } 115 116 if (o.vmode) { 117 if (o.minY != null) o.minMouseY = e.clientY - y + o.minY; 118 if (o.maxY != null) o.maxMouseY = o.minMouseY + o.maxY - o.minY; 119 } else { 120 if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y; 121 if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y; 122 } 123 124 document.onmousemove = Drag.drag; 125 document.onmouseup = Drag.end; 126 127 return false; 128 }, 129 130 drag : function(e) 131 { 132 e = Drag.fixE(e); 133 var o = Drag.obj; 134 135 var ey = e.clientY; 136 var ex = e.clientX; 137 var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom); 138 var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right ); 139 var nx, ny; 140 141 if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX); 142 if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX); 143 if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY); 144 if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY); 145 146 nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1)); 147 ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1)); 148 149 if (o.xMapper) nx = o.xMapper(y)
150 else if (o.yMapper) ny = o.yMapper(x) 151 152 //---------------------------------- 153 // Keep on screen? 154 //---------------------------------- 155 156 if ( Drag.keeponscreen ) 157 { 158 ny = ny < 0 ? 0 : ny; 159 nx = nx < 0 ? 0 : nx; 160 161 if ( Drag.my_width ) 162 { 163 nx = nx > Drag.my_width - parseInt(o.root.style.width) ? Drag.my_width - parseInt(o.root.style.width) : nx; 164 } 165 } 166 167 Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px"; 168 Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px"; 169 Drag.obj.lastMouseX = ex; 170 Drag.obj.lastMouseY = ey; 171 172 Drag.obj.root.onDrag(nx, ny); 173 return false; 174 }, 175 176 end : function() 177 { 178 document.onmousemove = null; 179 document.onmouseup = null; 180 Drag.obj.root.onDragEnd( parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), 181 parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"])); 182 183 var o = Drag.obj; 184 185 fy = parseInt( o.root.style.top ); 186 fx = parseInt( o.root.style.left ); 187 188 //---------------------------------- 189 // Store in a cookie? 190 //---------------------------------- 191 192 if ( Drag.cookiename ) 193 { 194 try 195 { 196 my_setcookie( Drag.cookiename, fx+','+fy, 1 ); 197 } 198 catch(e) 199 { 200 } 201 } 202 203 Drag.obj = null; 204 205 }, 206 207 fixE : function(e) 208 { 209 if (typeof e == 'undefined') e = window.event; 210 if (typeof e.layerX == 'undefined') e.layerX = e.offsetX; 211 if (typeof e.layerY == 'undefined') e.layerY = e.offsetY; 212 return e; 213 } 214};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.