From 26b2908040c48ffbd8f53bdb0d8bee66a93e0da3 Mon Sep 17 00:00:00 2001 From: Eduardo Lundgren Date: Sat, 24 May 2008 14:55:02 +0000 Subject: [PATCH] Resizable automated tests - Resize fixed --- ui/tests/resizable.html | 1 + ui/tests/resizable.js | 62 ++++++++++++++++++++++++++++------------- 2 files changed, 43 insertions(+), 20 deletions(-) diff --git a/ui/tests/resizable.html b/ui/tests/resizable.html index 7be13005b..735c7a298 100644 --- a/ui/tests/resizable.html +++ b/ui/tests/resizable.html @@ -18,6 +18,7 @@

jQuery Test Suite

+

I'm a resizable.
diff --git a/ui/tests/resizable.js b/ui/tests/resizable.js index 1fd2a9b0b..c88ce239a 100644 --- a/ui/tests/resizable.js +++ b/ui/tests/resizable.js @@ -1,3 +1,9 @@ +var console = console || { + log: function(l) { + $('log').append(l +
); + } +}; + var num = function(i) { return parseInt(i, 10); }; @@ -8,13 +14,33 @@ var animateClick = function(co) { .animate({ width: 80, height: 80, left: co.x-40, top: co.y-40, opacity: 'hide' }, 1000, function() { $(this).remove(); }); }; -var initMouseEvent = function(type, el, co) { - var evt = document.createEvent("MouseEvents"); - evt.initMouseEvent(type, true, true, window, 0, 0, 0, co.x, co.y, false, false, false, false, 0, null); +var initMouseEvent = function(type, el, co, relatedTarget) { - el.dispatchEvent(evt); + //check for DOM-compliant browsers + if ($.isFunction(document.createEvent)) { - if (/^mouseup|mousedown|click$/i.test(type)) { + var evt = document.createEvent("MouseEvents"); + evt.initMouseEvent(type, true, true, window, 0, 0, 0, co.x, co.y, false, false, false, false, 0, null); + + if (relatedTarget && !evt.relatedTarget) { + if (type == "mouseout") { + evt.toElement = relatedTarget; + } + else + if (type == "mouseover") { + evt.fromElement = relatedTarget; + } + } + + el.dispatchEvent(evt); + } + + // IE + if (document.createEventObject) { + + } + + if (/^mouseup|mousdemove|mousedown|click$/i.test(type)) { animateClick(co); } @@ -22,16 +48,8 @@ var initMouseEvent = function(type, el, co) { }; -$.fn.triggerMousedown = function(co) { - return initMouseEvent("mousedown", this[0], co); -}; - -$.fn.triggerMouseup = function(co) { - return initMouseEvent("mouseup", this[0], co); -}; - -$.fn.triggerMousemove = function(co, target) { - return initMouseEvent("mousemove", this[0], co); +$.fn.triggerMouse = function(type, co, relatedTarget) { + return initMouseEvent(type, this[0], co, relatedTarget); }; var xy = function(el, offset) { @@ -43,6 +61,8 @@ $(document).ready(function() { $("#resizable1").resizable({ + //maxHeight: 200, + start: function(e, ui) { console.log('start: [' + e.pageX + ', ' + e.pageY + ']' ) console.log(ui.instance.size, ui.instance.position) @@ -63,14 +83,16 @@ $(document).ready(function() { handler.mousedown(function() { /*console.log('down')*/ }); handler.mouseup(function() { /*console.log('up')*/ }); - handler.triggerMousedown( xy(handler) ); + handler.triggerMouse( "mouseover", xy(handler), handler[0] ); + handler.triggerMouse( "mousedown", xy(handler) ); + + var lastco = [], distance = 30; - for (var x = 0; x < 50; x += 10) { - var evt = $(handler).triggerMousemove( xy(handler, [x, x]) ); - console.log(evt) + for (var x = 0; x < distance; x++) { + var evt = $(handler).triggerMouse( "mousemove", lastco = xy(handler, [x, x]) ); } - handler.triggerMouseup( xy(handler, [50, 50]) ); + handler.triggerMouse( "mouseup", lastco ); -- 2.39.5