moved (still experimental) test automation files to experimental branch
@ -1,156 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>jQuery UI - Automated Tests</title>
|
||||
|
||||
<script type="text/javascript" src="../jquery-1.2.6.js"></script>
|
||||
<script type="text/javascript" src="../ui/ui.core.js"></script>
|
||||
<script type="text/javascript" src="../ui/ui.draggable.js"></script>
|
||||
<script type="text/javascript" src="../ui/ui.selectable.js"></script>
|
||||
|
||||
<script type="text/javascript" src="simulate/jquery.simulate.js"></script>
|
||||
<script type="text/javascript" src="ui.testmouse.js"></script>
|
||||
|
||||
<style type="text/css">
|
||||
|
||||
html, body { height: 100%; }
|
||||
#main { height: 100%; }
|
||||
|
||||
#foo { position: relative; margin: 10px; padding: 10px; border: 3px solid gray; width: 200px; height: 200px; background: #eef; text-align: center; }
|
||||
#foo * { margin: 4px; }
|
||||
.ui-draggable .msg-missing-class { display: none !important; background: red; color: white; font-weight: bold; }
|
||||
.ui-draggable .msg-enabled { display: block; }
|
||||
.ui-draggable .msg-disabled { display: none; }
|
||||
.ui-draggable-disabled .msg-enabled { display: none !important; }
|
||||
.ui-draggable-disabled .msg-disabled { display: block !important; }
|
||||
.ui-selectable .msg-missing-class { display: none !important; background: red; color: white; font-weight: bold; }
|
||||
.ui-selectable .msg-enabled { display: block; }
|
||||
.ui-selectable .msg-disabled { display: none; }
|
||||
.ui-selectable-disabled .msg-enabled { display: none !important; }
|
||||
.ui-selectable-disabled .msg-disabled { display: block !important; }
|
||||
//.ui-selectee { border: 1px solid white; }
|
||||
.ui-selecting { background: Highlight; color: HighlightText; outline: 1px dotted white; }
|
||||
.ui-selected { background: Highlight; color: HighlightText; outline: 1px dotted black; }
|
||||
|
||||
</style>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(function() {
|
||||
|
||||
var speed = "fast";
|
||||
|
||||
var queue;
|
||||
var start = function() {
|
||||
queue = tests.slice().reverse(); // clone
|
||||
$("#status").text("Running...");
|
||||
nextTest();
|
||||
}
|
||||
var stop = function() {
|
||||
$("#status").text("Ready");
|
||||
teardown();
|
||||
}
|
||||
|
||||
var tests = [];
|
||||
var nextTest = function() {
|
||||
if (queue.length) {
|
||||
var nTest = queue.pop();
|
||||
teardown(function() {
|
||||
setupAndRun(nTest);
|
||||
});
|
||||
} else {
|
||||
stop();
|
||||
}
|
||||
}
|
||||
|
||||
var num = 0;
|
||||
|
||||
var addTest = function(fn) {
|
||||
num += 1;
|
||||
tests.push({
|
||||
num: num,
|
||||
fn: fn
|
||||
});
|
||||
}
|
||||
|
||||
var setupAndRun = function(nTest) {
|
||||
$('#testnum').text(nTest.num);
|
||||
$('#sandbox').hide()
|
||||
.append('<ul id="foo">' +
|
||||
'<li class="msg-missing-class">THIS TEXT SHOULD NOT BE VISIBLE</li>' +
|
||||
'<li class="msg-enabled">enabled</li>' +
|
||||
'<li class="msg-disabled">disabled</li>' +
|
||||
'<li>Item 2</li>' +
|
||||
'<li>Item 3</li>' +
|
||||
'<li>Item 4</li>' +
|
||||
'<li>Item 5</li>' +
|
||||
'<li>Item 6</li>' +
|
||||
'<li>Item 7</li>' +
|
||||
'<li>Item 8</li>' +
|
||||
'</ul>')
|
||||
$('#foo').testMouse({
|
||||
speed: speed,
|
||||
complete: nextTest
|
||||
});
|
||||
$('#sandbox').show();
|
||||
nTest.fn.apply(nTest.fn);
|
||||
}
|
||||
|
||||
var teardown = function(fn) {
|
||||
$('#sandbox').hide();
|
||||
$('#foo').remove();
|
||||
if ($.isFunction(fn)) fn.apply();
|
||||
}
|
||||
var plugin = "draggable";
|
||||
//plugin = "selectable"
|
||||
var testFn = "testMouse";
|
||||
var testArgs = ["drag", 40, 50];
|
||||
//1
|
||||
addTest(function() { $("#foo")[plugin]()[testFn].apply($("#foo"), testArgs); });
|
||||
//2
|
||||
addTest(function() { $("#foo")[plugin]({ disabled: true })[testFn].apply($("#foo"), testArgs); });
|
||||
addTest(function() { $("#foo")[plugin]({ disabled: false })[testFn].apply($("#foo"), testArgs); });
|
||||
//4
|
||||
addTest(function() { $("#foo")[plugin]()[plugin]('disable')[testFn].apply($("#foo"), testArgs); });
|
||||
addTest(function() { $("#foo")[plugin]()[plugin]('enable')[testFn].apply($("#foo"), testArgs); });
|
||||
//6
|
||||
addTest(function() { $("#foo")[plugin]()[plugin]('enable')[plugin]('disable')[testFn].apply($("#foo"), testArgs); });
|
||||
addTest(function() { $("#foo")[plugin]()[plugin]('disable')[plugin]('enable')[testFn].apply($("#foo"), testArgs); });
|
||||
//8
|
||||
addTest(function() { $("#foo")[plugin]({ disabled: false })[plugin]('disable')[testFn].apply($("#foo"), testArgs); });
|
||||
addTest(function() { $("#foo")[plugin]({ disabled: true })[plugin]('enable')[testFn].apply($("#foo"), testArgs); });
|
||||
//10
|
||||
addTest(function() { $("#foo")[plugin]({ disabled: false }).data('disabled.' + plugin, true)[testFn].apply($("#foo"), testArgs); });
|
||||
addTest(function() { $("#foo")[plugin]({ disabled: true }).data('disabled.' + plugin, false)[testFn].apply($("#foo"), testArgs); });
|
||||
|
||||
$('#begin').click(function() {
|
||||
start();
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="main">
|
||||
|
||||
<h1>jQuery UI - Automated Tests</h1>
|
||||
|
||||
<div>
|
||||
Status: <span id="status">Ready</span>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
Test: <span id="testnum"></span>
|
||||
</div>
|
||||
|
||||
<div style="height: 3em;"><button id="begin">Run Test</button></div>
|
||||
|
||||
<div id="sandbox">
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
Before Width: | Height: | Size: 851 B |
Before Width: | Height: | Size: 413 B |
Before Width: | Height: | Size: 851 B |
Before Width: | Height: | Size: 861 B |
Before Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 710 B |
Before Width: | Height: | Size: 871 B |
Before Width: | Height: | Size: 836 B |
Before Width: | Height: | Size: 2.2 KiB |
Before Width: | Height: | Size: 872 B |
Before Width: | Height: | Size: 824 B |
Before Width: | Height: | Size: 541 B |
Before Width: | Height: | Size: 871 B |
Before Width: | Height: | Size: 824 B |
Before Width: | Height: | Size: 836 B |
Before Width: | Height: | Size: 486 B |
Before Width: | Height: | Size: 861 B |
Before Width: | Height: | Size: 401 B |
Before Width: | Height: | Size: 341 B |
Before Width: | Height: | Size: 401 B |
Before Width: | Height: | Size: 390 B |
Before Width: | Height: | Size: 689 B |
Before Width: | Height: | Size: 651 B |
Before Width: | Height: | Size: 434 B |
Before Width: | Height: | Size: 440 B |
Before Width: | Height: | Size: 2.2 KiB |
Before Width: | Height: | Size: 872 B |
Before Width: | Height: | Size: 452 B |
Before Width: | Height: | Size: 675 B |
Before Width: | Height: | Size: 434 B |
Before Width: | Height: | Size: 452 B |
Before Width: | Height: | Size: 440 B |
Before Width: | Height: | Size: 436 B |
Before Width: | Height: | Size: 390 B |
Before Width: | Height: | Size: 724 B |
Before Width: | Height: | Size: 304 B |
Before Width: | Height: | Size: 724 B |
Before Width: | Height: | Size: 714 B |
Before Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 722 B |
Before Width: | Height: | Size: 985 B |
Before Width: | Height: | Size: 2.2 KiB |
Before Width: | Height: | Size: 2.8 KiB |
Before Width: | Height: | Size: 993 B |
Before Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 722 B |
Before Width: | Height: | Size: 993 B |
Before Width: | Height: | Size: 985 B |
Before Width: | Height: | Size: 258 B |
Before Width: | Height: | Size: 714 B |
Before Width: | Height: | Size: 1.3 KiB |
@ -1,347 +0,0 @@
|
||||
/* Copyright (c) 2007 Eduardo Lundgren (eduardolundgren@gmail.com)
|
||||
* Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
|
||||
* and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
|
||||
*
|
||||
* Version: 0.1a
|
||||
* Date: May, 2008
|
||||
* Requires jQuery 1.2.x+
|
||||
* Docs: http://docs.jquery.com/Plugins/userAction
|
||||
* Greetings: Richard Worth
|
||||
*/
|
||||
|
||||
;(function($) {
|
||||
|
||||
$.fn.extend({
|
||||
userAction: function(type) {
|
||||
var args = arguments, opts = {}, a1 = args[1], a2 = args[2];
|
||||
|
||||
// transfer center offset
|
||||
if (a1 && a1.length) {
|
||||
opts.center = [a1[0], a1[1]];
|
||||
}
|
||||
// set x and y
|
||||
else if (typeof a1 == StringPool.NUMBER) {
|
||||
opts.x = a1; opts.y = a2;
|
||||
}
|
||||
// extend options
|
||||
else {
|
||||
$.extend(opts, a1);
|
||||
}
|
||||
|
||||
return this.each(function() {
|
||||
new $.userAction(this, type, opts);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$.userAction = function(el, type, options) {
|
||||
this.type = type;
|
||||
this.options = $.extend({}, $.userAction.defaults, options || {});
|
||||
this.target = $(this.options.target || el)[0];
|
||||
|
||||
var self = this, o = this.options, c = o.center, center = { x: 0, y: 0 };
|
||||
|
||||
if (!o.x && !o.y) {
|
||||
center = this.findCenter(
|
||||
c && c.length ? c : [0, 0]
|
||||
)
|
||||
}
|
||||
|
||||
// if x and y not set, get the center of the element
|
||||
o.x = o.x || center.x; o.y = o.y || center.y;
|
||||
|
||||
var EVENT_DEFAULT = {
|
||||
target: this.target,
|
||||
view: window,
|
||||
bubbles: o.bubbles || true,
|
||||
cancelable: o.cancelable || false,
|
||||
ctrlKey: o.ctrlKey || false,
|
||||
altKey: o.altKey || false,
|
||||
shiftKey: o.shiftKey || false,
|
||||
metaKey: o.metaKey || false
|
||||
};
|
||||
|
||||
// Simulating drag and drop event
|
||||
if (/^drag$/i.test(type)) {
|
||||
var self = this, t = this.target, queue = $.data(t, StringPool.DATA_QUEUE),
|
||||
data = [options.dx || options.x, options.dy || options.y, this];
|
||||
|
||||
var fire = function() {
|
||||
self.drag(options.dx || options.x, options.dy || options.y);
|
||||
};
|
||||
|
||||
if (/^sync$/i.test(o.speed)) {
|
||||
fire(); return;
|
||||
}
|
||||
|
||||
if (!queue) {
|
||||
$.data(t, StringPool.DATA_QUEUE, [data]); fire(); return;
|
||||
}
|
||||
// queuing drags...
|
||||
if (queue && queue.length) {
|
||||
queue.push(data);
|
||||
}
|
||||
// if drag, stop here.
|
||||
return;
|
||||
}
|
||||
|
||||
var isMouse = /^mouse(over|out|down|up|move)|(dbl)?click$/i.test(type),
|
||||
isKeyboard = /^textevent|key(up|down|press)$/i.test(type),
|
||||
|
||||
EVT = isMouse ?
|
||||
$.extend({}, EVENT_DEFAULT, {
|
||||
clientX: o.x, clientY: o.y,
|
||||
screenX: o.screenX || 0, screenY: o.screenY || 0,
|
||||
relatedTarget: $(o.relatedTarget)[0] || null, detail: 0,
|
||||
button: o.button || ($.browser.msie ? 1 : 0), isTrusted: false
|
||||
}) :
|
||||
$.extend({}, EVENT_DEFAULT, {
|
||||
keyCode: o.keyCode || 0, charCode: o.charCode || 0
|
||||
});
|
||||
|
||||
// avoid e.type == undefined before dispatchment
|
||||
EVT.type = type;
|
||||
|
||||
if (o.before) o.before.apply(this.target, [$.event.fix(EVT), o.x, o.y, this]);
|
||||
|
||||
// check event type for mouse events
|
||||
if (isMouse) {
|
||||
// simulating mouse event
|
||||
EVT = this.mouseEvent(EVT)
|
||||
}
|
||||
|
||||
// check event type for key events
|
||||
if (isKeyboard) {
|
||||
// simulating keuboard event
|
||||
EVT = this.keyboardEvent(EVT);
|
||||
}
|
||||
|
||||
if (o.after) o.after.apply(this.target, [$.event.fix(EVT), o.x, o.y, this]);
|
||||
};
|
||||
|
||||
$.extend($.userAction.prototype, {
|
||||
|
||||
down: function(target) {
|
||||
$(target).userAction(StringPool.MOUSEOVER).userAction(StringPool.MOUSEDOWN)
|
||||
.userAction(StringPool.MOUSEMOVE);
|
||||
},
|
||||
|
||||
up: function(target) {
|
||||
$(target).userAction(StringPool.MOUSEUP).userAction(StringPool.MOUSEOUT);
|
||||
},
|
||||
|
||||
move: function(target, x, y, after) {
|
||||
$(target).userAction(StringPool.MOUSEMOVE, { x: x, y: y, after: after });
|
||||
},
|
||||
|
||||
drag: function(dx, dy) {
|
||||
// drag helper function, thanks Richard Worth's testmouse api.
|
||||
var self = this, o = this.options, center = this.findCenter(),
|
||||
target = $(this.target), lastx = center.x, lasty = center.y,
|
||||
fake = $(StringPool.FAKE_CURSOR_EXP),
|
||||
speed = o.speed || StringPool.SLOW,
|
||||
easing = o.easing || StringPool.SWING;
|
||||
|
||||
var complete = function() {
|
||||
// fire complete or after cb
|
||||
if (o.after||o.complete) (o.after||o.complete).apply(self.target, [o, self]);
|
||||
};
|
||||
|
||||
// drag synchronously
|
||||
if (/^sync$/i.test(o.speed)) {
|
||||
self.down(target);
|
||||
|
||||
var mdx = Math.abs(dx)||0, mdy = Math.abs(dy)||0, range = Math.max(mdx, mdy),
|
||||
sx = dx/mdx||1, sy = dy/mdy||1;
|
||||
|
||||
for (var dt = 1; dt <= range; dt++) {
|
||||
var x = center.x + sx*(dt <= mdx ? dt : 0), y = center.y + sy*(dt <= mdy ? dt : 0);
|
||||
this.move(target, x, y, o.drag);
|
||||
}
|
||||
self.up(target);
|
||||
complete();
|
||||
return;
|
||||
}
|
||||
|
||||
// drag asynchronously - animated
|
||||
fake = fake.size() ? fake :
|
||||
$(StringPool.FAKE_CURSOR_DIV)
|
||||
.css({ position: StringPool.ABSOLUTE }).appendTo(document.body);
|
||||
|
||||
fake
|
||||
.animate({ left: center.x, top: center.y }, speed, easing, function(){
|
||||
self.down(target);
|
||||
})
|
||||
.animate({ left: center.x + (dx||0), top: center.y + (dy||0) }, {
|
||||
speed: speed,
|
||||
easing: easing,
|
||||
step: function(i, anim) {
|
||||
lastx = anim.prop == StringPool.LEFT ? i : lastx;
|
||||
lasty = anim.prop == StringPool.TOP ? i : lasty;
|
||||
self.move(target, lastx, lasty, o.drag);
|
||||
},
|
||||
complete: function() {
|
||||
|
||||
self.up(target);
|
||||
|
||||
// remove fake cursor
|
||||
$(this).remove();
|
||||
|
||||
complete();
|
||||
|
||||
// trigger drag queue
|
||||
var queue = $.data(self.target, StringPool.DATA_QUEUE);
|
||||
if (queue) queue.shift();
|
||||
|
||||
if (queue && queue[0]) {
|
||||
// trigger drag on correct instance
|
||||
queue[0][2].drag(queue[0][0], queue[0][1]);
|
||||
}
|
||||
else
|
||||
$.removeData(self.target, StringPool.DATA_QUEUE);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
mouseEvent: function(EVT) {
|
||||
var evt, type = this.type, o = this.options;
|
||||
|
||||
//check for DOM-compliant browsers
|
||||
if ($.isFunction(document.createEvent)) {
|
||||
evt = document.createEvent(StringPool.MOUSE_EVENTS);
|
||||
|
||||
//Safari 2.x doesn't implement initMouseEvent()
|
||||
if ($.isFunction(evt.initMouseEvent)) {
|
||||
evt.initMouseEvent(type,
|
||||
EVT.bubbles, EVT.cancelable, EVT.view, EVT.detail,
|
||||
EVT.screenX, EVT.screenY, EVT.clientX, EVT.clientY,
|
||||
EVT.ctrlKey, EVT.altKey, EVT.shiftKey, EVT.metaKey,
|
||||
EVT.button, EVT.relatedTarget);
|
||||
} else {
|
||||
// Safari
|
||||
evt = document.createEvent(StringPool.UI_EVENTS);
|
||||
customEvent.initEvent(type, EVT.bubbles, EVT.cancelable);
|
||||
$.extend(evt, EVT);
|
||||
}
|
||||
|
||||
// check to see if relatedTarget has been assigned
|
||||
if (EVT.relatedTarget && !evt.relatedTarget){
|
||||
if (type == StringPool.MOUSEOUT) {
|
||||
evt.toElement = EVT.relatedTarget;
|
||||
} else if (type == StringPool.MOUSEOVER) {
|
||||
evt.fromElement = EVT.relatedTarget;
|
||||
}
|
||||
}
|
||||
// fire the event
|
||||
this.target.dispatchEvent(evt);
|
||||
|
||||
} else if (document.createEventObject) {
|
||||
evt = document.createEventObject();
|
||||
|
||||
// assign available properties
|
||||
$.extend(evt, EVT)
|
||||
|
||||
// IE won't allow assignment to toElement or fromElement
|
||||
evt.relatedTarget = EVT.relatedTarget;
|
||||
|
||||
// fix for 2 pixels bug from mousecords
|
||||
evt.pageX = o.x; evt.pageY = o.y;
|
||||
|
||||
// fire the event
|
||||
this.target.fireEvent(StringPool.ON + type, evt);
|
||||
}
|
||||
|
||||
return evt;
|
||||
},
|
||||
|
||||
keyboardEvent: function(EVT) {
|
||||
var evt, type = this.type, o = this.options;
|
||||
|
||||
// check for DOM-compliant browsers first
|
||||
if ($.isFunction(document.createEvent)) {
|
||||
|
||||
try {
|
||||
// try to create key event
|
||||
evt = document.createEvent(StringPool.KEY_EVENTS);
|
||||
|
||||
evt.initKeyEvent(type,
|
||||
EVT.bubbles, EVT.cancelable, EVT.view, EVT.ctrlKey,
|
||||
EVT.altKey, EVT.shiftKey, EVT.metaKey, EVT.keyCode, EVT.charCode);
|
||||
|
||||
} catch (err) {
|
||||
// we need another try-catch for Safari 2.x
|
||||
try {
|
||||
// generic event for opera and webkit nightlies, will fail in Safari 2.x
|
||||
evt = document.createEvent(StringPool.EVENTS);
|
||||
} catch (ierr){
|
||||
// Safari 2.x - create a UIEvent
|
||||
evt = document.createEvent(StringPool.UI_EVENTS);
|
||||
} finally {
|
||||
evt.initEvent(type, EVT.bubbles, EVT.cancelable);
|
||||
|
||||
// initializing
|
||||
$.each(EVT, function(k, v) {
|
||||
// using try-catch for avoiding Opera NO_MODIFICATION_ALLOWED_ERR
|
||||
try { evt[k] = v; } catch(e) { }
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// fire the event
|
||||
this.target.dispatchEvent(evt);
|
||||
|
||||
} else if (document.createEventObject) {
|
||||
// create an IE event object
|
||||
evt = document.createEventObject();
|
||||
|
||||
// assign available properties
|
||||
$.extend(evt, EVT);
|
||||
|
||||
// IE doesn't support charCode explicitly
|
||||
evt.keyCode = (EVT.charCode > 0) ? EVT.charCode : EVT.keyCode;
|
||||
|
||||
// fire the event
|
||||
this.target.fireEvent(StringPool.ON + type, evt);
|
||||
}
|
||||
|
||||
return evt;
|
||||
},
|
||||
|
||||
findCenter: function(offset) {
|
||||
var el = $(this.target), o = el.offset();
|
||||
return {
|
||||
x: o.left + (((offset||[0, 0])[0]) || 0) + el.outerWidth() / 2,
|
||||
y: o.top + (((offset||[0, 0])[1]) || 0) + el.outerHeight() / 2
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
$.extend($.userAction, {
|
||||
defaults: {
|
||||
center: true
|
||||
}
|
||||
});
|
||||
|
||||
var StringPool = {
|
||||
ON: 'on',
|
||||
NUMBER: 'number',
|
||||
MOUSEOVER: 'mouseover',
|
||||
MOUSEOUT: 'mouseout',
|
||||
MOUSEDOWN: 'mousedown',
|
||||
MOUSEUP: 'mouseup',
|
||||
MOUSEMOVE: 'mousemove',
|
||||
MOUSE_EVENTS: 'MouseEvents',
|
||||
UI_EVENTS: 'UIEvents',
|
||||
KEY_EVENTS: 'KeyEvents',
|
||||
EVENTS: 'Events',
|
||||
FAKE_CURSOR_EXP: 'div.ui-fake-cursor',
|
||||
FAKE_CURSOR_DIV: '<div class="ui-fake-cursor"/>',
|
||||
ABSOLUTE: 'absolute',
|
||||
DATA_QUEUE: 'ua-drag-queue',
|
||||
TOP: 'top',
|
||||
LEFT: 'left',
|
||||
SLOW: 'slow',
|
||||
SWING: 'swing'
|
||||
};
|
||||
|
||||
})(jQuery);
|
@ -1,142 +0,0 @@
|
||||
/*
|
||||
* jQuery UI testMouse
|
||||
*
|
||||
* Copyright (c) 2008 Richard D. Worth (rdworth.org)
|
||||
* Dual licensed under the MIT (MIT-LICENSE.txt)
|
||||
* and GPL (GPL-LICENSE.txt) licenses.
|
||||
*
|
||||
* Revision: $Id: $
|
||||
*/
|
||||
;(function($) {
|
||||
|
||||
var mouseX = 0;
|
||||
var mouseY = 0;
|
||||
|
||||
$(function() {
|
||||
$(document).mousemove(function(e) {
|
||||
if (e.isTrusted !== false) {
|
||||
mouseX = e.pageX;
|
||||
mouseY = e.pageY;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$.widget("ui.testMouse", {
|
||||
trackMouse: function() {},
|
||||
init: function() {
|
||||
},
|
||||
destroy: function() {
|
||||
},
|
||||
center: function(offset) {
|
||||
var o = this.element.offset();
|
||||
return {
|
||||
x: (o.left + (offset || [0, 0])[0] || 0) + this.element.width() / 2,
|
||||
y: (o.top + (offset || [0, 0])[1] || 0) + this.element.height() / 2
|
||||
};
|
||||
},
|
||||
drag: function(dx, dy) {
|
||||
var self = this;
|
||||
|
||||
var center = this.center();
|
||||
this.left = center.x;
|
||||
this.top = center.y;
|
||||
|
||||
var OS = (/(win|mac|linux)/i.exec(navigator.platform) || ['other'])[0].toLowerCase();
|
||||
|
||||
var defaultUrl = ['cursors', OS == 'other' ? 'win' : OS, 'default.png'].join('/');
|
||||
var cursorUrl = function() {
|
||||
return ['cursors', OS == 'other' ? 'win' : OS, self.element.css('cursor') + '.png'].join('/');
|
||||
}
|
||||
var noneUrl = ['cursors', OS == 'other' ? 'win' : OS, 'none' + ($.browser.safari ? '.png' : '.cur')].join('/');
|
||||
|
||||
var fakemouse = $('<img src="' + defaultUrl + '" />');
|
||||
var realmouse = $('<img src="' + defaultUrl + '" />');
|
||||
if ($.browser.msie && $.browser.version == 6) {
|
||||
fakemouse = $('<div style="height:32;width:32;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + defaultUrl + '\', sizingMethod=\'scale\');" ></div>');
|
||||
realmouse = $('<div><div style="height:32;width:32;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + defaultUrl + '\', sizingMethod=\'scale\');" ></div></div>');
|
||||
}
|
||||
var mousescreen = $('<div/>');
|
||||
|
||||
var updateCursor = function() {
|
||||
if ($.browser.msie && $.browser.version == 6) {
|
||||
fakemouse.css('filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + cursorUrl() + '\', sizingMethod=\'scale\'');
|
||||
} else {
|
||||
fakemouse.attr('src', cursorUrl());
|
||||
}
|
||||
}
|
||||
var resetCursor = function() {
|
||||
if ($.browser.msie && $.browser.version == 6) {
|
||||
fakemouse.css('filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + defaultUrl + '\', sizingMethod=\'scale\'');
|
||||
} else {
|
||||
fakemouse.attr('src', defaultUrl);
|
||||
}
|
||||
}
|
||||
|
||||
var testStart = function() {
|
||||
self.element.bind("mouseover", updateCursor).bind("mouseout", resetCursor);
|
||||
fakemouse.appendTo('body').css({ position: 'absolute', left: mouseX, top: mouseY, zIndex: 5000 });
|
||||
realmouse.appendTo('body').css({ position: 'absolute', left: mouseX, top: mouseY, zIndex: 5000, opacity: 0.1 });
|
||||
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; });
|
||||
mousescreen.css('cursor', 'url(' + noneUrl + '), crosshair');
|
||||
($.browser.opera && mousescreen.css('cursor', 'crosshair'));
|
||||
}
|
||||
var testStop = function() {
|
||||
self.element.unbind("mouseover", updateCursor).unbind("mouseout", resetCursor);
|
||||
mousescreen.remove();
|
||||
mouseX = realmouse.css("left");
|
||||
mouseY = realmouse.css("top");
|
||||
realmouse.remove();
|
||||
fakemouse.remove();
|
||||
self.options.complete.apply();
|
||||
}
|
||||
|
||||
testStart();
|
||||
|
||||
this.lastX = null;
|
||||
|
||||
var before = function() {
|
||||
self.element.triggerHandler('mouseover');
|
||||
self.element.simulate("mousedown", { clientX: self.left, clientY: self.top });
|
||||
self.element.simulate("mousemove", { clientX: self.left, clientY: self.top });
|
||||
}
|
||||
|
||||
var during = function(xory) {
|
||||
if (!self.lastX) {
|
||||
self.lastX = xory;
|
||||
} else {
|
||||
var x = self.lastX, y = xory;
|
||||
self.element.simulate("mousemove", { clientX: x, clientY: y });
|
||||
self.lastX = null;
|
||||
}
|
||||
}
|
||||
|
||||
var after = function() {
|
||||
self.element.triggerHandler('mouseout');
|
||||
self.element.simulate("mouseup", { clientX: 0, clientY: 0 });
|
||||
testStop();
|
||||
}
|
||||
|
||||
fakemouse
|
||||
.animate({ left: this.left, top: this.top }, this.options.speed, before)
|
||||
.animate({ left: this.left + dx, top: this.top + dy }, {
|
||||
speed: this.options.speed,
|
||||
easing: "swing",
|
||||
step: during
|
||||
})
|
||||
.animate({ left: this.left + dx, top: this.top + dy }, {
|
||||
speed: this.options.speed,
|
||||
easing: "swing",
|
||||
complete: after
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
$.ui.testMouse.defaults = {
|
||||
speed: "slow"
|
||||
}
|
||||
|
||||
})(jQuery);
|