From 76525dc99d08fe03ed584c5db86a5bfb599f68e8 Mon Sep 17 00:00:00 2001 From: Eduardo Lundgren Date: Mon, 26 May 2008 21:15:21 +0000 Subject: [PATCH] $('div.target').userAction("click", x, y); UserAvtion Plugin - Simulate mouse/keys real events. --- ui/tests/resizable.html | 103 ++++++++++++++++++++++++++++++++++++++++ ui/tests/resizable.js | 77 +++--------------------------- 2 files changed, 109 insertions(+), 71 deletions(-) diff --git a/ui/tests/resizable.html b/ui/tests/resizable.html index 2a97bcb82..ab605d543 100644 --- a/ui/tests/resizable.html +++ b/ui/tests/resizable.html @@ -12,6 +12,7 @@ + @@ -26,5 +27,107 @@
    + + + + + + diff --git a/ui/tests/resizable.js b/ui/tests/resizable.js index c88ce239a..fe16d1b7b 100644 --- a/ui/tests/resizable.js +++ b/ui/tests/resizable.js @@ -1,6 +1,6 @@ var console = console || { log: function(l) { - $('log').append(l +
    ); + $('log').append(l + '
    '); } }; @@ -8,54 +8,6 @@ var num = function(i) { return parseInt(i, 10); }; -var animateClick = function(co) { - var img = $("").appendTo("body") - .css({ position: "absolute", zIndex: 1000, left: co.x, top: co.y }) - .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, relatedTarget) { - - //check for DOM-compliant browsers - if ($.isFunction(document.createEvent)) { - - 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); - } - - return evt; -}; - - -$.fn.triggerMouse = function(type, co, relatedTarget) { - return initMouseEvent(type, this[0], co, relatedTarget); -}; - -var xy = function(el, offset) { - var o = el.offset(); - return { x: o.left + (offset || [0, 0])[0]||0, y: o.top + (offset || [0, 0])[1]||0 }; -}; $(document).ready(function() { @@ -64,37 +16,20 @@ $(document).ready(function() { //maxHeight: 200, start: function(e, ui) { - console.log('start: [' + e.pageX + ', ' + e.pageY + ']' ) - console.log(ui.instance.size, ui.instance.position) + //console.log('start: [' + e.pageX + ', ' + e.pageY + ']' ) + //console.log(ui.instance.size, ui.instance.position) }, stop: function(e, ui) { - console.log('stop: [' + e.pageX + ', ' + e.pageY + ']' ) - console.log(ui.instance.size, ui.instance.position) + //console.log('stop: [' + e.pageX + ', ' + e.pageY + ']' ) + //console.log(ui.instance.size, ui.instance.position) }, resize: function(e) { - console.log(e); + //console.log(e); } }); - var handler = $(this).find('.ui-resizable-s'); - - handler.mousedown(function() { /*console.log('down')*/ }); - handler.mouseup(function() { /*console.log('up')*/ }); - - handler.triggerMouse( "mouseover", xy(handler), handler[0] ); - handler.triggerMouse( "mousedown", xy(handler) ); - - var lastco = [], distance = 30; - - for (var x = 0; x < distance; x++) { - var evt = $(handler).triggerMouse( "mousemove", lastco = xy(handler, [x, x]) ); - } - - handler.triggerMouse( "mouseup", lastco ); - - return;