[ Index ] |
|
Code source de Serendipity 1.2 |
1 /********************************************************** 2 Very minorly modified from the example by Tim Taylor 3 http://tool-man.org/examples/sorting.html 4 5 Added Coordinate.prototype.inside( northwest, southeast ); 6 7 Copyright (c) 2005 Tim Taylor Consulting <http://tool-man.org/> 8 9 Permission is hereby granted, free of charge, to any person obtaining a 10 copy of this software and associated documentation files (the "Software"), 11 to deal in the Software without restriction, including without limitation 12 the rights to use, copy, modify, merge, publish, distribute, sublicense, 13 and/or sell copies of the Software, and to permit persons to whom the 14 Software is furnished to do so, subject to the following conditions: 15 16 The above copyright notice and this permission notice shall be included 17 in all copies or substantial portions of the Software. 18 19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 20 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 25 IN THE SOFTWARE. 26 **********************************************************/ 27 28 var Coordinates = { 29 ORIGIN : new Coordinate(0, 0), 30 31 northwestPosition : function(element) { 32 var x = parseInt(element.style.left); 33 var y = parseInt(element.style.top); 34 35 return new Coordinate(isNaN(x) ? 0 : x, isNaN(y) ? 0 : y); 36 }, 37 38 southeastPosition : function(element) { 39 return Coordinates.northwestPosition(element).plus( 40 new Coordinate(element.offsetWidth, element.offsetHeight)); 41 }, 42 43 northwestOffset : function(element, isRecursive) { 44 var offset = new Coordinate(element.offsetLeft, element.offsetTop); 45 46 if (!isRecursive) return offset; 47 48 var parent = element.offsetParent; 49 while (parent) { 50 offset = offset.plus( 51 new Coordinate(parent.offsetLeft, parent.offsetTop)); 52 parent = parent.offsetParent; 53 } 54 return offset; 55 }, 56 57 southeastOffset : function(element, isRecursive) { 58 return Coordinates.northwestOffset(element, isRecursive).plus( 59 new Coordinate(element.offsetWidth, element.offsetHeight)); 60 }, 61 62 fixEvent : function(event) { 63 event.windowCoordinate = new Coordinate(event.clientX, event.clientY); 64 } 65 }; 66 67 function Coordinate(x, y) { 68 this.x = x; 69 this.y = y; 70 } 71 72 Coordinate.prototype.toString = function() { 73 return "(" + this.x + "," + this.y + ")"; 74 } 75 76 Coordinate.prototype.plus = function(that) { 77 return new Coordinate(this.x + that.x, this.y + that.y); 78 } 79 80 Coordinate.prototype.minus = function(that) { 81 return new Coordinate(this.x - that.x, this.y - that.y); 82 } 83 84 Coordinate.prototype.distance = function(that) { 85 var deltaX = this.x - that.x; 86 var deltaY = this.y - that.y; 87 88 return Math.sqrt(Math.pow(deltaX, 2) + Math.pow(deltaY, 2)); 89 } 90 91 Coordinate.prototype.max = function(that) { 92 var x = Math.max(this.x, that.x); 93 var y = Math.max(this.y, that.y); 94 return new Coordinate(x, y); 95 } 96 97 Coordinate.prototype.constrain = function(min, max) { 98 if (min.x > max.x || min.y > max.y) return this; 99 100 var x = this.x; 101 var y = this.y; 102 103 if (min.x != null) x = Math.max(x, min.x); 104 if (max.x != null) x = Math.min(x, max.x); 105 if (min.y != null) y = Math.max(y, min.y); 106 if (max.y != null) y = Math.min(y, max.y); 107 108 return new Coordinate(x, y); 109 } 110 111 Coordinate.prototype.reposition = function(element) { 112 element.style["top"] = this.y + "px"; 113 element.style["left"] = this.x + "px"; 114 } 115 116 Coordinate.prototype.equals = function(that) { 117 if (this == that) return true; 118 if (!that || that == null) return false; 119 120 return this.x == that.x && this.y == that.y; 121 } 122 123 // returns true of this point is inside specified box 124 Coordinate.prototype.inside = function(northwest, southeast) { 125 if ((this.x >= northwest.x) && (this.x <= southeast.x) && 126 (this.y >= northwest.y) && (this.y <= southeast.y)) { 127 128 return true; 129 } 130 return false; 131 } 132 133 /* 134 * drag.js - click & drag DOM elements 135 * 136 * originally based on Youngpup's dom-drag.js, www.youngpup.net 137 */ 138 139 /********************************************************** 140 Further modified from the example by Tim Taylor 141 http://tool-man.org/examples/sorting.html 142 143 Changed onMouseMove where it calls group.onDrag and then 144 adjusts the offset for changes to the DOM. If the item 145 being moved changed parents it would be off so changed to 146 get the absolute offset (recursive northwestOffset). 147 148 **********************************************************/ 149 150 var Drag = { 151 BIG_Z_INDEX : 10000, 152 group : null, 153 isDragging : false, 154 155 makeDraggable : function(group) { 156 group.handle = group; 157 group.handle.group = group; 158 159 group.minX = null; 160 group.minY = null; 161 group.maxX = null; 162 group.maxY = null; 163 group.threshold = 0; 164 group.thresholdY = 0; 165 group.thresholdX = 0; 166 167 group.onDragStart = new Function(); 168 group.onDragEnd = new Function(); 169 group.onDrag = new Function(); 170 171 // TODO: use element.prototype.myFunc 172 group.setDragHandle = Drag.setDragHandle; 173 group.setDragThreshold = Drag.setDragThreshold; 174 group.setDragThresholdX = Drag.setDragThresholdX; 175 group.setDragThresholdY = Drag.setDragThresholdY; 176 group.constrain = Drag.constrain; 177 group.constrainVertical = Drag.constrainVertical; 178 group.constrainHorizontal = Drag.constrainHorizontal; 179 180 group.onmousedown = Drag.onMouseDown; 181 }, 182 183 constrainVertical : function() { 184 var nwOffset = Coordinates.northwestOffset(this, true); 185 this.minX = nwOffset.x; 186 this.maxX = nwOffset.x; 187 }, 188 189 constrainHorizontal : function() { 190 var nwOffset = Coordinates.northwestOffset(this, true); 191 this.minY = nwOffset.y; 192 this.maxY = nwOffset.y; 193 }, 194 195 constrain : function(nwPosition, sePosition) { 196 this.minX = nwPosition.x; 197 this.minY = nwPosition.y; 198 this.maxX = sePosition.x; 199 this.maxY = sePosition.y; 200 }, 201 202 setDragHandle : function(handle) { 203 if (handle && handle != null) { 204 this.handle = handle; 205 } else { 206 this.handle = this; 207 } 208 209 this.handle.group = this; 210 this.onmousedown = null; 211 // this.onclick = Drag.toggleMe; 212 // this.handle.onclick = Drag.toggleMe; 213 this.handle.onmousedown = Drag.onMouseDown; 214 }, 215 216 toggleMe : function(str) { 217 alert('Toggle: ' + str); 218 }, 219 220 setDragThreshold : function(threshold) { 221 if (isNaN(parseInt(threshold))) return; 222 223 this.threshold = threshold; 224 }, 225 226 setDragThresholdX : function(threshold) { 227 if (isNaN(parseInt(threshold))) return; 228 229 this.thresholdX = threshold; 230 }, 231 232 setDragThresholdY : function(threshold) { 233 if (isNaN(parseInt(threshold))) return; 234 235 this.thresholdY = threshold; 236 }, 237 238 onMouseDown : function(event) { 239 event = Drag.fixEvent(event); 240 Drag.group = this.group; 241 242 var group = this.group; 243 var mouse = event.windowCoordinate; 244 var nwOffset = Coordinates.northwestOffset(group, true); 245 var nwPosition = Coordinates.northwestPosition(group); 246 var sePosition = Coordinates.southeastPosition(group); 247 var seOffset = Coordinates.southeastOffset(group, true); 248 249 group.originalOpacity = group.style.opacity; 250 group.originalZIndex = group.style.zIndex; 251 group.initialWindowCoordinate = mouse; 252 // TODO: need a better name, but don't yet understand how it 253 // participates in the magic while dragging 254 group.dragCoordinate = mouse; 255 256 Drag.showStatus(mouse, nwPosition, sePosition, nwOffset, seOffset); 257 258 group.onDragStart(nwPosition, sePosition, nwOffset, seOffset); 259 260 // TODO: need better constraint API 261 if (group.minX != null) 262 group.minMouseX = mouse.x - nwPosition.x + 263 group.minX - nwOffset.x; 264 if (group.maxX != null) 265 group.maxMouseX = group.minMouseX + group.maxX - group.minX; 266 267 if (group.minY != null) 268 group.minMouseY = mouse.y - nwPosition.y + 269 group.minY - nwOffset.y; 270 if (group.maxY != null) 271 group.maxMouseY = group.minMouseY + group.maxY - group.minY; 272 273 group.mouseMin = new Coordinate(group.minMouseX, group.minMouseY); 274 group.mouseMax = new Coordinate(group.maxMouseX, group.maxMouseY); 275 276 document.onmousemove = Drag.onMouseMove; 277 document.onmouseup = Drag.onMouseUp; 278 279 return false; 280 }, 281 282 showStatus : function(mouse, nwPosition, sePosition, nwOffset, seOffset) { 283 /*window.status = 284 "mouse: " + mouse.toString() + " " + 285 "NW pos: " + nwPosition.toString() + " " + 286 "SE pos: " + sePosition.toString() + " " + 287 "NW offset: " + nwOffset.toString() + " " + 288 "SE offset: " + seOffset.toString();*/ 289 }, 290 291 onMouseMove : function(event) { 292 event = Drag.fixEvent(event); 293 var group = Drag.group; 294 var mouse = event.windowCoordinate; 295 var nwOffset = Coordinates.northwestOffset(group, true); 296 var nwPosition = Coordinates.northwestPosition(group); 297 var sePosition = Coordinates.southeastPosition(group); 298 var seOffset = Coordinates.southeastOffset(group, true); 299 300 Drag.showStatus(mouse, nwPosition, sePosition, nwOffset, seOffset); 301 302 if (!Drag.isDragging) { 303 if (group.threshold > 0) { 304 var distance = group.initialWindowCoordinate.distance( 305 mouse); 306 if (distance < group.threshold) return true; 307 } else if (group.thresholdY > 0) { 308 var deltaY = Math.abs(group.initialWindowCoordinate.y - mouse.y); 309 if (deltaY < group.thresholdY) return true; 310 } else if (group.thresholdX > 0) { 311 var deltaX = Math.abs(group.initialWindowCoordinate.x - mouse.x); 312 if (deltaX < group.thresholdX) return true; 313 } 314 315 Drag.isDragging = true; 316 group.style["zIndex"] = Drag.BIG_Z_INDEX; 317 group.style["opacity"] = 0.75; 318 } 319 320 // TODO: need better constraint API 321 var adjusted = mouse.constrain(group.mouseMin, group.mouseMax); 322 nwPosition = nwPosition.plus(adjusted.minus(group.dragCoordinate)); 323 nwPosition.reposition(group); 324 group.dragCoordinate = adjusted; 325 326 // once dragging has started, the position of the group 327 // relative to the mouse should stay fixed. They can get out 328 // of sync if the DOM is manipulated while dragging, so we 329 // correct the error here 330 // 331 // TODO: what we really want to do is find the offset from 332 // our corner to the mouse coordinate and adjust to keep it 333 // the same 334 335 // changed to be recursive/use absolute offset for corrections 336 var offsetBefore = Coordinates.northwestOffset(group, true); 337 group.onDrag(nwPosition, sePosition, nwOffset, seOffset); 338 var offsetAfter = Coordinates.northwestOffset(group, true); 339 340 if (!offsetBefore.equals(offsetAfter)) { 341 var errorDelta = offsetBefore.minus(offsetAfter); 342 nwPosition = Coordinates.northwestPosition(group).plus(errorDelta); 343 nwPosition.reposition(group); 344 } 345 346 return false; 347 }, 348 349 onMouseUp : function(event) { 350 event = Drag.fixEvent(event); 351 var group = Drag.group; 352 353 var mouse = event.windowCoordinate; 354 var nwOffset = Coordinates.northwestOffset(group, true); 355 var nwPosition = Coordinates.northwestPosition(group); 356 var sePosition = Coordinates.southeastPosition(group); 357 var seOffset = Coordinates.southeastOffset(group, true); 358 359 document.onmousemove = null; 360 document.onmouseup = null; 361 group.onDragEnd(nwPosition, sePosition, nwOffset, seOffset); 362 363 if (Drag.isDragging) { 364 // restoring zIndex before opacity avoids visual flicker in Firefox 365 group.style["zIndex"] = group.originalZIndex; 366 group.style["opacity"] = group.originalOpacity; 367 } 368 369 Drag.group = null; 370 Drag.isDragging = false; 371 372 return false; 373 }, 374 375 fixEvent : function(event) { 376 if (typeof event == 'undefined') event = window.event; 377 Coordinates.fixEvent(event); 378 379 return event; 380 } 381 }; 382 383 /********************************************************** 384 Adapted from the sortable lists example by Tim Taylor 385 http://tool-man.org/examples/sorting.html 386 Modified by Tom Westcott : http://www.cyberdummy.co.uk 387 **********************************************************/ 388 389 var DragDrop = { 390 firstContainer : null, 391 lastContainer : null, 392 parent_id : null, 393 parent_group : null, 394 makeListContainer : function(list, group) { 395 // each container becomes a linked list node 396 if (this.firstContainer == null) { 397 this.firstContainer = this.lastContainer = list; 398 list.previousContainer = null; 399 list.nextContainer = null; 400 } else { 401 list.previousContainer = this.lastContainer; 402 list.nextContainer = null; 403 this.lastContainer.nextContainer = list; 404 this.lastContainer = list; 405 } 406 407 // these functions are called when an item is draged over 408 // a container or out of a container bounds. onDragOut 409 // is also called when the drag ends with an item having 410 // been added to the container 411 list.onDragOver = new Function(); 412 list.onDragOut = new Function(); 413 list.onDragDrop = new Function(); 414 list.group = group; 415 416 var items = list.getElementsByTagName( "li" ); 417 418 for (var i = 0; i < items.length; i++) { 419 DragDrop.makeItemDragable(items[i]); 420 } 421 }, 422 423 serData : function ( group, theid ) { 424 var container = DragDrop.firstContainer; 425 var j = 0; 426 var string = ""; 427 428 while (container != null) { 429 if(theid != null && container.id != theid) { 430 container = container.nextContainer; 431 continue; 432 } 433 434 if(group != null && container.group != group) { 435 container = container.nextContainer; 436 continue; 437 } 438 439 j ++; 440 if (j > 1) { 441 string += ":"; 442 } 443 string += container.id; 444 445 var items = container.getElementsByTagName( "li" ); 446 string += "("; 447 for (var i = 0; i < items.length; i++) { 448 if(i > 0) { 449 string += ","; 450 } 451 452 string += items[i].id; 453 } 454 string += ")"; 455 456 container = container.nextContainer; 457 } 458 459 return string; 460 }, 461 462 makeItemDragable : function(item) { 463 Drag.makeDraggable(item); 464 item.setDragThreshold(5); 465 466 // tracks if the item is currently outside all containers 467 item.isOutside = false; 468 469 item.onDragStart = DragDrop.onDragStart; 470 item.onDrag = DragDrop.onDrag; 471 item.onDragEnd = DragDrop.onDragEnd; 472 473 item.setDragHandle(document.getElementById('g' + item.id)); 474 }, 475 476 onDragStart : function(nwPosition, sePosition, nwOffset, seOffset) { 477 // update all container bounds, since they may have changed 478 // on a previous drag 479 // 480 // could be more smart about when to do this 481 var container = DragDrop.firstContainer; 482 while (container != null) { 483 container.northwest = Coordinates.northwestOffset( container, true ); 484 container.southeast = Coordinates.southeastOffset( container, true ); 485 container = container.nextContainer; 486 } 487 488 // item starts out over current parent 489 this.parentNode.onDragOver(); 490 parent_id = this.parentNode.id; 491 parent_group = this.parentNode.group; 492 }, 493 494 onDrag : function(nwPosition, sePosition, nwOffset, seOffset) { 495 // check if we were nowhere 496 if (this.isOutside) { 497 // check each container to see if in its bounds 498 var container = DragDrop.firstContainer; 499 while (container != null) { 500 501 if ((nwOffset.inside( container.northwest, container.southeast ) || 502 seOffset.inside( container.northwest, container.southeast )) && container.group == parent_group) { 503 // we're inside this one 504 container.onDragOver(); 505 this.isOutside = false; 506 507 // since isOutside was true, the current parent is a 508 // temporary clone of some previous container node and 509 // it needs to be removed from the document 510 var tempParent = this.parentNode; 511 tempParent.removeChild( this ); 512 container.appendChild( this ); 513 tempParent.parentNode.removeChild( tempParent ); 514 break; 515 } 516 container = container.nextContainer; 517 } 518 // we're still not inside the bounds of any container 519 if (this.isOutside) 520 return; 521 522 // check if we're outside our parent's bounds 523 } else if (!(nwOffset.inside( this.parentNode.northwest, this.parentNode.southeast ) || 524 seOffset.inside( this.parentNode.northwest, this.parentNode.southeast ))) { 525 526 this.parentNode.onDragOut(); 527 this.isOutside = true; 528 529 // check if we're inside a new container's bounds 530 var container = DragDrop.firstContainer; 531 while (container != null) { 532 if ((nwOffset.inside( container.northwest, container.southeast ) || 533 seOffset.inside( container.northwest, container.southeast )) && container.group == parent_group) { 534 // we're inside this one 535 container.onDragOver(); 536 this.isOutside = false; 537 this.parentNode.removeChild( this ); 538 container.appendChild( this ); 539 break; 540 } 541 container = container.nextContainer; 542 } 543 // if we're not in any container now, make a temporary clone of 544 // the previous container node and add it to the document 545 if (this.isOutside) { 546 var tempParent = this.parentNode.cloneNode( false ); 547 this.parentNode.removeChild( this ); 548 tempParent.appendChild( this ); 549 // body puts a border or item at bottom of page if do not have this 550 tempParent.style.border = 0; 551 document.getElementsByTagName( "body" ).item(0).appendChild( tempParent ); 552 return; 553 } 554 } 555 556 // if we get here, we're inside some container bounds, so we do 557 // everything the original dragsort script did to swap us into the 558 // correct position 559 560 var parent = this.parentNode; 561 562 var item = this; 563 var next = DragUtils.nextItem(item); 564 while (next != null && this.offsetTop >= next.offsetTop - 2) { 565 var item = next; 566 var next = DragUtils.nextItem(item); 567 } 568 if (this != item) { 569 DragUtils.swap(this, next); 570 return; 571 } 572 573 var item = this; 574 var previous = DragUtils.previousItem(item); 575 while (previous != null && this.offsetTop <= previous.offsetTop + 2) { 576 var item = previous; 577 var previous = DragUtils.previousItem(item); 578 } 579 if (this != item) { 580 DragUtils.swap(this, item); 581 return; 582 } 583 }, 584 585 onDragEnd : function(nwPosition, sePosition, nwOffset, seOffset) { 586 // if the drag ends and we're still outside all containers 587 // it's time to remove ourselves from the document or add 588 // to the trash bin 589 if (this.isOutside) { 590 var container = DragDrop.firstContainer; 591 while (container != null) { 592 if (container.id == parent_id) { 593 break; 594 } 595 container = container.nextContainer; 596 } 597 this.isOutside = false; 598 this.parentNode.removeChild( this ); 599 container.appendChild( this ); 600 this.style["top"] = "0px"; 601 this.style["left"] = "0px"; 602 //var container = DragDrop.firstContainer; 603 //container.appendChild( this ); 604 return; 605 } 606 this.parentNode.onDragOut(); 607 this.parentNode.onDragDrop(); 608 this.style["top"] = "0px"; 609 this.style["left"] = "0px"; 610 } 611 }; 612 613 var DragUtils = { 614 swap : function(item1, item2) { 615 var parent = item1.parentNode; 616 parent.removeChild(item1); 617 parent.insertBefore(item1, item2); 618 619 item1.style["top"] = "0px"; 620 item1.style["left"] = "0px"; 621 }, 622 623 nextItem : function(item) { 624 var sibling = item.nextSibling; 625 while (sibling != null) { 626 if (sibling.nodeName == item.nodeName) return sibling; 627 sibling = sibling.nextSibling; 628 } 629 return null; 630 }, 631 632 previousItem : function(item) { 633 var sibling = item.previousSibling; 634 while (sibling != null) { 635 if (sibling.nodeName == item.nodeName) return sibling; 636 sibling = sibling.previousSibling; 637 } 638 return null; 639 } 640 }; 641 642 /************************* 643 * Custom Serendipity code 644 *************************/ 645 646 function pluginMoverInit() { 647 var list = document.getElementById("left_col"); 648 DragDrop.makeListContainer(list, 'g1'); 649 list.onDragOver = function() { this.style["border"] = "1px solid #4d759b"; }; 650 list.onDragOut = function() { this.style["border"] = "none"; }; 651 652 list = document.getElementById("hide_col"); 653 DragDrop.makeListContainer(list, 'g1'); 654 list.onDragOver = function() { this.style["border"] = "1px solid #4d759b"; }; 655 list.onDragOut = function() {this.style["border"] = "none"; }; 656 657 list = document.getElementById("right_col"); 658 DragDrop.makeListContainer(list, 'g1'); 659 list.onDragOver = function() { this.style["border"] = "1px solid #4d759b"; }; 660 list.onDragOut = function() {this.style["border"] = "none"; }; 661 } 662 663 function pluginMoverInitEvent() { 664 var list = document.getElementById("event_col"); 665 DragDrop.makeListContainer(list, 'g1'); 666 list.onDragOver = function() { this.style["border"] = "1px solid #4d759b"; }; 667 list.onDragOut = function() { this.style["border"] = "none"; }; 668 669 list = document.getElementById("eventh_col"); 670 DragDrop.makeListContainer(list, 'g1'); 671 list.onDragOver = function() { this.style["border"] = "1px solid #4d759b"; }; 672 list.onDragOut = function() {this.style["border"] = "none"; }; 673 } 674 675 function pluginMovergetSort() { 676 order = document.getElementById("order"); 677 order.value = DragDrop.serData('g1', null); 678 return order.value; 679 } 680 681 function pluginMovergetSortEvent() { 682 order = document.getElementById("eventorder"); 683 order.value = DragDrop.serData('g1', null); 684 return order.value; 685 } 686 687 /************************************************** 688 * dom-drag.js 689 * 09.25.2001 690 * www.youngpup.net 691 ************************************************** 692 * 10.28.2001 - fixed minor bug where events 693 * sometimes fired off the handle, not the root. 694 **************************************************/ 695 696 var DOMDrag = { 697 698 obj : null, 699 700 init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper) { 701 o.onmousedown = DOMDrag.start; 702 703 o.hmode = bSwapHorzRef ? false : true ; 704 o.vmode = bSwapVertRef ? false : true ; 705 706 o.root = oRoot && oRoot != null ? oRoot : o ; 707 708 if (o.hmode && isNaN(parseInt(o.root.style.left ))) o.root.style.left = "0px"; 709 if (o.vmode && isNaN(parseInt(o.root.style.top ))) o.root.style.top = "0px"; 710 if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right = "0px"; 711 if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px"; 712 713 o.minX = typeof minX != 'undefined' ? minX : null; 714 o.minY = typeof minY != 'undefined' ? minY : null; 715 o.max = typeof maxX != 'undefined' ? maxX : null; 716 o.maxY = typeof maxY != 'undefined' ? maxY : null; 717 718 o.xMapper = fXMapper ? fXMapper : null; 719 o.yMapper = fYMapper ? fYMapper : null; 720 721 o.root.onDragStart = new Function(); 722 o.root.onDragEnd = new Function(); 723 o.root.onDrag = new Function(); 724 }, 725 726 start : function(e) { 727 var o = DOMDrag.obj = this; 728 e = DOMDrag.fixE(e); 729 var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom); 730 var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right ); 731 o.root.onDragStart(x, y); 732 733 o.lastMouseX = e.clientX; 734 o.lastMouseY = e.clientY; 735 736 if (o.hmode) { 737 if (o.minX != null) o.minMouseX = e.clientX - x + o.minX; 738 if (o.maxX != null) o.maxMouseX = o.minMouseX + o.maxX - o.minX; 739 } else { 740 if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x; 741 if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x; 742 } 743 744 if (o.vmode) { 745 if (o.minY != null) o.minMouseY = e.clientY - y + o.minY; 746 if (o.maxY != null) o.maxMouseY = o.minMouseY + o.maxY - o.minY; 747 } else { 748 if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y; 749 if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y; 750 } 751 752 document.onmousemove = DOMDrag.drag; 753 document.onmouseup = DOMDrag.end; 754 755 return false; 756 }, 757 758 drag : function(e) { 759 e = DOMDrag.fixE(e); 760 var o = DOMDrag.obj; 761 762 var ey = e.clientY; 763 var ex = e.clientX; 764 var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom); 765 var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right ); 766 var nx, ny; 767 768 if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX); 769 if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX); 770 if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY); 771 if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY); 772 773 nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1)); 774 ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1)); 775 776 if (o.xMapper) nx = o.xMapper(y) 777 else if (o.yMapper) ny = o.yMapper(x) 778 779 DOMDrag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px"; 780 DOMDrag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px"; 781 DOMDrag.obj.lastMouseX = ex; 782 DOMDrag.obj.lastMouseY = ey; 783 784 DOMDrag.obj.root.onDrag(nx, ny); 785 return false; 786 }, 787 788 end : function() { 789 document.onmousemove = null; 790 document.onmouseup = null; 791 DOMDrag.obj.root.onDragEnd( parseInt(DOMDrag.obj.root.style[DOMDrag.obj.hmode ? "left" : "right"]), 792 parseInt(DOMDrag.obj.root.style[DOMDrag.obj.vmode ? "top" : "bottom"])); 793 DOMDrag.obj = null; 794 }, 795 796 fixE : function(e) { 797 if (typeof e == 'undefined') e = window.event; 798 if (typeof e.layerX == 'undefined') e.layerX = e.offsetX; 799 if (typeof e.layerY == 'undefined') e.layerY = e.offsetY; 800 return e; 801 } 802 };
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Nov 24 09:00:37 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |