\r
html, body { height: 100%; }\r
#main { height: 100%; }\r
-.drag { position: relative; margin: 10px; padding: 10px; border: 3px solid black; cursor: move; width: 200px; height: 40px; background: #eef; }\r
+\r
+#foo { position: relative; margin: 10px; padding: 10px; border: 3px solid gray; cursor: move; width: 200px; height: 100px; background: #eef; text-align: center; }\r
+.ui-draggable .msg-missing-class { display: none !important; background: red; color: white; font-weight: bold; }\r
+.ui-draggable .msg-enabled { display: block; }\r
+.ui-draggable .msg-disabled { display: none; }\r
+.ui-draggable-disabled .msg-enabled { display: none !important; }\r
+.ui-draggable-disabled .msg-disabled { display: block !important; }\r
\r
</style>\r
\r
<script type="text/javascript">\r
$(function() {\r
\r
- $(".drag").draggable().testMouse({\r
- speed: "fast"\r
- });\r
+ var speed = "slow"\r
\r
var queue;\r
var start = function() {\r
- queue = tests.slice(); // clone\r
+ queue = tests.slice().reverse(); // clone\r
$("#status").text("Running...");\r
nextTest();\r
}\r
var stop = function() {\r
$("#status").text("Ready");\r
+ teardown();\r
}\r
-\r
+ \r
var tests = [];\r
var nextTest = function() {\r
if (queue.length) {\r
- queue.pop().apply();\r
+ var nTest = queue.pop();\r
+ teardown(function() {\r
+ setupAndRun(nTest);\r
+ });\r
} else {\r
stop();\r
}\r
}\r
-\r
+ \r
+ var num = 0;\r
+ \r
var addTest = function(fn) {\r
- tests.unshift(fn);\r
+ num += 1;\r
+ tests.push({\r
+ num: num,\r
+ fn: fn\r
+ });\r
}\r
-\r
- addTest(function() {\r
- $("#d1").testMouse("drag", 100, 0, nextTest);\r
- });\r
\r
- addTest(function() {\r
- $("#d2").testMouse("drag", 100, 0, nextTest);\r
- });\r
-\r
- addTest(function() {\r
- $("#d3").testMouse("drag", 100, 0, nextTest);\r
- });\r
-\r
- $('#begin').click(function(e) {\r
+ var setupAndRun = function(nTest) {\r
+ $('#testnum').text(nTest.num);\r
+ $('#sandbox').hide().append('<div id="foo">' + \r
+ '<div class="msg-missing-class">THIS TEXT SHOULD NOT BE VISIBLE</div>' +\r
+ '<div class="msg-enabled">enabled</div>' +\r
+ '<div class="msg-disabled">disabled</div>' +\r
+ '</div>');\r
+ $('#foo').testMouse({\r
+ speed: speed,\r
+ complete: nextTest\r
+ });\r
+ $('#sandbox').show();\r
+ nTest.fn.apply(nTest.fn);\r
+ }\r
+ \r
+ var teardown = function(fn) {\r
+ $('#sandbox').hide();\r
+ $('#foo').remove();\r
+ if ($.isFunction(fn)) fn.apply();\r
+ }\r
+ //1\r
+ addTest(function() { $("#foo").draggable().testMouse("drag", 100, 100); });\r
+ //2\r
+ addTest(function() { $("#foo").draggable({ disabled: true }).testMouse("drag", 100, 100); });\r
+ addTest(function() { $("#foo").draggable({ disabled: false }).testMouse("drag", 100, 100); });\r
+ //4\r
+ addTest(function() { $("#foo").draggable().draggable('disable').testMouse("drag", 100, 100); });\r
+ addTest(function() { $("#foo").draggable().draggable('enable').testMouse("drag", 100, 100); });\r
+ //6\r
+ addTest(function() { $("#foo").draggable().draggable('enable').draggable('disable').testMouse("drag", 100, 100); });\r
+ addTest(function() { $("#foo").draggable().draggable('disable').draggable('enable').testMouse("drag", 100, 100); });\r
+ //8\r
+ addTest(function() { $("#foo").draggable({ disabled: false }).draggable('disable').testMouse("drag", 100, 100); });\r
+ addTest(function() { $("#foo").draggable({ disabled: true }).draggable('enable').testMouse("drag", 100, 100); });\r
+\r
+ $('#begin').click(function() {\r
start();\r
});\r
\r
\r
<h1>jQuery UI Draggable - Automated Test</h1>\r
\r
- Status: <span id="status">Ready</span>\r
-\r
- <div style="height: 3em;"><button id="begin">Run Test</button></div>\r
-\r
- <div class="drag" id="d1">\r
- Drag 1\r
+ <div>\r
+ Status: <span id="status">Ready</span>\r
</div>\r
\r
- <div class="drag" id="d2">\r
- Drag 2\r
+ <div>\r
+ Test: <span id="testnum"></span>\r
</div>\r
\r
- <div class="drag" id="d3">\r
- Drag 3\r
+ <div style="height: 3em;"><button id="begin">Run Test</button></div>\r
+\r
+ <div id="sandbox">\r
+ \r
</div>\r
\r
</div>\r
* Revision: $Id: $\r
*/\r
;(function($) {\r
+ \r
+ var mouseX = 0;\r
+ var mouseY = 0;\r
\r
$.widget("ui.testMouse", {\r
- mouseX: 0,\r
- mouseY: 0,\r
trackMouse: function() {},\r
init: function() {\r
var self = this;\r
this.trackMouse = function(e) {\r
if (e.isTrusted !== false) {\r
- self.mouseX = e.pageX;\r
- self.mouseY = e.pageY;\r
+ mouseX = e.pageX;\r
+ mouseY = e.pageY;\r
}\r
}\r
$(document).bind("mousemove", this.trackMouse);\r
up: function(x, y) {\r
this.dispatch("mouseup", x, y);\r
},\r
- drag: function(dx, dy, complete) {\r
+ drag: function(dx, dy) {\r
var self = this; \r
\r
var center = this.center();\r
\r
var testStart = function() {\r
self.element.bind("mouseover", updateCursor).bind("mouseout", resetCursor);\r
- fakemouse.appendTo('body').css({ position: 'absolute', left: self.mouseX, top: self.mouseY, zIndex: 5000 });\r
- realmouse.appendTo('body').css({ position: 'absolute', left: self.mouseX, top: self.mouseY, zIndex: 5000, opacity: 0.1 });\r
+ fakemouse.appendTo('body').css({ position: 'absolute', left: mouseX, top: mouseY, zIndex: 5000 });\r
+ realmouse.appendTo('body').css({ position: 'absolute', left: mouseX, top: mouseY, zIndex: 5000, opacity: 0.1 });\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
var testStop = function() {\r
self.element.unbind("mouseover", updateCursor).unbind("mouseout", resetCursor);\r
mousescreen.remove();\r
- self.mouseX = realmouse.css("left");\r
- self.mouseY = realmouse.css("top");\r
+ mouseX = realmouse.css("left");\r
+ mouseY = realmouse.css("top");\r
realmouse.remove();\r
fakemouse.remove();\r
- ($.isFunction(complete) && complete.apply());\r
+ self.options.complete.apply();\r
}\r
\r
testStart();\r