Permalink
Browse files

Fix jQuery 1.6 support

  • Loading branch information...
1 parent 115ea85 commit a034893e32a692c2251ecc6285806492979e25e4 @odyniec committed May 6, 2011
Showing with 105 additions and 7 deletions.
  1. +3 −3 distfiles/scripts/jquery.min.js
  2. +5 −4 jquery.imgareaselect.dev.js
  3. +16 −0 test/jquery-1.6.min.js
  4. +29 −0 test/test-jquery-1.6.html
  5. +52 −0 test/unit/basic.js

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -1,6 +1,6 @@
/*
* imgAreaSelect jQuery plugin
- * version 0.9.5
+ * version 0.9.6
*
* Copyright (c) 2008-2011 Michal Wojciechowski (odyniec.net)
*
@@ -679,6 +679,7 @@ $.imgAreaSelect = function (img, options) {
* Start selection
*/
function startSelection() {
+ $(document).unbind('mousemove', startSelection);
adjust();
x2 = x1;
@@ -704,7 +705,8 @@ $.imgAreaSelect = function (img, options) {
* Cancel selection
*/
function cancelSelection() {
- $(document).unbind('mousemove', startSelection);
+ $(document).unbind('mousemove', startSelection)
+ .unbind('mouseup', cancelSelection);
hide($box.add($outer));
setSelection(selX(x1), selY(y1), selX(x1), selY(y1));
@@ -729,8 +731,7 @@ $.imgAreaSelect = function (img, options) {
startY = y1 = evY(event);
/* Selection will start when the mouse is moved */
- $(document).one('mousemove', startSelection)
- .one('mouseup', cancelSelection);
+ $(document).mousemove(startSelection).mouseup(cancelSelection);
return false;
}
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -0,0 +1,29 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+ <title>imgAreaSelect Tests</title>
+ <link rel="stylesheet" href="qunit/qunit.css" type="text/css" />
+ <link rel="stylesheet" href="../distfiles/css/imgareaselect-default.css" type="text/css" />
+
+ <script type="text/javascript" src="jquery-1.6.min.js"></script>
+ <script type="text/javascript" src="../jquery.imgareaselect.dev.js"></script>
+ <script type="text/javascript" src="qunit/qunit.js"></script>
+
+ <script type="text/javascript" src="common.js"></script>
+
+ <script type="text/javascript" src="unit/basic.js"></script>
+ <script type="text/javascript" src="unit/options.js"></script>
+ <script type="text/javascript" src="unit/api.js"></script>
+ </head>
+
+ <body>
+ <h1 id="qunit-header">imgAreaSelect Test Suite</h1>
+ <h2 id="qunit-banner"></h2>
+ <h2 id="qunit-userAgent"></h2>
+ <ol id="qunit-tests"></ol>
+
+ <div id="t">
+ </div>
+ </body>
+</html>
View
@@ -28,6 +28,58 @@ test("Plugin initialization", function () {
});
});
+test("Mouse events", function () {
+ /* Initialization */
+ $('#t').append('<img id="test-img" src="data/elephant.jpg" />');
+
+ stop();
+
+ $('#test-img').imgAreaSelect({
+ onInit: function (img, selection) {
+ var imgOfs = $('#test-img').offset();
+ var event = $.Event('mousedown');
+ event.which = 1;
+ event.target = $('#test-img');
+ event.pageX = imgOfs.left + 10;
+ event.pageY = imgOfs.top + 10;
+
+ $('#test-img').trigger(event);
+
+ event = $.Event('mousemove');
+ event.which = 1;
+ event.target = $(document);
+ event.pageX = imgOfs.left + 50;
+ event.pageY = imgOfs.top + 25;
+
+ $(document).trigger(event);
+ $(document).trigger(event);
+
+ event = $.Event('mouseup');
+ event.which = 1;
+ event.target = $(document);
+ event.pageX = imgOfs.left + 50;
+ event.pageY = imgOfs.top + 25;
+
+ $(document).trigger(event);
+
+ ok($('.imgareaselect-selection').is(':visible'), 'Check if the ' +
+ 'selection area is visible');
+
+ deepEqual([ $('.imgareaselect-selection').width(),
+ $('.imgareaselect-selection').height() ],
+ [ 40, 15 ],
+ 'Check if the selection area has the correct ' +
+ 'dimensions');
+
+ /* Cleanup */
+ $('#test-img').imgAreaSelect({ remove: true });
+ testCleanup();
+
+ start();
+ }
+ });
+});
+
/* Test disabled for now */
1||test("", function () {
$('#t').append('<img id="test-img" src="data/elephant.jpg?'

0 comments on commit a034893

Please sign in to comment.