]> source.dussan.org Git - jquery-ui.git/commitdiff
tests automated draggable - some refactoring
authorRichard Worth <rdworth@gmail.com>
Sat, 24 May 2008 18:49:23 +0000 (18:49 +0000)
committerRichard Worth <rdworth@gmail.com>
Sat, 24 May 2008 18:49:23 +0000 (18:49 +0000)
ui/tests/autodrag.html

index df62c67d0e06c812e61d10727381d9e80e13be8a..50ce36d3ae55a9618e3abb9695c731d6456e33b7 100644 (file)
@@ -20,30 +20,19 @@ html, body { height: 100%; }
 </style>\r
 \r
 <script type="text/javascript">\r
-$(function() {\r
 \r
-       var fakemouse = $('<img src="images/cursor.png" id="fakemouse>').appendTo('body')\r
-               .css({ opacity: 0.0 })\r
-               .hide();\r
+var mouseX = 0, mouseY = 0;\r
 \r
-       var realmouse = $('<img src="images/cursor.png" id="realmouse>').appendTo('body')\r
-               .css({ opacity: 0.2 })\r
-               .hide()\r
-               .mousedown(function() { return false; });\r
-       \r
-       $(document).mousemove(function(e) {\r
-               if (e.originalEvent && e.originalEvent.isTrusted) {\r
-                       realmouse.css({\r
-                               left: e.pageX,\r
-                               top: e.pageY\r
-                       });\r
-               }\r
-       });\r
+$(function() {\r
 \r
+$(document).mousemove(function(e) {\r
+       if (e.originalEvent && e.originalEvent.isTrusted) {\r
+               mouseX = e.pageX;\r
+               mouseY = e.pageY;\r
+       }\r
 });\r
-</script>\r
 \r
-<script type="text/javascript">\r
+});\r
 \r
 function testMouse(type, el, x, y) {\r
        var evt = document.createEvent("MouseEvents");\r
@@ -69,25 +58,36 @@ function draggableTest(el, dx, dy) {
        var left = center.x;\r
        var top = center.y;\r
 \r
-       var lastX = null;\r
+       var fakemouse = $('<img src="images/cursor.png" id="fakemouse>');\r
+       var realmouse = $('<img src="images/cursor.png" id="realmouse>');\r
+       var mousescreen = $('<div id="mousescreen"/>');\r
 \r
        var testStart = function() {\r
-               $(el).data("_ignoreTrusted.draggable", true);\r
+               fakemouse.appendTo('body').css({ left: mouseX, top: mouseY, opacity: 1.0 });\r
+               realmouse.appendTo('body').css({ left: mouseX, top: mouseY, opacity: 0.2 })\r
+                       .mousedown(function() { return false; });\r
+               mousescreen.appendTo('body').css({ width: '100%', height: '100%', position: 'absolute', top: 0, left: 0, zIndex: 5000 })\r
+                       .mousemove(function(e) { realmouse.css({ left: e.pageX, top: e.pageY }); return false; })\r
+                       .mousedown(function() { return false; })\r
+                       .mouseup(function() { return false; })\r
                $("body").addClass("testing");\r
        }\r
        var testStop = function() {\r
                $("body").removeClass("testing");\r
-               $(el).data("_ignoreTrusted.draggable", false);  \r
+               mousescreen.remove();\r
+               realmouse.remove();\r
+               fakemouse.remove();\r
        }\r
 \r
        testStart();\r
 \r
-       $('#fakemouse').css({ left: realmouse.css("left"), top: realmouse.css("top") })\r
-               .animate({ left: left, top: top, opacity: 1.0 }, "slow", function() {\r
+       var lastX = null;\r
+       fakemouse\r
+               .animate({ left: left, top: top, opacity: 1.0 }, "fast", function() {\r
                        testMouseDown(el, left, top);\r
                })\r
                .animate({ left: left + dx, top: top + dy }, {\r
-                       speed: "slow",\r
+                       speed: "fast",\r
                        easing: "swing",\r
                        step: function (xory) {\r
                                if (!lastX) { lastX = xory; }\r
@@ -95,8 +95,8 @@ function draggableTest(el, dx, dy) {
                        },\r
                        complete: function() {\r
                                testMouseUp(el, 0, 0);\r
-                               $(this).animate({ left: realmouse.css("left"), top: realmouse.css("top"), opacity: 0 }, {\r
-                                       speed: "slow",\r
+                               $(this).animate({ left: realmouse.css("left"), top: realmouse.css("top"), opacity: 1.0 }, {\r
+                                       speed: "fast",\r
                                        complete: function() {\r
                                                testStop();\r
                                        }\r