From 3524ef0c26f8760615c01217045c72f9bb20dde9 Mon Sep 17 00:00:00 2001 From: Richard Worth Date: Sat, 7 Jun 2008 17:35:27 +0000 Subject: removed extra level ui folder --- tests/accordion.html | 170 +++++++++++++ tests/accordion.js | 78 ++++++ tests/all.html | 182 ++++++++++++++ tests/autodrag.html | 155 ++++++++++++ tests/cursors/linux/auto.png | Bin 0 -> 851 bytes tests/cursors/linux/crosshair.png | Bin 0 -> 413 bytes tests/cursors/linux/default.png | Bin 0 -> 851 bytes tests/cursors/linux/e-resize.png | Bin 0 -> 861 bytes tests/cursors/linux/help.png | Bin 0 -> 1279 bytes tests/cursors/linux/move.png | Bin 0 -> 710 bytes tests/cursors/linux/n-resize.png | Bin 0 -> 871 bytes tests/cursors/linux/ne-resize.png | Bin 0 -> 836 bytes tests/cursors/linux/none.cur | Bin 0 -> 2238 bytes tests/cursors/linux/none.png | Bin 0 -> 872 bytes tests/cursors/linux/nw-resize.png | Bin 0 -> 824 bytes tests/cursors/linux/pointer.png | Bin 0 -> 541 bytes tests/cursors/linux/s-resize.png | Bin 0 -> 871 bytes tests/cursors/linux/se-resize.png | Bin 0 -> 824 bytes tests/cursors/linux/sw-resize.png | Bin 0 -> 836 bytes tests/cursors/linux/text.png | Bin 0 -> 486 bytes tests/cursors/linux/w-resize.png | Bin 0 -> 861 bytes tests/cursors/mac/auto.png | Bin 0 -> 401 bytes tests/cursors/mac/crosshair.png | Bin 0 -> 341 bytes tests/cursors/mac/default.png | Bin 0 -> 401 bytes tests/cursors/mac/e-resize.png | Bin 0 -> 390 bytes tests/cursors/mac/help.png | Bin 0 -> 689 bytes tests/cursors/mac/move.png | Bin 0 -> 651 bytes tests/cursors/mac/n-resize.png | Bin 0 -> 434 bytes tests/cursors/mac/ne-resize.png | Bin 0 -> 440 bytes tests/cursors/mac/none.cur | Bin 0 -> 2238 bytes tests/cursors/mac/none.png | Bin 0 -> 872 bytes tests/cursors/mac/nw-resize.png | Bin 0 -> 452 bytes tests/cursors/mac/pointer.png | Bin 0 -> 675 bytes tests/cursors/mac/s-resize.png | Bin 0 -> 434 bytes tests/cursors/mac/se-resize.png | Bin 0 -> 452 bytes tests/cursors/mac/sw-resize.png | Bin 0 -> 440 bytes tests/cursors/mac/text.png | Bin 0 -> 436 bytes tests/cursors/mac/w-resize.png | Bin 0 -> 390 bytes tests/cursors/win/auto.png | Bin 0 -> 724 bytes tests/cursors/win/crosshair.png | Bin 0 -> 304 bytes tests/cursors/win/default.png | Bin 0 -> 724 bytes tests/cursors/win/e-resize.png | Bin 0 -> 714 bytes tests/cursors/win/help.png | Bin 0 -> 1129 bytes tests/cursors/win/move.png | Bin 0 -> 1035 bytes tests/cursors/win/n-resize.png | Bin 0 -> 722 bytes tests/cursors/win/ne-resize.png | Bin 0 -> 985 bytes tests/cursors/win/none.cur | Bin 0 -> 2238 bytes tests/cursors/win/none.png | Bin 0 -> 2847 bytes tests/cursors/win/nw-resize.png | Bin 0 -> 993 bytes tests/cursors/win/pointer.png | Bin 0 -> 1178 bytes tests/cursors/win/s-resize.png | Bin 0 -> 722 bytes tests/cursors/win/se-resize.png | Bin 0 -> 993 bytes tests/cursors/win/sw-resize.png | Bin 0 -> 985 bytes tests/cursors/win/text.png | Bin 0 -> 258 bytes tests/cursors/win/w-resize.png | Bin 0 -> 714 bytes tests/draggable.html | 41 ++++ tests/draggable.js | 494 ++++++++++++++++++++++++++++++++++++++ tests/images/click.png | Bin 0 -> 1293 bytes tests/images/test.jpg | Bin 0 -> 915 bytes tests/jquery.useraction.js | 347 ++++++++++++++++++++++++++ tests/resizable.html | 41 ++++ tests/resizable.js | 400 ++++++++++++++++++++++++++++++ tests/simulate/jquery.simulate.js | 141 +++++++++++ tests/slider.html | 33 +++ tests/slider.js | 110 +++++++++ tests/ui.testmouse.js | 142 +++++++++++ 66 files changed, 2334 insertions(+) create mode 100644 tests/accordion.html create mode 100644 tests/accordion.js create mode 100644 tests/all.html create mode 100644 tests/autodrag.html create mode 100644 tests/cursors/linux/auto.png create mode 100644 tests/cursors/linux/crosshair.png create mode 100644 tests/cursors/linux/default.png create mode 100644 tests/cursors/linux/e-resize.png create mode 100644 tests/cursors/linux/help.png create mode 100644 tests/cursors/linux/move.png create mode 100644 tests/cursors/linux/n-resize.png create mode 100644 tests/cursors/linux/ne-resize.png create mode 100644 tests/cursors/linux/none.cur create mode 100644 tests/cursors/linux/none.png create mode 100644 tests/cursors/linux/nw-resize.png create mode 100644 tests/cursors/linux/pointer.png create mode 100644 tests/cursors/linux/s-resize.png create mode 100644 tests/cursors/linux/se-resize.png create mode 100644 tests/cursors/linux/sw-resize.png create mode 100644 tests/cursors/linux/text.png create mode 100644 tests/cursors/linux/w-resize.png create mode 100644 tests/cursors/mac/auto.png create mode 100644 tests/cursors/mac/crosshair.png create mode 100644 tests/cursors/mac/default.png create mode 100644 tests/cursors/mac/e-resize.png create mode 100644 tests/cursors/mac/help.png create mode 100644 tests/cursors/mac/move.png create mode 100644 tests/cursors/mac/n-resize.png create mode 100644 tests/cursors/mac/ne-resize.png create mode 100644 tests/cursors/mac/none.cur create mode 100644 tests/cursors/mac/none.png create mode 100644 tests/cursors/mac/nw-resize.png create mode 100644 tests/cursors/mac/pointer.png create mode 100644 tests/cursors/mac/s-resize.png create mode 100644 tests/cursors/mac/se-resize.png create mode 100644 tests/cursors/mac/sw-resize.png create mode 100644 tests/cursors/mac/text.png create mode 100644 tests/cursors/mac/w-resize.png create mode 100644 tests/cursors/win/auto.png create mode 100644 tests/cursors/win/crosshair.png create mode 100644 tests/cursors/win/default.png create mode 100644 tests/cursors/win/e-resize.png create mode 100644 tests/cursors/win/help.png create mode 100644 tests/cursors/win/move.png create mode 100644 tests/cursors/win/n-resize.png create mode 100644 tests/cursors/win/ne-resize.png create mode 100644 tests/cursors/win/none.cur create mode 100644 tests/cursors/win/none.png create mode 100644 tests/cursors/win/nw-resize.png create mode 100644 tests/cursors/win/pointer.png create mode 100644 tests/cursors/win/s-resize.png create mode 100644 tests/cursors/win/se-resize.png create mode 100644 tests/cursors/win/sw-resize.png create mode 100644 tests/cursors/win/text.png create mode 100644 tests/cursors/win/w-resize.png create mode 100644 tests/draggable.html create mode 100644 tests/draggable.js create mode 100644 tests/images/click.png create mode 100644 tests/images/test.jpg create mode 100644 tests/jquery.useraction.js create mode 100644 tests/resizable.html create mode 100644 tests/resizable.js create mode 100644 tests/simulate/jquery.simulate.js create mode 100644 tests/slider.html create mode 100644 tests/slider.js create mode 100644 tests/ui.testmouse.js (limited to 'tests') diff --git a/tests/accordion.html b/tests/accordion.html new file mode 100644 index 000000000..66913ba2b --- /dev/null +++ b/tests/accordion.html @@ -0,0 +1,170 @@ + + + + jQuery UI Accordion Test Suite + + + + + + + + + + + + + + +

jQuery UI Accordion Test Suite

+ +

+ +
    + +
    + +
    + Standard, container is a div, header is h3 and content p + +
    + There is one obvious advantage: +
    +

    + You've seen it coming!
    + Buy now and get nothing for free!
    + Well, at least no free beer. Perhaps a bear, if you can afford it. +

    +
    + Now that you've got... +
    +

    + your bear, you have to admit it!
    + No, we aren't selling bears. +

    +

    + We could talk about renting one. +

    +
    + Rent one bear, ... +
    +

    + get two for three beer. +

    +

    + And now, for something completely different. +

    +
    +
    + +
    + +
    + Navigation - Unordered List with anchors and nested lists. +

    The first item is cloned to allow the user to select it. The + active element is choosen based on location.hash: Open Drums and click + the first item ('Drums'), then reload the page.

    + + + +
    + +
    + With options, container is a definition list, header dt, content dd + +
    +
    Red
    +
    + Fancy stuff about red thingies. +
    +
    Green
    +
    + Green! Green! Green! +
    +
    Blue
    +
    + Cool kids are blue. +
    +
    + +
    + +
    + Divitus structure, div container, div header (class title), div + content, no active on startup and can be completely closed + +
    +
    +
    Tennis
    +
    + One ball, two players. Lots of fun. +
    +
    +
    +
    Soccer
    +
    + One ball, 22 players. Lots of fun. +
    +
    +
    +
    Baseball
    +
    + Well, one ball, some guys running around, some guys hitting others with a stick.
    + Sounds like fun, doesn't it? +
    +
    + Well, apart from the running part. +
    +
    +
    + +
    + +
    + + + Activate via selector, eg. ':first' or 'a:first': +
    + +
    Log of the 2nd accordion
    +
    + + \ No newline at end of file diff --git a/tests/accordion.js b/tests/accordion.js new file mode 100644 index 000000000..c0e3edfc5 --- /dev/null +++ b/tests/accordion.js @@ -0,0 +1,78 @@ +module("accordion"); + +jQuery.ui.accordion.defaults.animated = false; + +function state(accordion) { + var args = $.makeArray(arguments).slice(1); + $.each(args, function(i, n) { + equals(n, accordion.find("div").eq(i).is(":visible")); + }); +} + +test("basics", function() { + state($('#list1').accordion(), 1, 0, 0); +}); + +test("autoheight", function() { + $('#navigation').accordion({ header: '.head', autoHeight: false }); + equals( 90, $('#navigation ul:first').height() ); + equals( 126, $('#navigation ul:eq(1)').height() ); + equals( 54, $('#navigation ul:last').height() ); + $('#navigation').accordion("destroy").accordion({ header: '.head', autoHeight: true }); + equals( 126, $('#navigation ul:first').height() ); + equals( 126, $('#navigation ul:eq(1)').height() ); + equals( 126, $('#navigation ul:last').height() ); +}); + +test("activate, numeric", function() { + var ac = $('#list1').accordion({ active: 1 }); + state(ac, 0, 1, 0); + ac.accordion("activate", 2); + state(ac, 0, 0, 1); + ac.accordion("activate", 0); + state(ac, 1, 0, 0); + ac.accordion("activate", 1); + state(ac, 0, 1, 0); + ac.accordion("activate", 2); + state(ac, 0, 0, 1); + ac.accordion("activate", -1); + state(ac, 0, 0, 1); +}); + +test("activate, boolean and numeric, alwaysOpen:false", function() { + var ac = $('#list1').accordion({alwaysOpen: false}).accordion("activate", 2); + state(ac, 0, 0, 1); + ok("x", "----"); + ac.accordion("activate", 0); + state(ac, 1, 0, 0); + ok("x", "----"); + ac.accordion("activate", -1); + state(ac, 0, 0, 0); +}); + +test("activate, boolean, alwaysOpen:true", function() { + var ac = $('#list1').accordion().accordion("activate", 2); + state(ac, 0, 0, 1); + ac.accordion("activate", -1); + state(ac, 0, 0, 1); +}); + +test("activate, string expression", function() { + var ac = $('#list1').accordion({ active: ":last" }); + state(ac, 0, 0, 1); + ac.accordion("activate", ":first"); + state(ac, 1, 0, 0); + ac.accordion("activate", ":eq(1)"); + state(ac, 0, 1, 0); + ac.accordion("activate", ":last"); + state(ac, 0, 0, 1); +}); + +test("activate, jQuery or DOM element", function() { + var ac = $('#list1').accordion({ active: $("#list1 a:last") }); + state(ac, 0, 0, 1); + ac.accordion("activate", $("#list1 a:first")); + state(ac, 1, 0, 0); + ac.accordion("activate", $("#list1 a")[1]); + state(ac, 0, 1, 0); +}); \ No newline at end of file diff --git a/tests/all.html b/tests/all.html new file mode 100644 index 000000000..82000437d --- /dev/null +++ b/tests/all.html @@ -0,0 +1,182 @@ + + + + jQuery UI All Tests + + + + + + + + + + + + + + + +

    jQuery UI All Tests

    + +

    + +

    Run individual testsuites or doubleclick a test below

    + + +
      + +
      + +
      +
      +
      +
      + +
      + Standard, container is a div, header is h3 and content p + +
      + There is one obvious advantage: +
      +

      + You've seen it coming!
      + Buy now and get nothing for free!
      + Well, at least no free beer. Perhaps a bear, if you can afford it. +

      +
      + Now that you've got... +
      +

      + your bear, you have to admit it!
      + No, we aren't selling bears. +

      +

      + We could talk about renting one. +

      +
      + Rent one bear, ... +
      +

      + get two for three beer. +

      +

      + And now, for something completely different. +

      +
      +
      + +
      + +
      + Navigation - Unordered List with anchors and nested lists. +

      The first item is cloned to allow the user to select it. The + active element is choosen based on location.hash: Open Drums and click + the first item ('Drums'), then reload the page.

      + + + +
      + +
      + With options, container is a definition list, header dt, content dd + +
      +
      Red
      +
      + Fancy stuff about red thingies. +
      +
      Green
      +
      + Green! Green! Green! +
      +
      Blue
      +
      + Cool kids are blue. +
      +
      + +
      + +
      + Divitus structure, div container, div header (class title), div + content, no active on startup and can be completely closed + +
      +
      +
      Tennis
      +
      + One ball, two players. Lots of fun. +
      +
      +
      +
      Soccer
      +
      + One ball, 22 players. Lots of fun. +
      +
      +
      +
      Baseball
      +
      + Well, one ball, some guys running around, some guys hitting others with a stick.
      + Sounds like fun, doesn't it? +
      +
      + Well, apart from the running part. +
      +
      +
      + +
      + +
      + + + Activate via selector, eg. ':first' or 'a:first': +
      + +
      Log of the 2nd accordion
      +
      + + \ No newline at end of file diff --git a/tests/autodrag.html b/tests/autodrag.html new file mode 100644 index 000000000..acc17fb4c --- /dev/null +++ b/tests/autodrag.html @@ -0,0 +1,155 @@ + + + + jQuery UI - Automated Tests + + + + + + + + + + + + + + + +
      + +

      jQuery UI - Automated Tests

      + +
      + Status: Ready +
      + +
      + Test: +
      + +
      + +
      + +
      + +
      + + + diff --git a/tests/cursors/linux/auto.png b/tests/cursors/linux/auto.png new file mode 100644 index 000000000..03ac2f281 Binary files /dev/null and b/tests/cursors/linux/auto.png differ diff --git a/tests/cursors/linux/crosshair.png b/tests/cursors/linux/crosshair.png new file mode 100644 index 000000000..30904f933 Binary files /dev/null and b/tests/cursors/linux/crosshair.png differ diff --git a/tests/cursors/linux/default.png b/tests/cursors/linux/default.png new file mode 100644 index 000000000..03ac2f281 Binary files /dev/null and b/tests/cursors/linux/default.png differ diff --git a/tests/cursors/linux/e-resize.png b/tests/cursors/linux/e-resize.png new file mode 100644 index 000000000..b4c40ff17 Binary files /dev/null and b/tests/cursors/linux/e-resize.png differ diff --git a/tests/cursors/linux/help.png b/tests/cursors/linux/help.png new file mode 100644 index 000000000..a6b5836d6 Binary files /dev/null and b/tests/cursors/linux/help.png differ diff --git a/tests/cursors/linux/move.png b/tests/cursors/linux/move.png new file mode 100644 index 000000000..39ae04520 Binary files /dev/null and b/tests/cursors/linux/move.png differ diff --git a/tests/cursors/linux/n-resize.png b/tests/cursors/linux/n-resize.png new file mode 100644 index 000000000..afef5b438 Binary files /dev/null and b/tests/cursors/linux/n-resize.png differ diff --git a/tests/cursors/linux/ne-resize.png b/tests/cursors/linux/ne-resize.png new file mode 100644 index 000000000..8c5e970e1 Binary files /dev/null and b/tests/cursors/linux/ne-resize.png differ diff --git a/tests/cursors/linux/none.cur b/tests/cursors/linux/none.cur new file mode 100644 index 000000000..4f7970a9f Binary files /dev/null and b/tests/cursors/linux/none.cur differ diff --git a/tests/cursors/linux/none.png b/tests/cursors/linux/none.png new file mode 100644 index 000000000..3b34811c5 Binary files /dev/null and b/tests/cursors/linux/none.png differ diff --git a/tests/cursors/linux/nw-resize.png b/tests/cursors/linux/nw-resize.png new file mode 100644 index 000000000..7c17be53e Binary files /dev/null and b/tests/cursors/linux/nw-resize.png differ diff --git a/tests/cursors/linux/pointer.png b/tests/cursors/linux/pointer.png new file mode 100644 index 000000000..b39fcef8f Binary files /dev/null and b/tests/cursors/linux/pointer.png differ diff --git a/tests/cursors/linux/s-resize.png b/tests/cursors/linux/s-resize.png new file mode 100644 index 000000000..afef5b438 Binary files /dev/null and b/tests/cursors/linux/s-resize.png differ diff --git a/tests/cursors/linux/se-resize.png b/tests/cursors/linux/se-resize.png new file mode 100644 index 000000000..7c17be53e Binary files /dev/null and b/tests/cursors/linux/se-resize.png differ diff --git a/tests/cursors/linux/sw-resize.png b/tests/cursors/linux/sw-resize.png new file mode 100644 index 000000000..8c5e970e1 Binary files /dev/null and b/tests/cursors/linux/sw-resize.png differ diff --git a/tests/cursors/linux/text.png b/tests/cursors/linux/text.png new file mode 100644 index 000000000..85a54fcb7 Binary files /dev/null and b/tests/cursors/linux/text.png differ diff --git a/tests/cursors/linux/w-resize.png b/tests/cursors/linux/w-resize.png new file mode 100644 index 000000000..b4c40ff17 Binary files /dev/null and b/tests/cursors/linux/w-resize.png differ diff --git a/tests/cursors/mac/auto.png b/tests/cursors/mac/auto.png new file mode 100644 index 000000000..65b21e435 Binary files /dev/null and b/tests/cursors/mac/auto.png differ diff --git a/tests/cursors/mac/crosshair.png b/tests/cursors/mac/crosshair.png new file mode 100644 index 000000000..b4f165b6a Binary files /dev/null and b/tests/cursors/mac/crosshair.png differ diff --git a/tests/cursors/mac/default.png b/tests/cursors/mac/default.png new file mode 100644 index 000000000..65b21e435 Binary files /dev/null and b/tests/cursors/mac/default.png differ diff --git a/tests/cursors/mac/e-resize.png b/tests/cursors/mac/e-resize.png new file mode 100644 index 000000000..583ce1862 Binary files /dev/null and b/tests/cursors/mac/e-resize.png differ diff --git a/tests/cursors/mac/help.png b/tests/cursors/mac/help.png new file mode 100644 index 000000000..5e8ee5870 Binary files /dev/null and b/tests/cursors/mac/help.png differ diff --git a/tests/cursors/mac/move.png b/tests/cursors/mac/move.png new file mode 100644 index 000000000..cf7608539 Binary files /dev/null and b/tests/cursors/mac/move.png differ diff --git a/tests/cursors/mac/n-resize.png b/tests/cursors/mac/n-resize.png new file mode 100644 index 000000000..1242980a4 Binary files /dev/null and b/tests/cursors/mac/n-resize.png differ diff --git a/tests/cursors/mac/ne-resize.png b/tests/cursors/mac/ne-resize.png new file mode 100644 index 000000000..da3f6d05f Binary files /dev/null and b/tests/cursors/mac/ne-resize.png differ diff --git a/tests/cursors/mac/none.cur b/tests/cursors/mac/none.cur new file mode 100644 index 000000000..4f7970a9f Binary files /dev/null and b/tests/cursors/mac/none.cur differ diff --git a/tests/cursors/mac/none.png b/tests/cursors/mac/none.png new file mode 100644 index 000000000..3b34811c5 Binary files /dev/null and b/tests/cursors/mac/none.png differ diff --git a/tests/cursors/mac/nw-resize.png b/tests/cursors/mac/nw-resize.png new file mode 100644 index 000000000..b6c5e3956 Binary files /dev/null and b/tests/cursors/mac/nw-resize.png differ diff --git a/tests/cursors/mac/pointer.png b/tests/cursors/mac/pointer.png new file mode 100644 index 000000000..45fbd2b77 Binary files /dev/null and b/tests/cursors/mac/pointer.png differ diff --git a/tests/cursors/mac/s-resize.png b/tests/cursors/mac/s-resize.png new file mode 100644 index 000000000..1242980a4 Binary files /dev/null and b/tests/cursors/mac/s-resize.png differ diff --git a/tests/cursors/mac/se-resize.png b/tests/cursors/mac/se-resize.png new file mode 100644 index 000000000..b6c5e3956 Binary files /dev/null and b/tests/cursors/mac/se-resize.png differ diff --git a/tests/cursors/mac/sw-resize.png b/tests/cursors/mac/sw-resize.png new file mode 100644 index 000000000..da3f6d05f Binary files /dev/null and b/tests/cursors/mac/sw-resize.png differ diff --git a/tests/cursors/mac/text.png b/tests/cursors/mac/text.png new file mode 100644 index 000000000..2257903e9 Binary files /dev/null and b/tests/cursors/mac/text.png differ diff --git a/tests/cursors/mac/w-resize.png b/tests/cursors/mac/w-resize.png new file mode 100644 index 000000000..583ce1862 Binary files /dev/null and b/tests/cursors/mac/w-resize.png differ diff --git a/tests/cursors/win/auto.png b/tests/cursors/win/auto.png new file mode 100644 index 000000000..b2c5c858c Binary files /dev/null and b/tests/cursors/win/auto.png differ diff --git a/tests/cursors/win/crosshair.png b/tests/cursors/win/crosshair.png new file mode 100644 index 000000000..02c99b7fd Binary files /dev/null and b/tests/cursors/win/crosshair.png differ diff --git a/tests/cursors/win/default.png b/tests/cursors/win/default.png new file mode 100644 index 000000000..b2c5c858c Binary files /dev/null and b/tests/cursors/win/default.png differ diff --git a/tests/cursors/win/e-resize.png b/tests/cursors/win/e-resize.png new file mode 100644 index 000000000..056eb699f Binary files /dev/null and b/tests/cursors/win/e-resize.png differ diff --git a/tests/cursors/win/help.png b/tests/cursors/win/help.png new file mode 100644 index 000000000..b8034bb7b Binary files /dev/null and b/tests/cursors/win/help.png differ diff --git a/tests/cursors/win/move.png b/tests/cursors/win/move.png new file mode 100644 index 000000000..627e79937 Binary files /dev/null and b/tests/cursors/win/move.png differ diff --git a/tests/cursors/win/n-resize.png b/tests/cursors/win/n-resize.png new file mode 100644 index 000000000..d06244cbb Binary files /dev/null and b/tests/cursors/win/n-resize.png differ diff --git a/tests/cursors/win/ne-resize.png b/tests/cursors/win/ne-resize.png new file mode 100644 index 000000000..79f6c3ae3 Binary files /dev/null and b/tests/cursors/win/ne-resize.png differ diff --git a/tests/cursors/win/none.cur b/tests/cursors/win/none.cur new file mode 100644 index 000000000..4f7970a9f Binary files /dev/null and b/tests/cursors/win/none.cur differ diff --git a/tests/cursors/win/none.png b/tests/cursors/win/none.png new file mode 100644 index 000000000..1764445c9 Binary files /dev/null and b/tests/cursors/win/none.png differ diff --git a/tests/cursors/win/nw-resize.png b/tests/cursors/win/nw-resize.png new file mode 100644 index 000000000..af48a12d2 Binary files /dev/null and b/tests/cursors/win/nw-resize.png differ diff --git a/tests/cursors/win/pointer.png b/tests/cursors/win/pointer.png new file mode 100644 index 000000000..7d07182a9 Binary files /dev/null and b/tests/cursors/win/pointer.png differ diff --git a/tests/cursors/win/s-resize.png b/tests/cursors/win/s-resize.png new file mode 100644 index 000000000..d06244cbb Binary files /dev/null and b/tests/cursors/win/s-resize.png differ diff --git a/tests/cursors/win/se-resize.png b/tests/cursors/win/se-resize.png new file mode 100644 index 000000000..af48a12d2 Binary files /dev/null and b/tests/cursors/win/se-resize.png differ diff --git a/tests/cursors/win/sw-resize.png b/tests/cursors/win/sw-resize.png new file mode 100644 index 000000000..79f6c3ae3 Binary files /dev/null and b/tests/cursors/win/sw-resize.png differ diff --git a/tests/cursors/win/text.png b/tests/cursors/win/text.png new file mode 100644 index 000000000..ce8dc22ee Binary files /dev/null and b/tests/cursors/win/text.png differ diff --git a/tests/cursors/win/w-resize.png b/tests/cursors/win/w-resize.png new file mode 100644 index 000000000..056eb699f Binary files /dev/null and b/tests/cursors/win/w-resize.png differ diff --git a/tests/draggable.html b/tests/draggable.html new file mode 100644 index 000000000..a70fb0df7 --- /dev/null +++ b/tests/draggable.html @@ -0,0 +1,41 @@ + + + + + +Draggable Test Page + + + + + + + + + + + + + + + +

      Draggable Test Suite

      + +

      + +
      +
      Static
      +
      Absolute
      +
      + +
        + + + diff --git a/tests/draggable.js b/tests/draggable.js new file mode 100644 index 000000000..299017b90 --- /dev/null +++ b/tests/draggable.js @@ -0,0 +1,494 @@ +/* + * draggable unit tests + */ + +// +// Draggable Test Helper Functions +// +var el, offsetBefore, offsetAfter, dragged; + +var drag = function(handle, dx, dy) { + var element = el.data("draggable").element; + offsetBefore = el.offset(); + $(handle).simulate("drag", { + dx: dx || 0, + dy: dy || 0 + }); + dragged = { dx: dx, dy: dy }; + offsetAfter = el.offset(); +} + +var moved = function (dx, dy, msg) { + msg = msg ? msg + "." : ""; + var actual = { left: offsetAfter.left, top: offsetAfter.top }; + var expected = { left: offsetBefore.left + dx, top: offsetAfter.top }; + compare2(actual, expected, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ' + msg); +} + +function shouldmove(why) { + drag(el, 50, 50); + moved(50, 50, why); +} + +function shouldnotmove(why) { + drag(el, 50, 50); + moved(0, 0, why); +} + +var border = function(el, side) { return parseInt(el.css('border-' + side + '-width')); } + +var margin = function(el, side) { return parseInt(el.css('margin-' + side)); } + +// Draggable Tests +module("Draggable"); + +test("init", function() { + expect(6); + + el = $("#draggable1").draggable(); + ok(true, '.draggable() called on element'); + + $([]).draggable(); + ok(true, '.draggable() called on empty collection'); + + $("
        ").draggable(); + ok(true, '.draggable() called on disconnected DOMElement'); + + $("
        ").draggable().draggable("foo"); + ok(true, 'arbitrary method called after init'); + + $("
        ").draggable().data("foo.draggable"); + ok(true, 'arbitrary option getter after init'); + + $("
        ").draggable().data("foo.draggable", "bar"); + ok(true, 'arbitrary option setter after init'); +}); + +test("destroy", function() { + expect(6); + + $("#draggable1").draggable().draggable("destroy"); + ok(true, '.draggable("destroy") called on element'); + + $([]).draggable().draggable("destroy"); + ok(true, '.draggable("destroy") called on empty collection'); + + $("
        ").draggable().draggable("destroy"); + ok(true, '.draggable("destroy") called on disconnected DOMElement'); + + $("
        ").draggable().draggable("destroy").draggable("foo"); + ok(true, 'arbitrary method called after destroy'); + + $("
        ").draggable().draggable("destroy").data("foo.draggable"); + ok(true, 'arbitrary option getter after destroy'); + + $("
        ").draggable().draggable("destroy").data("foo.draggable", "bar"); + ok(true, 'arbitrary option setter after destroy'); +}); + +test("enable", function() { + expect(6); + el = $("#draggable2").draggable({ disabled: true }); + shouldnotmove('.draggable({ disabled: true })'); + el.draggable("enable"); + shouldmove('.draggable("enable")'); + equals(el.data("disabled.draggable"), false, "disabled.draggable getter"); + + el.draggable("destroy"); + el.draggable({ disabled: true }); + shouldnotmove('.draggable({ disabled: true })'); + el.data("disabled.draggable", false); + equals(el.data("disabled.draggable"), false, "disabled.draggable setter"); + shouldmove('.data("disabled.draggable", false)'); +}); + +test("disable", function() { + expect(6); + el = $("#draggable2").draggable({ disabled: false }); + shouldmove('.draggable({ disabled: false })'); + el.draggable("disable"); + shouldnotmove('.draggable("disable")'); + equals(el.data("disabled.draggable"), true, "disabled.draggable getter"); + + el.draggable("destroy"); + + el.draggable({ disabled: false }); + shouldmove('.draggable({ disabled: false })'); + el.data("disabled.draggable", true); + equals(el.data("disabled.draggable"), true, "disabled.draggable setter"); + shouldnotmove('.data("disabled.draggable", true)'); +}); + +test("element types", function() { + var typeNames = ('p,h1,h2,h3,h4,h5,h6,blockquote,ol,ul,dl,div,form' + + ',table,fieldset,address,ins,del,em,strong,q,cite,dfn,abbr' + + ',acronym,code,samp,kbd,var,img,object,hr' + + ',input,button,label,select,iframe').split(','); + + $.each(typeNames, function(i) { + var typeName = typeNames[i]; + el = $(document.createElement(typeName)).appendTo('body'); + (typeName == 'table' && el.append("content")); + el.draggable({ cancel: '' }); + drag(el, 50, 50); + moved(50, 50, "<" + typeName + ">"); + el.draggable("destroy"); + el.remove(); + }); +}); + +test("defaults", function() { + el = $("#draggable1").draggable(); + equals(el.data("appendTo.draggable"), "parent", "appendTo"); + equals(el.data("axis.draggable"), false, "axis"); + equals(el.data("cancel.draggable"), ":input,button", "cancel"); + equals(el.data("delay.draggable"), 0, "delay"); + equals(el.data("disabled.draggable"), false, "disabled"); + equals(el.data("distance.draggable"), 0, "distance"); + equals(el.data("helper.draggable"), "original", "helper"); +}); + +test("No options, relative", function() { + el = $("#draggable1").draggable(); + drag(el, 50, 50); + moved(50, 50); +}); + +test("No options, absolute", function() { + el = $("#draggable2").draggable(); + drag(el, 50, 50); + moved(50, 50); +}); + +module("Draggable Options"); + +test("{ axis: false }, default", function() { + el = $("#draggable2").draggable({ axis: false }); + drag(el, 50, 50); + moved(50, 50); +}); + +test("{ axis: 'x' }", function() { + el = $("#draggable2").draggable({ axis: "x" }); + drag(el, 50, 50); + moved(50, 0); +}); + +test("{ axis: 'y' }", function() { + el = $("#draggable2").draggable({ axis: "y" }); + drag(el, 50, 50); + moved(0, 50); +}); + +test("{ axis: ? }, unexpected", function() { + var unexpected = { + "true": true, + "{}": {}, + "[]": [], + "null": null, + "undefined": undefined, + "function() {}": function() {} + }; + $.each(unexpected, function(key, val) { + el = $("#draggable2").draggable({ axis: val }); + drag(el, 50, 50); + moved(50, 50, "axis: " + key); + el.draggable("destroy"); + }) +}); + +test("{ cancel: 'span' }", function() { + el = $("#draggable2").draggable(); + drag("#draggable2 span", 50, 50); + moved(50, 50); + + el.draggable("destroy"); + + el = $("#draggable2").draggable({ cancel: 'span' }); + drag("#draggable2 span", 50, 50); + moved(0, 0); +}); + +test("{ cancel: ? }, unexpected", function() { + var unexpected = { + "true": true, + "false": false, + "{}": {}, + "[]": [], + "null": null, + "undefined": undefined, + "function() {return '';}": function() {return '';}, + "function() {return true;}": function() {return true;}, + "function() {return false;}": function() {return false;} + }; + $.each(unexpected, function(key, val) { + el = $("#draggable2").draggable({ cancel: val }); + drag(el, 50, 50); + var expected = [50, 50]; + switch(key) { + case "true": + expected = [0, 0] + break; + } + moved(expected[0], expected[1], "cancel: " + key); + el.draggable("destroy"); + }) +}); + +test("{ containment: 'parent' }, relative", function() { + el = $("#draggable1").draggable({ containment: 'parent' }); + var p = el.parent(), po = p.offset(); + drag(el, -100, -100); + var expected = { + left: po.left + border(p, 'left') + margin(el, 'left'), + top: po.top + border(p, 'top') + margin(el, 'top') + } + compare2(offsetAfter, expected, 'compare offset to parent'); +}); + +test("{ containment: 'parent' }, absolute", function() { + el = $("#draggable2").draggable({ containment: 'parent' }); + var p = el.parent(), po = p.offset(); + drag(el, -100, -100); + var expected = { + left: po.left + border(p, 'left') + margin(el, 'left'), + top: po.top + border(p, 'top') + margin(el, 'top') + } + compare2(offsetAfter, expected, 'compare offset to parent'); +}); + +test("{ cursor: 'move' }", function() { + + function getCursor() { return $("body").css("cursor"); } + + expect(2); + + var expected = "move", actual, before, after; + + el = $("#draggable2").draggable({ + cursor: expected, + start: function(e, ui) { + actual = getCursor(); + } + }); + + before = getCursor(); + drag("#draggable2", -1, -1); + after = getCursor(); + + equals(actual, expected, "start callback: cursor '" + expected + "'"); + equals(after, before, "after drag: cursor restored"); + +}); + +test("{ cursorAt: { left: -5, top: -5 } }", function() { + + expect(4); + + var dx = -3, dy = -3; + var ox = 5, oy = 5; + var cax = -5, cay = -5; + + var actual = null; + $("#draggable2").draggable({ + cursorAt: { left: cax, top: cay }, + drag: function(e, ui) { + actual = ui.absolutePosition; + } + }); + var el = $("#draggable2").data("draggable").element; + + var before = el.offset(); + var pos = { clientX: before.left + ox, clientY: before.top + oy }; + $("#draggable2").simulate("mousedown", pos); + pos = { clientX: pos.clientX + dx, clientY: pos.clientY + dy }; + $(document).simulate("mousemove", pos); + $(document).simulate("mousemove", pos); + $("#draggable2").simulate("mouseup", pos); + var expected = { + left: before.left + ox - cax + dx, + top: before.top + oy - cay + dy + }; + + equals(actual.left, expected.left, "Absolute: -1px left"); + equals(actual.top, expected.top, "Absolute: -1px top"); + + var actual = null; + $("#draggable1").draggable({ + cursorAt: { left: cax, top: cay }, + drag: function(e, ui) { + actual = ui.absolutePosition; + } + }); + var el = $("#draggable2").data("draggable").element; + + var before = el.offset(); + var pos = { clientX: before.left + ox, clientY: before.top + oy }; + $("#draggable2").simulate("mousedown", pos); + pos = { clientX: pos.clientX + dx, clientY: pos.clientY + dy }; + $(document).simulate("mousemove", pos); + $(document).simulate("mousemove", pos); + $("#draggable2").simulate("mouseup", pos); + var expected = { + left: before.left + ox - cax + dx, + top: before.top + oy - cay + dy + }; + + equals(actual.left, expected.left, "Relative: -1px left"); + equals(actual.top, expected.top, "Relative: -1px top"); + +}); + +test("{ distance: 10 }", function() { + + el = $("#draggable2").draggable({ distance: 10 }); + drag(el, -9, -9); + moved(0, 0, 'distance not met'); + + drag(el, -10, -10); + moved(-10, -10, 'distance met'); + + drag(el, 9, 9); + moved(0, 0, 'distance not met'); + +}); + +test("{ grid: [50, 50] }, relative", function() { + el = $("#draggable1").draggable({ grid: [50, 50] }); + drag(el, 24, 24); + moved(0, 0); + drag(el, 26, 25); + moved(50, 50); +}); + +test("{ grid: [50, 50] }, absolute", function() { + el = $("#draggable2").draggable({ grid: [50, 50] }); + drag(el, 24, 24); + moved(0, 0); + drag(el, 26, 25); + moved(50, 50); +}); + +test("{ handle: 'span' }", function() { + el = $("#draggable2").draggable({ handle: 'span' }); + + drag("#draggable2 span", 50, 50); + moved(50, 50, "drag span"); + + drag("#draggable2", 50, 50); + moved(0, 0, "drag element"); +}); + +test("{ helper: 'clone' }, relative", function() { + el = $("#draggable1").draggable({ helper: "clone" }); + drag(el, 50, 50); + moved(0, 0); +}); + +test("{ helper: 'clone' }, absolute", function() { + el = $("#draggable2").draggable({ helper: "clone" }); + drag(el, 50, 50); + moved(0, 0); +}); + +test("{ opacity: 0.5 }", function() { + + expect(1); + + var opacity = null; + el = $("#draggable2").draggable({ + opacity: 0.5, + start: function(e, ui) { + opacity = $(this).css("opacity"); + } + }); + + drag("#draggable2", -1, -1); + + equals(opacity, 0.5, "start callback: opacity is"); + +}); + +test("{ zIndex: 10 }", function() { + + expect(1); + + var expected = 10, actual; + + var zIndex = null; + el = $("#draggable2").draggable({ + zIndex: expected, + start: function(e, ui) { + actual = $(this).css("zIndex"); + } + }); + + drag("#draggable2", -1, -1); + + equals(actual, expected, "start callback: zIndex is"); + +}); + +module("Draggable Callbacks"); + +test("callbacks occurance count", function() { + + expect(3); + + var start = 0, stop = 0, dragc = 0; + el = $("#draggable2").draggable({ + start: function() { start++; }, + drag: function() { dragc++; }, + stop: function() { stop++; } + }); + + drag(el, 10, 10); + + equals(start, 1, "start callback should happen exactly once"); + equals(dragc, 2 + 1, "drag callback should happen exactly once per mousemove + 1"); + equals(stop, 1, "stop callback should happen exactly once"); + +}); + +module("Tickets"); + +test("#2965 cursorAt with margin", function() { + + expect(2); + + var ox = 0, oy = 0; + + var actual, expected; + $("#draggable2").draggable({ + cursorAt: { left: ox, top: oy }, + drag: function(e, ui) { + actual = ui.absolutePosition; + } + }); + var el = $("#draggable2").data("draggable").element; + + $("#draggable2").css('margin', '0px !important'); + + var before = el.offset(); + var pos = { clientX: before.left + ox, clientY: before.top + oy }; + $("#draggable2").simulate("mousedown", pos); + $(document).simulate("mousemove", pos); + $(document).simulate("mousemove", pos); + $("#draggable2").simulate("mouseup", pos); + var expected = actual; + actual = undefined; + + var marg = 13; + + $("#draggable2").css('margin', marg + 'px !important'); + var before = el.offset(); + var pos = { clientX: before.left + ox - marg, clientY: before.top + oy - marg }; + $("#draggable2").simulate("mousedown", pos); + $(document).simulate("mousemove", pos); + $(document).simulate("mousemove", pos); + $("#draggable2").simulate("mouseup", pos); + + equals(actual.left, expected.left, "10px margin. left"); + equals(actual.top, expected.top, "10px margin. top"); + +}); diff --git a/tests/images/click.png b/tests/images/click.png new file mode 100644 index 000000000..2b32f8d84 Binary files /dev/null and b/tests/images/click.png differ diff --git a/tests/images/test.jpg b/tests/images/test.jpg new file mode 100644 index 000000000..7d8ec0996 Binary files /dev/null and b/tests/images/test.jpg differ diff --git a/tests/jquery.useraction.js b/tests/jquery.useraction.js new file mode 100644 index 000000000..82ec0cd22 --- /dev/null +++ b/tests/jquery.useraction.js @@ -0,0 +1,347 @@ +/* Copyright (c) 2007 Eduardo Lundgren (eduardolundgren@gmail.com) + * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) + * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses. + * + * Version: 0.1a + * Date: May, 2008 + * Requires jQuery 1.2.x+ + * Docs: http://docs.jquery.com/Plugins/userAction + * Greetings: Richard Worth + */ + +;(function($) { + +$.fn.extend({ + userAction: function(type) { + var args = arguments, opts = {}, a1 = args[1], a2 = args[2]; + + // transfer center offset + if (a1 && a1.length) { + opts.center = [a1[0], a1[1]]; + } + // set x and y + else if (typeof a1 == StringPool.NUMBER) { + opts.x = a1; opts.y = a2; + } + // extend options + else { + $.extend(opts, a1); + } + + return this.each(function() { + new $.userAction(this, type, opts); + }); + } +}); + +$.userAction = function(el, type, options) { + this.type = type; + this.options = $.extend({}, $.userAction.defaults, options || {}); + this.target = $(this.options.target || el)[0]; + + var self = this, o = this.options, c = o.center, center = { x: 0, y: 0 }; + + if (!o.x && !o.y) { + center = this.findCenter( + c && c.length ? c : [0, 0] + ) + } + + // if x and y not set, get the center of the element + o.x = o.x || center.x; o.y = o.y || center.y; + + var EVENT_DEFAULT = { + target: this.target, + view: window, + bubbles: o.bubbles || true, + cancelable: o.cancelable || false, + ctrlKey: o.ctrlKey || false, + altKey: o.altKey || false, + shiftKey: o.shiftKey || false, + metaKey: o.metaKey || false + }; + + // Simulating drag and drop event + if (/^drag$/i.test(type)) { + var self = this, t = this.target, queue = $.data(t, StringPool.DATA_QUEUE), + data = [options.dx || options.x, options.dy || options.y, this]; + + var fire = function() { + self.drag(options.dx || options.x, options.dy || options.y); + }; + + if (/^sync$/i.test(o.speed)) { + fire(); return; + } + + if (!queue) { + $.data(t, StringPool.DATA_QUEUE, [data]); fire(); return; + } + // queuing drags... + if (queue && queue.length) { + queue.push(data); + } + // if drag, stop here. + return; + } + + var isMouse = /^mouse(over|out|down|up|move)|(dbl)?click$/i.test(type), + isKeyboard = /^textevent|key(up|down|press)$/i.test(type), + + EVT = isMouse ? + $.extend({}, EVENT_DEFAULT, { + clientX: o.x, clientY: o.y, + screenX: o.screenX || 0, screenY: o.screenY || 0, + relatedTarget: $(o.relatedTarget)[0] || null, detail: 0, + button: o.button || ($.browser.msie ? 1 : 0), isTrusted: false + }) : + $.extend({}, EVENT_DEFAULT, { + keyCode: o.keyCode || 0, charCode: o.charCode || 0 + }); + + // avoid e.type == undefined before dispatchment + EVT.type = type; + + if (o.before) o.before.apply(this.target, [$.event.fix(EVT), o.x, o.y, this]); + + // check event type for mouse events + if (isMouse) { + // simulating mouse event + EVT = this.mouseEvent(EVT) + } + + // check event type for key events + if (isKeyboard) { + // simulating keuboard event + EVT = this.keyboardEvent(EVT); + } + + if (o.after) o.after.apply(this.target, [$.event.fix(EVT), o.x, o.y, this]); +}; + +$.extend($.userAction.prototype, { + + down: function(target) { + $(target).userAction(StringPool.MOUSEOVER).userAction(StringPool.MOUSEDOWN) + .userAction(StringPool.MOUSEMOVE); + }, + + up: function(target) { + $(target).userAction(StringPool.MOUSEUP).userAction(StringPool.MOUSEOUT); + }, + + move: function(target, x, y, after) { + $(target).userAction(StringPool.MOUSEMOVE, { x: x, y: y, after: after }); + }, + + drag: function(dx, dy) { + // drag helper function, thanks Richard Worth's testmouse api. + var self = this, o = this.options, center = this.findCenter(), + target = $(this.target), lastx = center.x, lasty = center.y, + fake = $(StringPool.FAKE_CURSOR_EXP), + speed = o.speed || StringPool.SLOW, + easing = o.easing || StringPool.SWING; + + var complete = function() { + // fire complete or after cb + if (o.after||o.complete) (o.after||o.complete).apply(self.target, [o, self]); + }; + + // drag synchronously + if (/^sync$/i.test(o.speed)) { + self.down(target); + + var mdx = Math.abs(dx)||0, mdy = Math.abs(dy)||0, range = Math.max(mdx, mdy), + sx = dx/mdx||1, sy = dy/mdy||1; + + for (var dt = 1; dt <= range; dt++) { + var x = center.x + sx*(dt <= mdx ? dt : 0), y = center.y + sy*(dt <= mdy ? dt : 0); + this.move(target, x, y, o.drag); + } + self.up(target); + complete(); + return; + } + + // drag asynchronously - animated + fake = fake.size() ? fake : + $(StringPool.FAKE_CURSOR_DIV) + .css({ position: StringPool.ABSOLUTE }).appendTo(document.body); + + fake + .animate({ left: center.x, top: center.y }, speed, easing, function(){ + self.down(target); + }) + .animate({ left: center.x + (dx||0), top: center.y + (dy||0) }, { + speed: speed, + easing: easing, + step: function(i, anim) { + lastx = anim.prop == StringPool.LEFT ? i : lastx; + lasty = anim.prop == StringPool.TOP ? i : lasty; + self.move(target, lastx, lasty, o.drag); + }, + complete: function() { + + self.up(target); + + // remove fake cursor + $(this).remove(); + + complete(); + + // trigger drag queue + var queue = $.data(self.target, StringPool.DATA_QUEUE); + if (queue) queue.shift(); + + if (queue && queue[0]) { + // trigger drag on correct instance + queue[0][2].drag(queue[0][0], queue[0][1]); + } + else + $.removeData(self.target, StringPool.DATA_QUEUE); + } + }); + }, + + mouseEvent: function(EVT) { + var evt, type = this.type, o = this.options; + + //check for DOM-compliant browsers + if ($.isFunction(document.createEvent)) { + evt = document.createEvent(StringPool.MOUSE_EVENTS); + + //Safari 2.x doesn't implement initMouseEvent() + if ($.isFunction(evt.initMouseEvent)) { + evt.initMouseEvent(type, + EVT.bubbles, EVT.cancelable, EVT.view, EVT.detail, + EVT.screenX, EVT.screenY, EVT.clientX, EVT.clientY, + EVT.ctrlKey, EVT.altKey, EVT.shiftKey, EVT.metaKey, + EVT.button, EVT.relatedTarget); + } else { + // Safari + evt = document.createEvent(StringPool.UI_EVENTS); + customEvent.initEvent(type, EVT.bubbles, EVT.cancelable); + $.extend(evt, EVT); + } + + // check to see if relatedTarget has been assigned + if (EVT.relatedTarget && !evt.relatedTarget){ + if (type == StringPool.MOUSEOUT) { + evt.toElement = EVT.relatedTarget; + } else if (type == StringPool.MOUSEOVER) { + evt.fromElement = EVT.relatedTarget; + } + } + // fire the event + this.target.dispatchEvent(evt); + + } else if (document.createEventObject) { + evt = document.createEventObject(); + + // assign available properties + $.extend(evt, EVT) + + // IE won't allow assignment to toElement or fromElement + evt.relatedTarget = EVT.relatedTarget; + + // fix for 2 pixels bug from mousecords + evt.pageX = o.x; evt.pageY = o.y; + + // fire the event + this.target.fireEvent(StringPool.ON + type, evt); + } + + return evt; + }, + + keyboardEvent: function(EVT) { + var evt, type = this.type, o = this.options; + + // check for DOM-compliant browsers first + if ($.isFunction(document.createEvent)) { + + try { + // try to create key event + evt = document.createEvent(StringPool.KEY_EVENTS); + + evt.initKeyEvent(type, + EVT.bubbles, EVT.cancelable, EVT.view, EVT.ctrlKey, + EVT.altKey, EVT.shiftKey, EVT.metaKey, EVT.keyCode, EVT.charCode); + + } catch (err) { + // we need another try-catch for Safari 2.x + try { + // generic event for opera and webkit nightlies, will fail in Safari 2.x + evt = document.createEvent(StringPool.EVENTS); + } catch (ierr){ + // Safari 2.x - create a UIEvent + evt = document.createEvent(StringPool.UI_EVENTS); + } finally { + evt.initEvent(type, EVT.bubbles, EVT.cancelable); + + // initializing + $.each(EVT, function(k, v) { + // using try-catch for avoiding Opera NO_MODIFICATION_ALLOWED_ERR + try { evt[k] = v; } catch(e) { } + }); + } + } + + // fire the event + this.target.dispatchEvent(evt); + + } else if (document.createEventObject) { + // create an IE event object + evt = document.createEventObject(); + + // assign available properties + $.extend(evt, EVT); + + // IE doesn't support charCode explicitly + evt.keyCode = (EVT.charCode > 0) ? EVT.charCode : EVT.keyCode; + + // fire the event + this.target.fireEvent(StringPool.ON + type, evt); + } + + return evt; + }, + + findCenter: function(offset) { + var el = $(this.target), o = el.offset(); + return { + x: o.left + (((offset||[0, 0])[0]) || 0) + el.outerWidth() / 2, + y: o.top + (((offset||[0, 0])[1]) || 0) + el.outerHeight() / 2 + }; + } +}); + +$.extend($.userAction, { + defaults: { + center: true + } +}); + +var StringPool = { + ON: 'on', + NUMBER: 'number', + MOUSEOVER: 'mouseover', + MOUSEOUT: 'mouseout', + MOUSEDOWN: 'mousedown', + MOUSEUP: 'mouseup', + MOUSEMOVE: 'mousemove', + MOUSE_EVENTS: 'MouseEvents', + UI_EVENTS: 'UIEvents', + KEY_EVENTS: 'KeyEvents', + EVENTS: 'Events', + FAKE_CURSOR_EXP: 'div.ui-fake-cursor', + FAKE_CURSOR_DIV: '
        ', + ABSOLUTE: 'absolute', + DATA_QUEUE: 'ua-drag-queue', + TOP: 'top', + LEFT: 'left', + SLOW: 'slow', + SWING: 'swing' +}; + +})(jQuery); \ No newline at end of file diff --git a/tests/resizable.html b/tests/resizable.html new file mode 100644 index 000000000..685ec88c9 --- /dev/null +++ b/tests/resizable.html @@ -0,0 +1,41 @@ + + + + + +Resizable Test Page + + + + + + + + + + + + + + + + +

        jQuery Test Suite

        + +

        + +
        +
        I'm a resizable.
        + +
        + +
          +
          + + diff --git a/tests/resizable.js b/tests/resizable.js new file mode 100644 index 000000000..48582e016 --- /dev/null +++ b/tests/resizable.js @@ -0,0 +1,400 @@ +/* + * resizable tests + */ + +var drag = function(el, dx, dy, complete) { + + // speed = sync -> Drag syncrhonously. + // speed = fast|slow -> Drag asyncrhonously - animated. + + return $(el).simulate("drag", { + dx: dx||0, dy: dy||0, speed: 'sync', complete: complete + }); +}; + +module("Simple Resize"); + +test("ui-resizable-e resize x", function() { + + var handle = '.ui-resizable-e', target = $('#resizable1').resizable({ handles: 'all' }); + + expect(2); + + drag(handle, 50); + + equals( target.width(), 150, "compare width"); + + drag(handle, -50); + + equals( target.width(), 100, "compare width" ); + +}); + +test("ui-resizable-w resize x", function() { + + var handle = '.ui-resizable-w', target = $('#resizable1').resizable({ handles: 'all' }); + + expect(2); + + drag(handle, -50); + + equals( target.width(), 150, "compare width" ); + + drag(handle, 50); + + equals( target.width(), 100, "compare width" ); + +}); + +test("ui-resizable-n resize y", function() { + + var handle = '.ui-resizable-n', target = $('#resizable1').resizable({ handles: 'all' }); + + expect(2); + + drag(handle, 0, -50); + + equals( target.height(), 150, "compare height" ); + + drag(handle, 0, 50); + + equals( target.height(), 100, "compare height" ); + +}); + +test("ui-resizable-s resize y", function() { + + var handle = '.ui-resizable-s', target = $('#resizable1').resizable({ handles: 'all' }); + + expect(2); + + drag(handle, 0, 50); + + equals( target.height(), 150, "compare height" ); + + drag(handle, 0, -50); + + equals( target.height(), 100, "compare height" ); + +}); + +test("ui-resizable-se resize xy", function() { + + var handle = '.ui-resizable-se', target = $('#resizable1').resizable({ handles: 'all' }); + + expect(4); + + drag(handle, 50, 50); + + equals( target.width(), 150, "compare width" ); + equals( target.height(), 150, "compare height" ); + + drag(handle, -50, -50); + + equals( target.width(), 100, "compare width" ); + equals( target.height(), 100, "compare height" ); + +}); + +test("ui-resizable-sw resize xy", function() { + + var handle = '.ui-resizable-sw', target = $('#resizable1').resizable({ handles: 'all' }); + + expect(4); + + drag(handle, -50, -50); + + equals( target.width(), 150, "compare width" ); + equals( target.height(), 50, "compare height" ); + + drag(handle, 50, 50); + + equals( target.width(), 100, "compare width" ); + equals( target.height(), 100, "compare height" ); + +}); + +test("ui-resizable-ne resize xy", function() { + + var handle = '.ui-resizable-ne', target = $('#resizable1').css({ overflow: 'hidden' }).resizable({ handles: 'all' }); + + expect(4); + + drag(handle, -50, -50); + + equals( target.width(), 50, "compare width" ); + equals( target.height(), 150, "compare height" ); + + drag(handle, 50, 50); + + equals( target.width(), 100, "compare width" ); + equals( target.height(), 100, "compare height" ); + +}); + +test("ui-resizable-nw resize xy", function() { + + var handle = '.ui-resizable-nw', target = $('#resizable1').resizable({ handles: 'all' }); + + expect(4); + + drag(handle, -50, -50); + + equals( target.width(), 150, "compare width" ); + equals( target.height(), 150, "compare height" ); + + drag(handle, 50, 50); + + equals( target.width(), 100, "compare width" ); + equals( target.height(), 100, "compare height" ); + +}); + +/** + * Conditional Resize + * min/max Height/Width + */ + +module("Dimensions limit"); + +test("ui-resizable-se { handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }", function() { + + var handle = '.ui-resizable-se', target = $('#resizable1').resizable({ handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }); + + expect(4); + + drag(handle, -50, -50); + + equals( target.width(), 60, "compare minWidth" ); + equals( target.height(), 60, "compare minHeight" ); + + drag(handle, 70, 70); + + equals( target.width(), 100, "compare maxWidth" ); + equals( target.height(), 100, "compare maxHeight" ); + +}); + +test("ui-resizable-sw { handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }", function() { + + var handle = '.ui-resizable-sw', target = $('#resizable1').resizable({ handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }); + + expect(4); + + drag(handle, 50, -50); + + equals( target.width(), 60, "compare minWidth" ); + equals( target.height(), 60, "compare minHeight" ); + + drag(handle, -70, 70); + + equals( target.width(), 100, "compare maxWidth" ); + equals( target.height(), 100, "compare maxHeight" ); + +}); + +test("ui-resizable-ne { handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }", function() { + + var handle = '.ui-resizable-ne', target = $('#resizable1').resizable({ handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }); + + expect(4); + + drag(handle, -50, 50); + + equals( target.width(), 60, "compare minWidth" ); + equals( target.height(), 60, "compare minHeight" ); + + drag(handle, 70, -70); + + equals( target.width(), 100, "compare maxWidth" ); + equals( target.height(), 100, "compare maxHeight" ); + +}); + +test("ui-resizable-nw { handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }", function() { + + var handle = '.ui-resizable-nw', target = $('#resizable1').resizable({ handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }); + + expect(4); + + drag(handle, 70, 70); + + equals( target.width(), 60, "compare minWidth" ); + equals( target.height(), 60, "compare minHeight" ); + + drag(handle, -70, -70); + + equals( target.width(), 100, "compare maxWidth" ); + equals( target.height(), 100, "compare maxHeight" ); + +}); + +/** + * Respecting ratio resize with dimensions limit + */ + +module("Respecting ratio resize with dimensions limits"); + +test("ui-resizable-e { aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }", function() { + + var handle = '.ui-resizable-e', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }); + + expect(4); + + drag(handle, 80); + + equals( target.width(), 130, "compare maxWidth"); + equals( target.height(), 130, "compare maxHeight"); + + drag(handle, -130); + + equals( target.width(), 70, "compare minWidth"); + equals( target.height(), 70, "compare minHeight"); + +}); + +test("ui-resizable-w { aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }", function() { + + var handle = '.ui-resizable-w', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }); + + expect(4); + + drag(handle, -80); + + equals( target.width(), 130, "compare maxWidth"); + equals( target.height(), 130, "compare maxHeight"); + + drag(handle, 130); + + equals( target.width(), 70, "compare minWidth"); + equals( target.height(), 70, "compare minHeight"); + +}); + +test("ui-resizable-n { aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }", function() { + + var handle = '.ui-resizable-n', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }); + + expect(4); + + drag(handle, 0, -80); + + equals( target.width(), 130, "compare maxWidth"); + equals( target.height(), 130, "compare maxHeight"); + + 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() { + + var handle = '.ui-resizable-s', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }); + + expect(4); + + drag(handle, 0, 80); + + equals( target.width(), 130, "compare maxWidth"); + equals( target.height(), 130, "compare maxHeight"); + + drag(handle, 0, -80); + + equals( target.width(), 70, "compare minWidth"); + equals( target.height(), 70, "compare minHeight"); + +}); + +test("ui-resizable-se { aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }", function() { + + var handle = '.ui-resizable-se', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }); + + expect(4); + + drag(handle, 80, 80); + + equals( target.width(), 130, "compare maxWidth"); + equals( target.height(), 130, "compare maxHeight"); + + drag(handle, -80, -80); + + equals( target.width(), 70, "compare minWidth"); + equals( target.height(), 70, "compare minHeight"); + +}); + +test("ui-resizable-sw { aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }", function() { + + var handle = '.ui-resizable-sw', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }); + + expect(4); + + drag(handle, -80, 80); + + equals( target.width(), 130, "compare maxWidth"); + equals( target.height(), 130, "compare maxHeight"); + + drag(handle, 80, -80); + + equals( target.width(), 70, "compare minWidth"); + equals( target.height(), 70, "compare minHeight"); + +}); + +test("ui-resizable-ne { aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }", function() { + + var handle = '.ui-resizable-ne', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }); + + expect(4); + + drag(handle, 80, -80); + + equals( target.width(), 130, "compare maxWidth"); + equals( target.height(), 130, "compare maxHeight"); + + drag(handle, -80, 80); + + equals( target.width(), 70, "compare minWidth"); + equals( target.height(), 70, "compare minHeight"); + +}); + +module("Options"); + +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, 3, 9); + + equals( target.width(), 103, "compare width"); + equals( target.height(), 100, "compare height"); + + drag(handle, 15, 11); + + equals( target.width(), 118, "compare width"); + equals( target.height(), 120, "compare height"); + +}); + +test("ui-resizable-se { handles: 'all', grid: [0, 20] } wrapped", function() { + + var handle = '.ui-resizable-se', target = $('#resizable2').resizable({ handles: 'all', grid: [0, 20] }); + + expect(4); + + drag(handle, 3, 9); + + equals( target.width(), 103, "compare width"); + equals( target.height(), 100, "compare height"); + + drag(handle, 15, 11); + + equals( target.width(), 118, "compare width"); + equals( target.height(), 120, "compare height"); + +}); diff --git a/tests/simulate/jquery.simulate.js b/tests/simulate/jquery.simulate.js new file mode 100644 index 000000000..f5168bf3b --- /dev/null +++ b/tests/simulate/jquery.simulate.js @@ -0,0 +1,141 @@ +/* + * jquery.simulate - simulate browser mouse and keyboard events + * + * Copyright (c) 2007 Eduardo Lundgren (eduardolundgren@gmail.com) + * and Richard D. Worth (rdworth@gmail.com) + * + * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) + * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses. + * + */ + +;(function($) { + +$.fn.extend({ + simulate: function(type, options) { + return this.each(function() { + var opt = $.extend({}, $.simulate.defaults, options || {}); + new $.simulate(this, type, opt); + }); + } +}); + +$.simulate = function(el, type, options) { + this.target = el; + this.options = options; + + if (/^drag$/.test(type)) { + this[type].apply(this, [this.target, options]); + } else { + this.simulateEvent(el, type, options); + } +} + +$.extend($.simulate.prototype, { + simulateEvent: function(el, type, options) { + var evt = this.createEvent(type, options); + this.dispatchEvent(el, type, evt, options); + return evt; + }, + createEvent: function(type, options) { + if (/^mouse(over|out|down|up|move)|(dbl)?click$/.test(type)) { + return this.mouseEvent(type, options); + } else if (/^key(up|down|press)$/.test(type)) { + return this.keyboardEvent(type, options); + } + }, + mouseEvent: function(type, options) { + var evt; + var e = $.extend({ + bubbles: true, cancelable: (type != "mousemove"), view: window, detail: 0, + screenX: 0, screenY: 0, clientX: 0, clientY: 0, + ctrlKey: false, altKey: false, shiftKey: false, metaKey: false, + button: 0, relatedTarget: undefined + }, options); + + var relatedTarget = $(e.relatedTarget)[0]; + + if ($.isFunction(document.createEvent)) { + evt = document.createEvent("MouseEvents"); + evt.initMouseEvent(type, e.bubbles, e.cancelable, e.view, e.detail, + e.screenX, e.screenY, e.clientX, e.clientY, + e.ctrlKey, e.altKey, e.shiftKey, e.metaKey, + e.button, e.relatedTarget || document.body.parentNode); + } else if (document.createEventObject) { + evt = document.createEventObject(); + $.extend(evt, e); + evt.button = { 0:1, 1:4, 2:2 }[evt.button] || evt.button; + } + return evt; + }, + keyboardEvent: function(type, options) { + var evt; + + var e = $.extend({ bubbles: true, cancelable: true, view: window, + ctrlKey: false, altKey: false, shiftKey: false, metaKey: false, + keyCode: 0, charCode: 0 + }, options); + + if ($.isFunction(document.createEvent)) { + try { + evt = document.createEvent("KeyEvents"); + evt.initKeyEvent(type, e.bubbles, e.cancelable, e.view, + e.ctrlKey, e.altKey, e.shiftKey, e.metaKey, + e.keyCode, e.charCode); + } catch(err) { + evt = document.createEvent("Events"); + evt.initEvent(type, e.bubbles, e.cancelable); + $.extend(evt, { view: e.view, + ctrlKey: e.ctrlKey, altKey: e.altKey, shiftKey: e.shiftKey, metaKey: e.metaKey, + keyCode: e.keyCode, charCode: e.charCode + }); + } + } else if (document.createEventObject) { + evt = document.createEventObject(); + $.extend(evt, e); + } + if ($.browser.msie || $.browser.opera) { + evt.keyCode = (e.charCode > 0) ? e.charCode : e.keyCode; + evt.charCode = undefined; + } + return evt; + }, + + dispatchEvent: function(el, type, evt) { + if (el.dispatchEvent) { + el.dispatchEvent(evt); + } else if (el.fireEvent) { + el.fireEvent('on' + type, evt); + } + return evt; + }, + + drag: function(el) { + var self = this, center = this.findCenter(this.target), + options = this.options, x = Math.floor(center.x), y = Math.floor(center.y), + dx = options.dx || 0, dy = options.dy || 0, target = this.target; + var coord = { clientX: x, clientY: y }; + this.simulateEvent(target, "mouseover"); + this.simulateEvent(target, "mousedown", coord); + coord = { clientX: x + dx, clientY: y + dy }; + this.simulateEvent(document, "mousemove", coord); + this.simulateEvent(document, "mousemove", coord); + this.simulateEvent(target, "mouseup", coord); + this.simulateEvent(target, "mouseout"); + }, + findCenter: function(el) { + var el = $(this.target), o = el.offset(); + return { + x: o.left + el.outerWidth() / 2, + y: o.top + el.outerHeight() / 2 + }; + } +}); + +$.extend($.simulate, { + defaults: { + speed: 'sync' + } +}); + +})(jQuery); diff --git a/tests/slider.html b/tests/slider.html new file mode 100644 index 000000000..090cfd2bf --- /dev/null +++ b/tests/slider.html @@ -0,0 +1,33 @@ + + + + + +Slider Test Page + + + + + + + + + + + + +

          jQuery Test Suite

          + +

          + +
          +
          +
          +
          +
          +
          + +
            + + + diff --git a/tests/slider.js b/tests/slider.js new file mode 100644 index 000000000..7b6d095a5 --- /dev/null +++ b/tests/slider.js @@ -0,0 +1,110 @@ + +var keyCodes = { + leftArrow: 37, + upArrow: 38, + rightArrow: 39, + downArrow: 40 +}; + +$.each(keyCodes, function(key, val) { + $.fn[key] = function() { + return this.simulate("keydown", { keyCode: val }); + } +}); + +function assertChange(stepping, start, result, action) { + return function() { + expect(1); + var slider = $("#slider3").slider({ + stepping: stepping, + startValue: start, + min: 0, + max: 1000, + change: function(e, ui) { + equals(ui.value, result, "changed to " + ui.value); + } + }); + action.apply(slider); + } +} + +module("slider: single handle") + +test("change one step via keydown", assertChange(1, undefined, 1, function() { + this.find("a").rightArrow(); +})) +test("change - 10 steps via keydown", assertChange(10, 20, 10, function() { + this.find("a").leftArrow(); +})) +test("change +10 steps via keydown", assertChange(10, 20, 30, function() { + this.find("a").rightArrow(); +})) + +test("moveTo, absolute value", assertChange(1, 1, 10, function() { + this.slider("moveTo", 10); +})) + +test("moveTo, absolute value as string", assertChange(1, 1, 10, function() { + this.slider("moveTo", "10"); +})) + +test("moveTo, absolute value, below min", assertChange(1, 1, 0, function() { + this.slider("moveTo", -10); +})) + +test("moveTo, relative positive value", assertChange(1, 1, 11, function() { + this.slider("moveTo", "+=10"); +})) + +test("moveTo, relative positive value, above max", assertChange(1, 10, 1000, function() { + this.slider("moveTo", "+=2000"); +})) + +test("moveTo, relative negative value", assertChange(1, 20, 10, function() { + this.slider("moveTo", "-=10"); +})) + +test("options update min/max", function() { + expect(2); + var slider = $("#slider3").slider({ + stepping: 1, + startValue: 1 + }); + slider.slider("moveTo", "-=10"); + equals(slider.slider("value"), 0); + slider.data("min.slider", -10); + slider.slider("moveTo", "-=20"); + equals(slider.slider("value"), -10); +}) + +module("slider: setup and teardown"); + +test("destroy and recreate", function() { + expect(3) + var slider = $("#slider3").slider(); + slider.slider("moveTo", "+=20"); + equals(slider.slider("value"), 20); + slider.slider("destroy"); + + slider.slider("moveTo", "+=30"); + ok(true, "nothing happens after slider is destroyed"); + + slider.slider().slider("moveTo", "30"); + + equals(Math.round(slider.slider("value")), 30); +}) + +test("handle creation", function() { + var slider = $("#slider1"); + equals(slider.children().size(), 0); + slider.slider({ + handles: [ + { start: 0 }, + { start: 10 } + ] + }); + equals(slider.children().size(), 2); + var instance = $.data(slider[0], "slider") + equals(instance.handle.length, 2); + ok(instance.handle.jquery, "handle must be a jquery object") +}) \ No newline at end of file diff --git a/tests/ui.testmouse.js b/tests/ui.testmouse.js new file mode 100644 index 000000000..5c4d41204 --- /dev/null +++ b/tests/ui.testmouse.js @@ -0,0 +1,142 @@ +/* + * jQuery UI testMouse + * + * Copyright (c) 2008 Richard D. Worth (rdworth.org) + * Dual licensed under the MIT (MIT-LICENSE.txt) + * and GPL (GPL-LICENSE.txt) licenses. + * + * Revision: $Id: $ + */ +;(function($) { + + var mouseX = 0; + var mouseY = 0; + + $(function() { + $(document).mousemove(function(e) { + if (e.isTrusted !== false) { + mouseX = e.pageX; + mouseY = e.pageY; + } + }); + }); + + $.widget("ui.testMouse", { + trackMouse: function() {}, + init: function() { + }, + destroy: function() { + }, + center: function(offset) { + var o = this.element.offset(); + return { + x: (o.left + (offset || [0, 0])[0] || 0) + this.element.width() / 2, + y: (o.top + (offset || [0, 0])[1] || 0) + this.element.height() / 2 + }; + }, + drag: function(dx, dy) { + var self = this; + + var center = this.center(); + this.left = center.x; + this.top = center.y; + + var OS = (/(win|mac|linux)/i.exec(navigator.platform) || ['other'])[0].toLowerCase(); + + var defaultUrl = ['cursors', OS == 'other' ? 'win' : OS, 'default.png'].join('/'); + var cursorUrl = function() { + return ['cursors', OS == 'other' ? 'win' : OS, self.element.css('cursor') + '.png'].join('/'); + } + var noneUrl = ['cursors', OS == 'other' ? 'win' : OS, 'none' + ($.browser.safari ? '.png' : '.cur')].join('/'); + + var fakemouse = $(''); + var realmouse = $(''); + if ($.browser.msie && $.browser.version == 6) { + fakemouse = $('
            '); + realmouse = $('
            '); + } + var mousescreen = $('
            '); + + var updateCursor = function() { + if ($.browser.msie && $.browser.version == 6) { + fakemouse.css('filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + cursorUrl() + '\', sizingMethod=\'scale\''); + } else { + fakemouse.attr('src', cursorUrl()); + } + } + var resetCursor = function() { + if ($.browser.msie && $.browser.version == 6) { + fakemouse.css('filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + defaultUrl + '\', sizingMethod=\'scale\''); + } else { + fakemouse.attr('src', defaultUrl); + } + } + + var testStart = function() { + self.element.bind("mouseover", updateCursor).bind("mouseout", resetCursor); + fakemouse.appendTo('body').css({ position: 'absolute', left: mouseX, top: mouseY, zIndex: 5000 }); + realmouse.appendTo('body').css({ position: 'absolute', left: mouseX, top: mouseY, zIndex: 5000, opacity: 0.1 }); + mousescreen.appendTo('body').css({ width: '100%', height: '100%', position: 'absolute', top: 0, left: 0, zIndex: 5000 }) + .mousemove(function(e) { realmouse.css({ left: e.pageX, top: e.pageY }); return false; }) + .mousedown(function() { return false; }) + .mouseup(function() { return false; }); + mousescreen.css('cursor', 'url(' + noneUrl + '), crosshair'); + ($.browser.opera && mousescreen.css('cursor', 'crosshair')); + } + var testStop = function() { + self.element.unbind("mouseover", updateCursor).unbind("mouseout", resetCursor); + mousescreen.remove(); + mouseX = realmouse.css("left"); + mouseY = realmouse.css("top"); + realmouse.remove(); + fakemouse.remove(); + self.options.complete.apply(); + } + + testStart(); + + this.lastX = null; + + var before = function() { + self.element.triggerHandler('mouseover'); + self.element.simulate("mousedown", { clientX: self.left, clientY: self.top }); + self.element.simulate("mousemove", { clientX: self.left, clientY: self.top }); + } + + var during = function(xory) { + if (!self.lastX) { + self.lastX = xory; + } else { + var x = self.lastX, y = xory; + self.element.simulate("mousemove", { clientX: x, clientY: y }); + self.lastX = null; + } + } + + var after = function() { + self.element.triggerHandler('mouseout'); + self.element.simulate("mouseup", { clientX: 0, clientY: 0 }); + testStop(); + } + + fakemouse + .animate({ left: this.left, top: this.top }, this.options.speed, before) + .animate({ left: this.left + dx, top: this.top + dy }, { + speed: this.options.speed, + easing: "swing", + step: during + }) + .animate({ left: this.left + dx, top: this.top + dy }, { + speed: this.options.speed, + easing: "swing", + complete: after + }); + + } + }); + + $.ui.testMouse.defaults = { + speed: "slow" + } + +})(jQuery); -- cgit v1.2.3