aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Worth <rdworth@gmail.com>2008-06-04 08:47:26 +0000
committerRichard Worth <rdworth@gmail.com>2008-06-04 08:47:26 +0000
commit0b2be30492a91f7392845ee82befe16e65b061a2 (patch)
treef792779f13436e410bd5773777a1c87e6f0548cc
parent0646f774adee4ec804ac86a0355e3d7a212af097 (diff)
downloadjquery-ui-0b2be30492a91f7392845ee82befe16e65b061a2.tar.gz
jquery-ui-0b2be30492a91f7392845ee82befe16e65b061a2.zip
Added simulate "drag" method. Fixed some issues in resizable tests.
-rw-r--r--ui/tests/jquery.simulate.js44
-rw-r--r--ui/tests/resizable.html13
-rw-r--r--ui/tests/resizable.js164
3 files changed, 126 insertions, 95 deletions
diff --git a/ui/tests/jquery.simulate.js b/ui/tests/jquery.simulate.js
index 7f3109994..9fa137734 100644
--- a/ui/tests/jquery.simulate.js
+++ b/ui/tests/jquery.simulate.js
@@ -12,19 +12,28 @@
;(function($) {
$.fn.extend({
- simulate: function(type, options) {
+ simulate: function(type, options, complete) {
return this.each(function() {
- new $.simulate(this, type, options);
+ var opt = $.extend({ complete: complete }, options);
+ new $.simulate(this, type, opt);
});
}
});
$.simulate = function(el, type, options) {
- var evt = this.createEvent(type, options);
- this.dispatchEvent(el, type, evt);
+ this.target = el;
+ if (/^drag$/.test(type)) {
+ this[type].apply(this, [this.target, options]);
+ } else {
+ this.simulateEvent(type, options);
+ }
}
$.extend($.simulate.prototype, {
+ simulateEvent: function(el, type, options) {
+ var evt = this.createEvent(type, options);
+ this.dispatchEvent(el, type, evt);
+ },
createEvent: function(type, options) {
if (/^mouse(over|out|down|up|move)|(dbl)?click$/.test(type)) {
return this.mouseEvent(type, options);
@@ -89,7 +98,34 @@ $.extend($.simulate.prototype, {
} else if (el.fireEvent) {
el.fireEvent('on' + type, evt);
}
+ },
+
+ findCenter: function(el) {
+ var el = $(this.target), o = el.offset();
+ return {
+ x: o.left + el.outerWidth() / 2,
+ y: o.top + el.outerHeight() / 2
+ };
+ },
+ drag: function(el, options) {
+ var center = this.findCenter(this.target),
+ x = center.x, y = center.y,
+ dx = options.dx || 0,
+ dy = options.dy || 0;
+ this.simulateEvent(this.target, "mouseover");
+ this.simulateEvent(this.target, "mousedown", { clientX: x, clientY: y });
+ this.simulateEvent(this.target, "mousemove", { clientX: x, clientY: y });
+ this.simulateEvent(this.target, "mousemove", { clientX: x, clientY: y });
+ this.simulateEvent(this.target, "mousemove", { clientX: x, clientY: y });
+ this.simulateEvent(document, "mousemove", { clientX: x + dx, clientY: y + dy });
+ this.simulateEvent(document, "mousemove", { clientX: x + dx, clientY: y + dy });
+ this.simulateEvent(document, "mousemove", { clientX: x + dx, clientY: y + dy });
+ this.simulateEvent(this.target, "mouseup", { clientX: x + dx, clientY: y + dy });
+ this.simulateEvent(this.target, "click", { clientX: x + dx, clientY: y + dy });
+ this.simulateEvent(this.target, "mouseout");
+ (options.complete && options.complete());
}
+
});
})(jQuery);
diff --git a/ui/tests/resizable.html b/ui/tests/resizable.html
index 00c6a5352..955798293 100644
--- a/ui/tests/resizable.html
+++ b/ui/tests/resizable.html
@@ -12,18 +12,13 @@
<script type="text/javascript" src="../../qunit/testrunner.js"></script>
<script type="text/javascript" src="resizable.js"></script>
-<script type="text/javascript" src="jquery.useraction.js"></script>
+<script type="text/javascript" src="jquery.simulate.js"></script>
+
</head>
<style>
- /*.ui-fake-cursor {
- position: absolute;
- background: url(cursors/win/auto.png);
- height: 32px; width: 32px;
- top: 270px; left: 0px;
- }*/
#main {
- position:absolute !important;
+ position: absolute !important;
top: -1000px !important;
left: -1000px !important;
}
@@ -42,4 +37,4 @@
<ol id="tests"></ol>
<div class="ui-fake-cursor"/>
</body>
-</html> \ No newline at end of file
+</html>
diff --git a/ui/tests/resizable.js b/ui/tests/resizable.js
index 9fe4d4a0d..12f9c4728 100644
--- a/ui/tests/resizable.js
+++ b/ui/tests/resizable.js
@@ -3,7 +3,7 @@ var drag = function(el, dx, dy, complete) {
// speed = sync -> Drag syncrhonously.
// speed = fast|slow -> Drag asyncrhonously - animated.
- return $(el).userAction("drag", {
+ return $(el).simulate("drag", {
dx: dx||0, dy: dy||0, speed: 'sync', complete: complete
});
};
@@ -18,11 +18,11 @@ test("ui-resizable-e resize x", function() {
drag(handle, 50);
- equals( 149, target.width(), "compare width");
+ equals( target.width(), 150, "compare width");
drag(handle, -50);
- equals( 100, target.width(), "compare width" );
+ equals( target.width(), 100, "compare width" );
});
@@ -34,11 +34,11 @@ test("ui-resizable-w resize x", function() {
drag(handle, -50);
- equals( 149, target.width(), "compare width" );
+ equals( target.width(), 150, "compare width" );
drag(handle, 50);
- equals( 100, target.width(), "compare width" );
+ equals( target.width(), 100, "compare width" );
});
@@ -50,11 +50,11 @@ test("ui-resizable-n resize y", function() {
drag(handle, 0, -50);
- equals( 149, target.height(), "compare height" );
+ equals( target.height(), 150, "compare height" );
drag(handle, 0, 50);
- equals( 100, target.height(), "compare height" );
+ equals( target.height(), 100, "compare height" );
});
@@ -66,11 +66,11 @@ test("ui-resizable-s resize y", function() {
drag(handle, 0, 50);
- equals( 149, target.height(), "compare height" );
+ equals( target.height(), 150, "compare height" );
drag(handle, 0, -50);
- equals( 100, target.height(), "compare height" );
+ equals( target.height(), 100, "compare height" );
});
@@ -82,13 +82,13 @@ test("ui-resizable-se resize xy", function() {
drag(handle, 50, 50);
- equals( 149, target.width(), "compare width" );
- equals( 149, target.height(), "compare height" );
+ equals( target.width(), 150, "compare width" );
+ equals( target.height(), 150, "compare height" );
drag(handle, -50, -50);
- equals( 100, target.width(), "compare width" );
- equals( 100, target.height(), "compare height" );
+ equals( target.width(), 100, "compare width" );
+ equals( target.height(), 100, "compare height" );
});
@@ -100,13 +100,13 @@ test("ui-resizable-sw resize xy", function() {
drag(handle, -50, -50);
- equals( 149, target.width(), "compare width" );
- equals( 51, target.height(), "compare height" );
+ equals( target.width(), 150, "compare width" );
+ equals( target.height(), 50, "compare height" );
drag(handle, 50, 50);
- equals( 100, target.width(), "compare width" );
- equals( 100, target.height(), "compare height" );
+ equals( target.width(), 100, "compare width" );
+ equals( target.height(), 100, "compare height" );
});
@@ -118,13 +118,13 @@ test("ui-resizable-ne resize xy", function() {
drag(handle, -50, -50);
- equals( 51, target.width(), "compare width" );
- equals( 149, target.height(), "compare height" );
+ equals( target.width(), 50, "compare width" );
+ equals( target.height(), 150, "compare height" );
drag(handle, 50, 50);
- equals( 100, target.width(), "compare width" );
- equals( 100, target.height(), "compare height" );
+ equals( target.width(), 100, "compare width" );
+ equals( target.height(), 100, "compare height" );
});
@@ -136,13 +136,13 @@ test("ui-resizable-nw resize xy", function() {
drag(handle, -50, -50);
- equals( 149, target.width(), "compare width" );
- equals( 149, target.height(), "compare height" );
+ equals( target.width(), 150, "compare width" );
+ equals( target.height(), 150, "compare height" );
drag(handle, 50, 50);
- equals( 100, target.width(), "compare width" );
- equals( 100, target.height(), "compare height" );
+ equals( target.width(), 100, "compare width" );
+ equals( target.height(), 100, "compare height" );
});
@@ -161,13 +161,13 @@ test("ui-resizable-se { handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 1
drag(handle, -50, -50);
- equals( 60, target.width(), "compare minWidth" );
- equals( 60, target.height(), "compare minHeight" );
+ equals( target.width(), 60, "compare minWidth" );
+ equals( target.height(), 60, "compare minHeight" );
drag(handle, 70, 70);
- equals( 100, target.width(), "compare maxWidth" );
- equals( 100, target.height(), "compare maxHeight" );
+ equals( target.width(), 100, "compare maxWidth" );
+ equals( target.height(), 100, "compare maxHeight" );
});
@@ -179,13 +179,13 @@ test("ui-resizable-sw { handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 1
drag(handle, 50, -50);
- equals( 60, target.width(), "compare minWidth" );
- equals( 60, target.height(), "compare minHeight" );
+ equals( target.width(), 60, "compare minWidth" );
+ equals( target.height(), 60, "compare minHeight" );
drag(handle, -70, 70);
- equals( 100, target.width(), "compare maxWidth" );
- equals( 100, target.height(), "compare maxHeight" );
+ equals( target.width(), 100, "compare maxWidth" );
+ equals( target.height(), 100, "compare maxHeight" );
});
@@ -197,13 +197,13 @@ test("ui-resizable-ne { handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 1
drag(handle, -50, 50);
- equals( 60, target.width(), "compare minWidth" );
- equals( 60, target.height(), "compare minHeight" );
+ equals( target.width(), 60, "compare minWidth" );
+ equals( target.height(), 60, "compare minHeight" );
drag(handle, 70, -70);
- equals( 100, target.width(), "compare maxWidth" );
- equals( 100, target.height(), "compare maxHeight" );
+ equals( target.width(), 100, "compare maxWidth" );
+ equals( target.height(), 100, "compare maxHeight" );
});
@@ -215,13 +215,13 @@ test("ui-resizable-nw { handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 1
drag(handle, 70, 70);
- equals( 60, target.width(), "compare minWidth" );
- equals( 60, target.height(), "compare minHeight" );
+ equals( target.width(), 60, "compare minWidth" );
+ equals( target.height(), 60, "compare minHeight" );
drag(handle, -70, -70);
- equals( 100, target.width(), "compare maxWidth" );
- equals( 100, target.height(), "compare maxHeight" );
+ equals( target.width(), 100, "compare maxWidth" );
+ equals( target.height(), 100, "compare maxHeight" );
});
@@ -239,13 +239,13 @@ test("ui-resizable-e { aspectRatio: 'preserve', handles: 'all', minWidth: 70, mi
drag(handle, 80);
- equals( 150, target.width(), "compare maxWidth");
- equals( 130, target.height(), "compare maxHeight");
+ equals( target.width(), 130, "compare maxWidth");
+ equals( target.height(), 130, "compare maxHeight");
drag(handle, -130);
- equals( 70, target.width(), "compare minWidth");
- equals( 70, target.height(), "compare minHeight");
+ equals( target.width(), 70, "compare minWidth");
+ equals( target.height(), 70, "compare minHeight");
});
@@ -257,13 +257,13 @@ test("ui-resizable-w { aspectRatio: 'preserve', handles: 'all', minWidth: 70, mi
drag(handle, -80);
- equals( 150, target.width(), "compare maxWidth");
- equals( 130, target.height(), "compare maxHeight");
+ equals( target.width(), 130, "compare maxWidth");
+ equals( target.height(), 130, "compare maxHeight");
drag(handle, 130);
- equals( 70, target.width(), "compare minWidth");
- equals( 70, target.height(), "compare minHeight");
+ equals( target.width(), 70, "compare minWidth");
+ equals( target.height(), 70, "compare minHeight");
});
@@ -275,14 +275,14 @@ test("ui-resizable-n { aspectRatio: 'preserve', handles: 'all', minWidth: 70, mi
drag(handle, 0, -80);
- equals( 130, target.width(), "compare maxWidth");
- equals( 130, target.height(), "compare maxHeight");
+ equals( target.width(), 130, "compare maxWidth");
+ equals( target.height(), 130, "compare maxHeight");
- drag(handle, 0, 130);
-
- equals( 70, target.width(), "compare minWidth");
- equals( 50, target.height(), "compare minHeight");
+ drag(handle, 0, 80);
+ equals( target.width(), 70, "compare minWidth");
+ equals( target.height(), 70, "compare minHeight");
+
});
test("ui-resizable-s { aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }", function() {
@@ -293,13 +293,13 @@ test("ui-resizable-s { aspectRatio: 'preserve', handles: 'all', minWidth: 70, mi
drag(handle, 0, 80);
- equals( 130, target.width(), "compare maxWidth");
- equals( 130, target.height(), "compare maxHeight");
+ equals( target.width(), 130, "compare maxWidth");
+ equals( target.height(), 130, "compare maxHeight");
- drag(handle, 0, -130);
+ drag(handle, 0, -80);
- equals( 70, target.width(), "compare minWidth");
- equals( 50, target.height(), "compare minHeight");
+ equals( target.width(), 70, "compare minWidth");
+ equals( target.height(), 70, "compare minHeight");
});
@@ -311,13 +311,13 @@ test("ui-resizable-se { aspectRatio: 'preserve', handles: 'all', minWidth: 70, m
drag(handle, 80, 80);
- equals( 130, target.width(), "compare maxWidth");
- equals( 130, target.height(), "compare maxHeight");
+ equals( target.width(), 130, "compare maxWidth");
+ equals( target.height(), 130, "compare maxHeight");
- drag(handle, -130, -130);
+ drag(handle, -80, -80);
- equals( 70, target.width(), "compare minWidth");
- equals( 50, target.height(), "compare minHeight");
+ equals( target.width(), 70, "compare minWidth");
+ equals( target.height(), 70, "compare minHeight");
});
@@ -329,13 +329,13 @@ test("ui-resizable-sw { aspectRatio: 'preserve', handles: 'all', minWidth: 70, m
drag(handle, -80, 80);
- equals( 130, target.width(), "compare maxWidth");
- equals( 130, target.height(), "compare maxHeight");
+ equals( target.width(), 130, "compare maxWidth");
+ equals( target.height(), 130, "compare maxHeight");
- drag(handle, 130, -130);
+ drag(handle, 80, -80);
- equals( 70, target.width(), "compare minWidth");
- equals( 50, target.height(), "compare minHeight");
+ equals( target.width(), 70, "compare minWidth");
+ equals( target.height(), 70, "compare minHeight");
});
@@ -347,33 +347,33 @@ test("ui-resizable-ne { aspectRatio: 'preserve', handles: 'all', minWidth: 70, m
drag(handle, 80, -80);
- equals( 130, target.width(), "compare maxWidth");
- equals( 130, target.height(), "compare maxHeight");
+ equals( target.width(), 130, "compare maxWidth");
+ equals( target.height(), 130, "compare maxHeight");
- drag(handle, -130, 130);
+ drag(handle, -80, 80);
- equals( 70, target.width(), "compare minWidth");
- equals( 50, target.height(), "compare minHeight");
+ equals( target.width(), 70, "compare minWidth");
+ equals( target.height(), 70, "compare minHeight");
});
module("Options");
-test("ui-resizable-se { handles: 'all', gird: [0, 20] }", function() {
+test("ui-resizable-se { handles: 'all', grid: [0, 20] }", function() {
var handle = '.ui-resizable-se', target = $('#resizable1').resizable({ handles: 'all', grid: [0, 20] });
expect(4);
- drag(handle, 10, 10);
+ drag(handle, 3, 9);
- equals( 109, target.width(), "compare width");
- equals( 100, target.height(), "compare height");
+ equals( target.width(), 103, "compare width");
+ equals( target.height(), 100, "compare height");
- drag(handle, 30, 30);
+ drag(handle, 15, 11);
- equals( 138, target.width(), "compare width");
- equals( 120, target.height(), "compare height");
+ equals( target.width(), 118, "compare width");
+ equals( target.height(), 120, "compare height");
});