mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
tests automated draggable - some refactoring
This commit is contained in:
parent
26b2908040
commit
813472aa8f
@ -20,30 +20,19 @@ html, body { height: 100%; }
|
|||||||
</style>
|
</style>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
var mouseX = 0, mouseY = 0;
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
|
|
||||||
var fakemouse = $('<img src="images/cursor.png" id="fakemouse>').appendTo('body')
|
$(document).mousemove(function(e) {
|
||||||
.css({ opacity: 0.0 })
|
if (e.originalEvent && e.originalEvent.isTrusted) {
|
||||||
.hide();
|
mouseX = e.pageX;
|
||||||
|
mouseY = e.pageY;
|
||||||
var realmouse = $('<img src="images/cursor.png" id="realmouse>').appendTo('body')
|
}
|
||||||
.css({ opacity: 0.2 })
|
});
|
||||||
.hide()
|
|
||||||
.mousedown(function() { return false; });
|
|
||||||
|
|
||||||
$(document).mousemove(function(e) {
|
|
||||||
if (e.originalEvent && e.originalEvent.isTrusted) {
|
|
||||||
realmouse.css({
|
|
||||||
left: e.pageX,
|
|
||||||
top: e.pageY
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
</script>
|
|
||||||
|
|
||||||
<script type="text/javascript">
|
|
||||||
|
|
||||||
function testMouse(type, el, x, y) {
|
function testMouse(type, el, x, y) {
|
||||||
var evt = document.createEvent("MouseEvents");
|
var evt = document.createEvent("MouseEvents");
|
||||||
@ -69,25 +58,36 @@ function draggableTest(el, dx, dy) {
|
|||||||
var left = center.x;
|
var left = center.x;
|
||||||
var top = center.y;
|
var top = center.y;
|
||||||
|
|
||||||
var lastX = null;
|
var fakemouse = $('<img src="images/cursor.png" id="fakemouse>');
|
||||||
|
var realmouse = $('<img src="images/cursor.png" id="realmouse>');
|
||||||
|
var mousescreen = $('<div id="mousescreen"/>');
|
||||||
|
|
||||||
var testStart = function() {
|
var testStart = function() {
|
||||||
$(el).data("_ignoreTrusted.draggable", true);
|
fakemouse.appendTo('body').css({ left: mouseX, top: mouseY, opacity: 1.0 });
|
||||||
|
realmouse.appendTo('body').css({ left: mouseX, top: mouseY, opacity: 0.2 })
|
||||||
|
.mousedown(function() { return false; });
|
||||||
|
mousescreen.appendTo('body').css({ width: '100%', height: '100%', position: 'absolute', top: 0, left: 0, zIndex: 5000 })
|
||||||
|
.mousemove(function(e) { realmouse.css({ left: e.pageX, top: e.pageY }); return false; })
|
||||||
|
.mousedown(function() { return false; })
|
||||||
|
.mouseup(function() { return false; })
|
||||||
$("body").addClass("testing");
|
$("body").addClass("testing");
|
||||||
}
|
}
|
||||||
var testStop = function() {
|
var testStop = function() {
|
||||||
$("body").removeClass("testing");
|
$("body").removeClass("testing");
|
||||||
$(el).data("_ignoreTrusted.draggable", false);
|
mousescreen.remove();
|
||||||
|
realmouse.remove();
|
||||||
|
fakemouse.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
testStart();
|
testStart();
|
||||||
|
|
||||||
$('#fakemouse').css({ left: realmouse.css("left"), top: realmouse.css("top") })
|
var lastX = null;
|
||||||
.animate({ left: left, top: top, opacity: 1.0 }, "slow", function() {
|
fakemouse
|
||||||
|
.animate({ left: left, top: top, opacity: 1.0 }, "fast", function() {
|
||||||
testMouseDown(el, left, top);
|
testMouseDown(el, left, top);
|
||||||
})
|
})
|
||||||
.animate({ left: left + dx, top: top + dy }, {
|
.animate({ left: left + dx, top: top + dy }, {
|
||||||
speed: "slow",
|
speed: "fast",
|
||||||
easing: "swing",
|
easing: "swing",
|
||||||
step: function (xory) {
|
step: function (xory) {
|
||||||
if (!lastX) { lastX = xory; }
|
if (!lastX) { lastX = xory; }
|
||||||
@ -95,8 +95,8 @@ function draggableTest(el, dx, dy) {
|
|||||||
},
|
},
|
||||||
complete: function() {
|
complete: function() {
|
||||||
testMouseUp(el, 0, 0);
|
testMouseUp(el, 0, 0);
|
||||||
$(this).animate({ left: realmouse.css("left"), top: realmouse.css("top"), opacity: 0 }, {
|
$(this).animate({ left: realmouse.css("left"), top: realmouse.css("top"), opacity: 1.0 }, {
|
||||||
speed: "slow",
|
speed: "fast",
|
||||||
complete: function() {
|
complete: function() {
|
||||||
testStop();
|
testStop();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user