]> source.dussan.org Git - jquery-ui.git/commitdiff
Resizable automated tests - Resize fixed
authorEduardo Lundgren <eduardolundgren@gmail.com>
Sat, 24 May 2008 14:55:02 +0000 (14:55 +0000)
committerEduardo Lundgren <eduardolundgren@gmail.com>
Sat, 24 May 2008 14:55:02 +0000 (14:55 +0000)
ui/tests/resizable.html
ui/tests/resizable.js

index 7be13005b0516629ba3ade85fba914c7506fb59d..735c7a2985db62e4f862812ba0fe56d5c5388048 100644 (file)
@@ -18,6 +18,7 @@
        <h1 id="header">jQuery Test Suite</h1>
        <h2 id="banner"></h2>
        <h2 id="userAgent"></h2>
+       <h2 id="log"></h2>
        
        <div id="main" style="border: 1px solid black; padding: 10px; margin: 10px;">
                <div id='resizable1' style="background: green; width: 200px; height: 100px;">I'm a resizable.</div>
index 1fd2a9b0b81b1ad619d7ec062a9f9ac357e0a14f..c88ce239a9b4c6c84100e1022ce44122db746210 100644 (file)
@@ -1,3 +1,9 @@
+var console = console || {
+       log: function(l) {
+               $('log').append(l + <br/>);
+       }
+};
+
 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 );