Skip to content
Permalink
Browse files

Added simulate "drag" method. Fixed some issues in resizable tests.

  • Loading branch information
rdworth committed Jun 4, 2008
1 parent 0646f77 commit 0b2be30492a91f7392845ee82befe16e65b061a2
Showing with 126 additions and 95 deletions.
  1. +40 −4 ui/tests/jquery.simulate.js
  2. +4 −9 ui/tests/resizable.html
  3. +82 −82 ui/tests/resizable.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);
@@ -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 @@ <h2 id="userAgent"></h2>
<ol id="tests"></ol>
<div class="ui-fake-cursor"/>
</body>
</html>
</html>

0 comments on commit 0b2be30

Please sign in to comment.
You can’t perform that action at this time.