Thread CGI-Skript mit Drag & Drop Funktion
(6 answers)
Opened by
kimmy
at 2010-12-14 17:19
User since 2010-09-10
87
Artikel
BenutzerIn
Hallo,
ich habe ein CGI-Skript mit Drag & Drop Funktion erstellt. Aber leider das Skript läuft nicht richtig. Aber wenn ich das Skript im Shell ausführe, wie z. B.
$ perl drag_drop.pl > test_drag_drop.html
und dann wenn ich die HTML-Datei mit Webbrowser aufmache, dann komischerweise läuft die Drag & Drop Funktion ganz richtig.
Könnt jemand mir sagen, woran es liegt?
Und wie kann ich die gedropte Elemente für die weitere Verwendung zugreifen?
my $drop = param("dropBox");
Leider das geht auch nicht.
Ciao.
kimmy
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
#!/usr/bin/perl -w
use strict; use CGI qw(:standard :html4); use CGI::Carp qw(carpout fatalsToBrowser); use CGI::Pretty ":standard"; use utf8;
my $cgi = CGI->new(); print header; print start_html(-head => style({-rel => 'stylesheet', -type => 'text/css', -media => 'screen', -src => 'css/demos.css'}, join('',<DATA>))); print "<script type=\"text/javascript\" src=\"js/drag-drop-custom.js\"></script>\n";
print start_form(-action=>"http://localhost:8888/cgi-bin/semanticlass/prep/param.pl");
#print "<div id=\"mainContainer\">\n"; print "<h2>Drag & Drop</h2>\n"; print "<div id=\"leftColumn\">\n"; print "<p><b>Drag</b></p>\n"; print "<div id=\"dropContent\">\n";
my @header = (1,2,3,4); my $i = 1; foreach(@header){ my $box = 'box'.$i; print "<div class=\"dragableBox\" id=\"$box\">$_</div>\n"; $i++; } print "</div>\n"; print "</div>\n"; #print "<div id=\"rightColumn\">\n"; print "<div id=\"dropBox\" class=\"dropBox\">\n"; print "<p><b>Drop</b></p>\n"; print "<div id=\"dropContent2\"></div>\n"; print "</div>\n"; #print "</div>\n"; print "<div class=\"clear\"></div>\n"; #print "</div>\n";
print "<div id=\"debug\"></div>\n"; print p("Feldname: ", textfield("wname")); print p("Datentyp: ", textfield("wtyp")); print p("Feldlänge: ", textfield("wlength")); print p(submit ("Abschicken")); print end_form(); ############## Java Script ############## print "<script type=\"text/javascript\" src=\"js/drag-drop-custom.js\"></script>\n"; print "<script type=text/javascript>\n"; print "function dropItems(idOfDraggedItem,targetId,x,y){\n"; print "if(targetId=='dropBox'){\n"; print "var obj = document.getElementById(idOfDraggedItem);\n"; print "if(obj.parentNode.id=='dropContent2')return;\n"; print "document.getElementById('dropContent2').appendChild(obj);\n"; print "}\n"; print "if(targetId=='leftColumn'){\n"; print "var obj = document.getElementById(idOfDraggedItem);\n"; print "if(obj.parentNode.id=='dropContent')return;\n"; print "document.getElementById('dropContent').appendChild(obj);\n"; print "}\n"; #print "if(targetId=='dropBoxTest'){\n"; #print "var obj = document.getElementById(idOfDraggedItem);\n"; #print "if(obj.parentNode.id=='dropContent3')return;\n"; #print "document.getElementById('dropContent3').appendChild(obj);\n"; #print "}\n"; print "}\n";
print "function onDragFunction(cloneId,origId){\n"; print "self.status = 'Started dragging element with id ' + cloneId;\n";
print "var obj = document.getElementById(cloneId);\n"; print "obj.style.border='1px solid #F00';\n"; print "}\n";
print "var dragDropObj = new DHTMLgoodies_dragDrop();\n"; print "dragDropObj.addSource('box1',true,true,true,false,'onDragFunction');\n"; print "dragDropObj.addSource('box2',true,true,true,false,'onDragFunction');\n"; print "dragDropObj.addSource('box3',true,true,true,false,'onDragFunction');\n"; print "dragDropObj.addSource('box4',true,true,true,false,'onDragFunction');\n"; print "dragDropObj.addTarget('dropBox','dropItems');\n"; print "dragDropObj.addTarget('leftColumn','dropItems');\n"; #print "dragDropObj.addTarget('dropBoxTest','dropItems');\n"; print "dragDropObj.init();\n"; print "</script>\n"; ############## Java Script ############## print end_html();
__DATA__
#mainContainer{ width:600px; margin:0 auto; margin-top:10px; border:1px solid #000; padding:2px; height:580px; }
#leftColumn{ width:150px; float:left; border:1px solid #000; background-color:#E2EBED; padding:3px; height:500px; }
#rightColumn{ width:150px; float:left; border:1px solid #000; background-color:#E2EBED; padding:3px; height:400px; }
#rightColumnTest{ width:200px; float:right; margin:2px; height:400px; }
.dragableBox{ width:110px; height:13px; border:1px solid #000; background-color:#FFF; margin-bottom:5px; padding:10px; font-weight:bold; text-align:center; } .dropBox{ width:150px; border:1px solid #000; background-color:#E2EBED; height:400px; margin-bottom:10px; padding:3px; overflow:auto; height:500px; } .dropBoxTest{ width:150px; border:1px solid #000; background-color:#E2EBED; height:400px; margin-bottom:10px; padding:3px; overflow:auto; } a{ color:#F00; }
.clear{ clear:both; } img{ border:0px; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731
/************************************************************************************************************
CUSTOM DRAG AND DROP SCRIPT This script is a part of DHTMLSuite for application which will be released before christmas 2006. (C) www.dhtmlgoodies.com, August 2006
This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website. Terms of use: Look at the terms of use at http://www.dhtmlgoodies.com/index.html?page=termsOfUse Thank you! www.dhtmlgoodies.com Alf Magne Kalleland
************************************************************************************************************/
/************************************************************************************************************ * * Global variables * ************************************************************************************************************/
var standardObjectsCreated = false; // The classes below will check this variable, if it is false, default help objects will be created var clientInfoObj; // Object of class DHTMLgoodies_clientInfo var dhtmlSuiteConfigObj = false; // Object of class DHTMLgoodies_config var dhtmlSuiteCommonObj; // Object of class DHTMLgoodies_common
// {{{ DHTMLgoodies_createStandardObjects() /** * Create objects used by all scripts * * @public */ function DHTMLgoodies_createStandardObjects() { clientInfoObj = new DHTMLgoodies_clientInfo(); // Create browser info object clientInfoObj.init(); if(!dhtmlSuiteConfigObj){ // If this object isn't allready created, create it. dhtmlSuiteConfigObj = new DHTMLgoodies_config(); // Create configuration object. dhtmlSuiteConfigObj.init(); } dhtmlSuiteCommonObj = new DHTMLgoodies_common(); // Create configuration object. dhtmlSuiteCommonObj.init(); }
/************************************************************************************************************ * Configuration class used by most of the scripts * * Created: August, 19th, 2006 * Purpose of class: Store global variables/configurations used by the classes below. Example: If you want to * change the path to the images used by the scripts, change it here. An object of this * class will always be available to the other classes. The name of this object is * "dhtmlSuiteConfigObj". * * If you want to create an object of this class manually, remember to name it "dhtmlSuiteConfigObj" * This object should then be created before any other objects. This is nescessary if you want * the other objects to use the values you have put into the object. * Update log: * ************************************************************************************************************/
// {{{ DHTMLgoodies_config() /** * Constructor * * @public */ function DHTMLgoodies_config() { var imagePath; // Path to images used by the classes. var cssPath; // Path to CSS files used by the DHTML suite. }
DHTMLgoodies_config.prototype = { // {{{ init() /** * * @public */ init : function() { this.imagePath = 'images_dhtmlsuite/'; // Path to images this.cssPath = 'css_dhtmlsuite/'; // Path to images } // }}} , // {{{ setCssPath() /** * This method will save a new CSS path, i.e. where the css files of the dhtml suite are located. * * @param string newCssPath = New path to css files * @public */ setCssPath : function(newCssPath) { this.cssPath = newCssPath; } // }}} , // {{{ setImagePath() /** * This method will save a new image file path, i.e. where the image files used by the dhtml suite ar located * * @param string newImagePath = New path to image files * @public */ setImagePath : function(newImagePath) { this.imagePath = newImagePath; } // }}} }
/************************************************************************************************************ * A class with general methods used by most of the scripts * * Created: August, 19th, 2006 * Purpose of class: A class containing common method used by one or more of the gui classes below, * example: loadCSS. * An object("dhtmlSuiteCommonObj") of this class will always be available to the other classes. * Update log: * ************************************************************************************************************/
// {{{ DHTMLgoodies_common() /** * Constructor * */ function DHTMLgoodies_common() { var loadedCSSFiles; // Array of loaded CSS files. Prevent same CSS file from being loaded twice. }
DHTMLgoodies_common.prototype = { // {{{ init() /** * This method initializes the DHTMLgoodies_common object. * * @public */ init : function() { this.loadedCSSFiles = new Array(); } // }}} , // {{{ getTopPos() /** * This method will return the top coordinate(pixel) of an object * * @param Object inputObj = Reference to HTML element * @public */ getTopPos : function(inputObj) { var returnValue = inputObj.offsetTop; while((inputObj = inputObj.offsetParent) != null){ if(inputObj.tagName!='HTML'){ returnValue += inputObj.offsetTop; if(document.all)returnValue+=inputObj.clientTop; } } return returnValue; } // }}} , // {{{ getLeftPos() /** * This method will return the left coordinate(pixel) of an object * * @param Object inputObj = Reference to HTML element * @public */ getLeftPos : function(inputObj) { var returnValue = inputObj.offsetLeft; while((inputObj = inputObj.offsetParent) != null){ if(inputObj.tagName!='HTML'){ returnValue += inputObj.offsetLeft; if(document.all)returnValue+=inputObj.clientLeft; } } return returnValue; } // }}} , // {{{ cancelEvent() /** * * This function only returns false. It is used to cancel selections and drag * * * @public */ cancelEvent : function() { return false; } // }}} }
/************************************************************************************************************ * Client info class * * Created: August, 18th, 2006 * Purpose of class: Provide browser information to the classes below. Instead of checking for * browser versions and browser types in the classes below, they should check this * easily by referncing properties in the class below. An object("clientInfoObj") of this * class will always be accessible to the other classes. * Update log: * ************************************************************************************************************/
/* Constructor */
function DHTMLgoodies_clientInfo() { var browser; // Complete user agent information var isOpera; // Is the browser "Opera" var isMSIE; // Is the browser "Internet Explorer" var isFirefox; // Is the browser "Firefox" var navigatorVersion; // Browser version } DHTMLgoodies_clientInfo.prototype = { /** * Constructor * Params: none: * return value: none; **/ // {{{ init() /** * * * This method initializes the script * * * @public */ init : function() { this.browser = navigator.userAgent; this.isOpera = (this.browser.toLowerCase().indexOf('opera')>=0)?true:false; this.isFirefox = (this.browser.toLowerCase().indexOf('firefox')>=0)?true:false; this.isMSIE = (this.browser.toLowerCase().indexOf('msie')>=0)?true:false; this.navigatorVersion = navigator.appVersion.replace(/.*?MSIE (\d\.\d).*/g,'$1')/1; } // }}} }
/************************************************************************************************************ * Drag and drop class * * Created: August, 18th, 2006 * Purpose of class: A general drag and drop class. By creating objects of this class, you can make elements * on your web page dragable and also assign actions to element when an item is dropped on it. * A page should only have one object of this class. * * IMPORTANT when you use this class: Don't assign layout to the dragable element ids * Assign it to classes or the tag instead. example: If you make <div id="dragableBox1" class="aBox"> * dragable, don't assign css to #dragableBox1. Assign it to div or .aBox instead. * * Update log: * ************************************************************************************************************/
var referenceToDragDropObject; // A reference to an object of the class below.
/* Constructor */ function DHTMLgoodies_dragDrop() { var mouse_x; // mouse x position when drag is started var mouse_y; // mouse y position when drag is started. var el_x; // x position of dragable element var el_y; // y position of dragable element var dragDropTimer; // Timer - short delay from mouse down to drag init. var numericIdToBeDragged; // numeric reference to element currently being dragged. var dragObjCloneArray; // Array of cloned dragable elements. every var dragDropSourcesArray; // Array of source elements, i.e. dragable elements. var dragDropTargetArray; // Array of target elements, i.e. elements where items could be dropped. var currentZIndex; // Current z index. incremented on each drag so that currently dragged element is always on top. var okToStartDrag; // Variable which is true or false. It would be false for 1/100 seconds after a drag has been started. // This is useful when you have nested dragable elements. It prevents the drag process from staring on // parent element when you click on dragable sub element. var moveBackBySliding; // Variable indicating if objects should slide into place moved back to their location without any slide animation. }
DHTMLgoodies_dragDrop.prototype = { // {{{ init() /** * Initialize the script * This method should be called after you have added sources and destinations. * * @public */ init : function() { if(!standardObjectsCreated)DHTMLgoodies_createStandardObjects(); // This line starts all the init methods this.currentZIndex = 10000; this.dragDropTimer = -1; this.dragObjCloneArray = new Array(); this.numericIdToBeDragged = false; this.__initDragDropScript(); referenceToDragDropObject = this; this.okToStartDrag = true; this.moveBackBySliding = true; } // }}} , // {{{ addSource() /** * Add dragable element * * @param String sourceId = Id of source * @param boolean slideBackAfterDrop = Slide the item back to it's original location after drop. * @param boolean xAxis = Allowed to slide along the x-axis(default = true, i.e. if omitted). * @param boolean yAxis = Allowed to slide along the y-axis(default = true, i.e. if omitted). * @param String dragOnlyWithinElId = You will only allow this element to be dragged within the boundaries of the element with this id. * @param String functionToCallOnDrag = Function to call when drag is initiated. id of element(clone and orig) will be passed to this function . clone is a copy of the element created by this script. The clone is what you see when drag is in process. * * @public */ addSource : function(sourceId,slideBackAfterDrop,xAxis,yAxis,dragOnlyWithinElId,functionToCallOnDrag) { if(!functionToCallOnDrag)functionToCallOnDrag=false; if(!this.dragDropSourcesArray)this.dragDropSourcesArray = new Array(); if(!document.getElementById(sourceId))alert('The source element with id ' + sourceId + ' does not exists'); var obj = document.getElementById(sourceId); if(xAxis!==false)xAxis = true; if(yAxis!==false)yAxis = true; this.dragDropSourcesArray[this.dragDropSourcesArray.length] = [obj,slideBackAfterDrop,xAxis,yAxis,dragOnlyWithinElId,functionToCallOnDrag]; obj.setAttribute('dragableElement',this.dragDropSourcesArray.length-1); obj.dragableElement = this.dragDropSourcesArray.length-1; } // }}} , // {{{ addTarget() /** * Add drop target * * @param String targetId = Id of drop target * @param String functionToCallOnDrop = name of function to call on drop. * Input to this the function specified in functionToCallOnDrop function would be * id of dragged element * id of the element the item was dropped on. * mouse x coordinate when item was dropped * mouse y coordinate when item was dropped * * @public */ addTarget : function(targetId,functionToCallOnDrop) { if(!this.dragDropTargetArray)this.dragDropTargetArray = new Array(); if(!document.getElementById(targetId))alert('The target element with id ' + targetId + ' does not exists'); var obj = document.getElementById(targetId); this.dragDropTargetArray[this.dragDropTargetArray.length] = [obj,functionToCallOnDrop]; } // }}} , // {{{ setSlide() /** * Activate or deactivate sliding animations. * * @param boolean slide = Move element back to orig. location in a sliding animation * * @public */ setSlide : function(slide) { this.moveBackBySliding = slide; } // }}} , /* Start private methods */ // {{{ __initDragDropScript() /** * Initialize drag drop script - this method is called by the init() method. * * @private */ __initDragDropScript : function() { var refToThis = this; for(var no=0;no<this.dragDropSourcesArray.length;no++){ var el = this.dragDropSourcesArray[no][0].cloneNode(true); el.onmousedown =this.__initDragDropElement; el.id = 'DHTMLgoodies_dragableElement' + no; el.style.position='absolute'; el.style.visibility='hidden'; el.style.display='none';
this.dragDropSourcesArray[no][0].parentNode.insertBefore(el,this.dragDropSourcesArray[no][0]); el.style.top = dhtmlSuiteCommonObj.getTopPos(this.dragDropSourcesArray[no][0]) + 'px'; el.style.left = dhtmlSuiteCommonObj.getLeftPos(this.dragDropSourcesArray[no][0]) + 'px'; this.dragDropSourcesArray[no][0].onmousedown =this.__initDragDropElement; this.dragObjCloneArray[no] = el; } document.documentElement.onmousemove = this.__moveDragableElement; document.documentElement.onmouseup = this.__stop_dragDropElement; document.documentElement.onselectstart = function() { return refToThis.__cancelSelectionEvent(false,this) }; document.documentElement.ondragstart = function() { return dhtmlSuiteCommonObj.cancelEvent(false,this) }; } // }}} , // {{{ __initDragDropElement() /** * Initialize drag process * * @param Event e = Event object, used to get x and y coordinate of mouse pointer * * @private */ // {{{ __initDragDropElement() /** * Initialize drag process * * @param Event e = Event object, used to get x and y coordinate of mouse pointer * * @private */ __initDragDropElement : function(e) { if(!referenceToDragDropObject.okToStartDrag)return; referenceToDragDropObject.okToStartDrag = false; setTimeout('referenceToDragDropObject.okToStartDrag = true;',100); if(document.all)e = event; referenceToDragDropObject.numericIdToBeDragged = this.getAttribute('dragableElement'); referenceToDragDropObject.numericIdToBeDragged = referenceToDragDropObject.numericIdToBeDragged + ''; if(referenceToDragDropObject.numericIdToBeDragged=='')referenceToDragDropObject.numericIdToBeDragged = this.dragableElement; referenceToDragDropObject.dragDropTimer=0; referenceToDragDropObject.mouse_x = e.clientX; referenceToDragDropObject.mouse_y = e.clientY; referenceToDragDropObject.currentZIndex = referenceToDragDropObject.currentZIndex + 1; referenceToDragDropObject.dragObjCloneArray[referenceToDragDropObject.numericIdToBeDragged].style.zIndex = referenceToDragDropObject.currentZIndex; referenceToDragDropObject.currentEl_allowX = referenceToDragDropObject.dragDropSourcesArray[referenceToDragDropObject.numericIdToBeDragged][2]; referenceToDragDropObject.currentEl_allowY = referenceToDragDropObject.dragDropSourcesArray[referenceToDragDropObject.numericIdToBeDragged][3];
var parentEl = referenceToDragDropObject.dragDropSourcesArray[referenceToDragDropObject.numericIdToBeDragged][4]; referenceToDragDropObject.drag_minX = false; referenceToDragDropObject.drag_minY = false; referenceToDragDropObject.drag_maxX = false; referenceToDragDropObject.drag_maxY = false; if(parentEl){ var obj = document.getElementById(parentEl); if(obj){ referenceToDragDropObject.drag_minX = dhtmlSuiteCommonObj.getLeftPos(obj); referenceToDragDropObject.drag_minY = dhtmlSuiteCommonObj.getTopPos(obj); referenceToDragDropObject.drag_maxX = referenceToDragDropObject.drag_minX + obj.clientWidth; referenceToDragDropObject.drag_maxY = referenceToDragDropObject.drag_minY + obj.clientHeight; } } // Reposition dragable element if(referenceToDragDropObject.dragDropSourcesArray[referenceToDragDropObject.numericIdToBeDragged][1]){ referenceToDragDropObject.dragObjCloneArray[referenceToDragDropObject.numericIdToBeDragged].style.top = dhtmlSuiteCommonObj.getTopPos(referenceToDragDropObject.dragDropSourcesArray[referenceToDragDropObject.numericIdToBeDragged][0]) + 'px'; referenceToDragDropObject.dragObjCloneArray[referenceToDragDropObject.numericIdToBeDragged].style.left = dhtmlSuiteCommonObj.getLeftPos(referenceToDragDropObject.dragDropSourcesArray[referenceToDragDropObject.numericIdToBeDragged][0]) + 'px'; } referenceToDragDropObject.el_x = referenceToDragDropObject.dragObjCloneArray[referenceToDragDropObject.numericIdToBeDragged].style.left.replace('px','')/1; referenceToDragDropObject.el_y = referenceToDragDropObject.dragObjCloneArray[referenceToDragDropObject.numericIdToBeDragged].style.top.replace('px','')/1;
referenceToDragDropObject.__timerDragDropElement();
return false; } // }}} , // {{{ __timerDragDropElement() /** * A small delay from mouse down to drag starts * * @private */ __timerDragDropElement : function() { window.thisRef = this; if(this.dragDropTimer>=0 && this.dragDropTimer<5){ this.dragDropTimer = this.dragDropTimer + 1; setTimeout('window.thisRef.__timerDragDropElement()',2); return; } if(this.dragDropTimer>=5){ if(this.dragObjCloneArray[this.numericIdToBeDragged].style.display=='none'){ this.dragDropSourcesArray[this.numericIdToBeDragged][0].style.visibility = 'hidden'; this.dragObjCloneArray[this.numericIdToBeDragged].style.display = 'block'; this.dragObjCloneArray[this.numericIdToBeDragged].style.visibility = 'visible'; this.dragObjCloneArray[this.numericIdToBeDragged].style.top = dhtmlSuiteCommonObj.getTopPos(this.dragDropSourcesArray[this.numericIdToBeDragged][0]) + 'px'; this.dragObjCloneArray[this.numericIdToBeDragged].style.left = dhtmlSuiteCommonObj.getLeftPos(this.dragDropSourcesArray[this.numericIdToBeDragged][0]) + 'px'; } if(this.dragDropSourcesArray[referenceToDragDropObject.numericIdToBeDragged][5]){ var id1 = this.dragObjCloneArray[this.numericIdToBeDragged].id + ''; var id2 = this.dragDropSourcesArray[this.numericIdToBeDragged][0].id + ''; var string = this.dragDropSourcesArray[referenceToDragDropObject.numericIdToBeDragged][5] + '("' + id1 + '","' + id2 + '")'; eval(string); } } } // }}} , // {{{ __cancelSelectionEvent() /** * Cancel text selection when drag is in progress * * @private */ __cancelSelectionEvent : function() { if(this.dragDropTimer>=0)return false; return true; } // }}} , // {{{ __moveDragableElement() /** * Move dragable element according to mouse position when drag is in process. * * @param Event e = Event object, used to get x and y coordinate of mouse pointer * * @private */ __moveDragableElement : function(e) { if(document.all)e = event; if(referenceToDragDropObject.dragDropTimer<5)return; var dragObj = referenceToDragDropObject.dragObjCloneArray[referenceToDragDropObject.numericIdToBeDragged]; if(referenceToDragDropObject.currentEl_allowX){ var leftPos = (e.clientX - referenceToDragDropObject.mouse_x + referenceToDragDropObject.el_x); if(referenceToDragDropObject.drag_maxX){ var tmpMaxX = referenceToDragDropObject.drag_maxX - dragObj.offsetWidth; if(leftPos > tmpMaxX)leftPos = tmpMaxX if(leftPos < referenceToDragDropObject.drag_minX)leftPos = referenceToDragDropObject.drag_minX; } dragObj.style.left = leftPos + 'px'; } if(referenceToDragDropObject.currentEl_allowY){ var topPos = (e.clientY - referenceToDragDropObject.mouse_y + referenceToDragDropObject.el_y); if(referenceToDragDropObject.drag_maxY){ var tmpMaxY = referenceToDragDropObject.drag_maxY - dragObj.offsetHeight; if(topPos > tmpMaxY)topPos = tmpMaxY; if(topPos < referenceToDragDropObject.drag_minY)topPos = referenceToDragDropObject.drag_minY; } dragObj.style.top = topPos + 'px'; } } // }}} , // {{{ __stop_dragDropElement() /** * Drag process stopped. * Note! In this method "this" refers to the element being dragged. referenceToDragDropObject refers to the dragDropObject. * * @param Event e = Event object, used to get x and y coordinate of mouse pointer * * @private */ __stop_dragDropElement : function(e) { if(referenceToDragDropObject.dragDropTimer<5)return; if(document.all)e = event; // Dropped on which element if (e.target) dropDestination = e.target; else if (e.srcElement) dropDestination = e.srcElement; if (dropDestination.nodeType == 3) // defeat Safari bug dropDestination = dropDestination.parentNode; var leftPosMouse = e.clientX + Math.max(document.body.scrollLeft,document.documentElement.scrollLeft); var topPosMouse = e.clientY + Math.max(document.body.scrollTop,document.documentElement.scrollTop); if(!referenceToDragDropObject.dragDropTargetArray)referenceToDragDropObject.dragDropTargetArray = new Array(); // Loop through drop targets and check if the coordinate of the mouse is over it. If it is, call specified drop function. for(var no=0;no<referenceToDragDropObject.dragDropTargetArray.length;no++){ var leftPosEl = dhtmlSuiteCommonObj.getLeftPos(referenceToDragDropObject.dragDropTargetArray[no][0]); var topPosEl = dhtmlSuiteCommonObj.getTopPos(referenceToDragDropObject.dragDropTargetArray[no][0]); var widthEl = referenceToDragDropObject.dragDropTargetArray[no][0].offsetWidth; var heightEl = referenceToDragDropObject.dragDropTargetArray[no][0].offsetHeight; if(leftPosMouse > leftPosEl && leftPosMouse < (leftPosEl + widthEl) && topPosMouse > topPosEl && topPosMouse < (topPosEl + heightEl)){ if(referenceToDragDropObject.dragDropTargetArray[no][1])eval(referenceToDragDropObject.dragDropTargetArray[no][1] + '("' + referenceToDragDropObject.dragDropSourcesArray[referenceToDragDropObject.numericIdToBeDragged][0].id + '","' + referenceToDragDropObject.dragDropTargetArray[no][0].id + '",' + e.clientX + ',' + e.clientY + ')'); break; } } if(referenceToDragDropObject.dragDropSourcesArray[referenceToDragDropObject.numericIdToBeDragged][1]){ referenceToDragDropObject.__slideElementBackIntoItsOriginalPosition(referenceToDragDropObject.numericIdToBeDragged); } // Variable cleanup after drop referenceToDragDropObject.dragDropTimer = -1; referenceToDragDropObject.numericIdToBeDragged = false; } // }}} , // {{{ __slideElementBackIntoItsOriginalPosition() /** * Slide an item back to it's original position * * @param Integer numId = numeric index of currently dragged element * * @private */ __slideElementBackIntoItsOriginalPosition : function(numId) { // Coordinates current element position var currentX = this.dragObjCloneArray[numId].style.left.replace('px','')/1; var currentY = this.dragObjCloneArray[numId].style.top.replace('px','')/1; // Coordinates - where it should slide to var targetX = dhtmlSuiteCommonObj.getLeftPos(referenceToDragDropObject.dragDropSourcesArray[numId][0]); var targetY = dhtmlSuiteCommonObj.getTopPos(referenceToDragDropObject.dragDropSourcesArray[numId][0]);; if(this.moveBackBySliding){ // Call the step by step slide method this.__processSlide(numId,currentX,currentY,targetX,targetY); }else{ this.dragObjCloneArray[numId].style.display='none'; this.dragDropSourcesArray[numId][0].style.visibility = 'visible'; } } // }}} , // {{{ __processSlide() /** * Move the element step by step in this method * * @param Int numId = numeric index of currently dragged element * @param Int currentX = Elements current X position * @param Int currentY = Elements current Y position * @param Int targetX = Destination X position, i.e. where the element should slide to * @param Int targetY = Destination Y position, i.e. where the element should slide to * * @private */ __processSlide : function(numId,currentX,currentY,targetX,targetY) { // Find slide x value var slideX = Math.round(Math.abs(Math.max(currentX,targetX) - Math.min(currentX,targetX)) / 10); // Find slide y value var slideY = Math.round(Math.abs(Math.max(currentY,targetY) - Math.min(currentY,targetY)) / 10); if(slideY<3 && Math.abs(slideX)<10)slideY = 3; // 3 is minimum slide value if(slideX<3 && Math.abs(slideY)<10)slideX = 3; // 3 is minimum slide value if(currentX > targetX) slideX*=-1; // If current x is larger than target x, make slide value negative<br> if(currentY > targetY) slideY*=-1; // If current y is larger than target x, make slide value negative // Update currentX and currentY currentX = currentX + slideX; currentY = currentY + slideY;
// If currentX or currentY is close to targetX or targetY, make currentX equal to targetX(or currentY equal to targetY) if(Math.max(currentX,targetX) - Math.min(currentX,targetX) < 4)currentX = targetX; if(Math.max(currentY,targetY) - Math.min(currentY,targetY) < 4)currentY = targetY;
// Update CSS position(left and top) this.dragObjCloneArray[numId].style.left = currentX + 'px'; this.dragObjCloneArray[numId].style.top = currentY + 'px'; // currentX different than targetX or currentY different than targetY, call this function in again in 5 milliseconds if(currentX!=targetX || currentY != targetY){ window.thisRef = this; // Reference to this dragdrop object setTimeout('window.thisRef.__processSlide("' + numId + '",' + currentX + ',' + currentY + ',' + targetX + ',' + targetY + ')',5); }else{ // Slide completed. Make absolute positioned element invisible and original element visible this.dragObjCloneArray[numId].style.display='none'; this.dragDropSourcesArray[numId][0].style.visibility = 'visible'; } } }
/* General CSS for the demos of DHTMLSuite */ body{ font-family: Trebuchet MS, Lucida Sans Unicode, Arial, sans-serif; font-size:0.8em; }
Last edited: 2010-12-14 17:52:38 +0100 (CET)
View full thread CGI-Skript mit Drag & Drop Funktion
|