/*
* imgAreaSelect jQuery plugin
- * version 0.9.9
+ * version 0.9.10
*
- * Copyright (c) 2008-2011 Michal Wojciechowski (odyniec.net)
+ * Copyright (c) 2008-2013 Michal Wojciechowski (odyniec.net)
*
* Dual licensed under the MIT (MIT-LICENSE.txt)
* and GPL (GPL-LICENSE.txt) licenses.
/* Document element */
docElem = document.documentElement,
+ /* User agent */
+ ua = navigator.userAgent,
+
/* Various helper variables used throughout the code */
$p, d, i, o, w, h, adjusted;
*/
function adjust() {
/*
- * Do not adjust if image width is not a positive number. This might
- * happen when imgAreaSelect is put on a parent element which is then
- * hidden.
+ * Do not adjust if image has not yet loaded or if width is not a
+ * positive number. The latter might happen when imgAreaSelect is put
+ * on a parent element which is then hidden.
*/
- if (!$img.width())
+ if (!imgLoaded || !$img.width())
return;
/*
* Need to reset the document keypress event handler -- unbind the
* current handler
*/
- if ($.imgAreaSelect.keyPress != docKeyPress)
+ if ($.imgAreaSelect.onKeyPress != docKeyPress)
$(document).unbind($.imgAreaSelect.keyPress,
$.imgAreaSelect.onKeyPress);
* borderOpacity, borderColor1, and borderColor2 options (which are now
* deprecated). Borders created with GIF background images are fine.
*/
- if ($.browser.msie && $border.outerWidth() - $border.innerWidth() == 2) {
+ if (msie && $border.outerWidth() - $border.innerWidth() == 2) {
$border.css('margin', 0);
setTimeout(function () { $border.css('margin', 'auto'); }, 0);
}
$($border[1]).css({ borderStyle: 'dashed', borderColor: o });
/* Append all the selection area elements to the container box */
- $box.append($area.add($border).add($areaOpera).add($handles));
+ $box.append($area.add($border).add($areaOpera)).append($handles);
- if ($.browser.msie) {
- if (o = $outer.css('filter').match(/opacity=(\d+)/))
+ if (msie) {
+ if (o = ($outer.css('filter')||'').match(/opacity=(\d+)/))
$outer.css('opacity', o[1]/100);
- if (o = $border.css('filter').match(/opacity=(\d+)/))
+ if (o = ($border.css('filter')||'').match(/opacity=(\d+)/))
$border.css('opacity', o[1]/100);
}
*/
this.update = doUpdate;
+ /* Do the dreaded browser detection */
+ var msie = (/msie ([\w.]+)/i.exec(ua)||[])[1],
+ opera = /opera/i.test(ua),
+ safari = /webkit/i.test(ua) && !/chrome/i.test(ua);
+
/*
* Traverse the image's parent elements (up to <body>) and find the
* highest z-index
*/
zIndex = options.zIndex || zIndex;
- if ($.browser.msie)
+ if (msie)
$img.attr('unselectable', 'on');
/*
* In MSIE and WebKit, we need to use the keydown event instead of keypress
*/
- $.imgAreaSelect.keyPress = $.browser.msie ||
- $.browser.safari ? 'keydown' : 'keypress';
+ $.imgAreaSelect.keyPress = msie || safari ? 'keydown' : 'keypress';
/*
* There is a bug affecting the CSS cursor property in Opera (observed in
* event, we're adding an additional div to $box and we're going to toggle
* it when mouse moves inside the selection area.
*/
- if ($.browser.opera)
+ if (opera)
$areaOpera = div().css({ width: '100%', height: '100%',
position: 'absolute', zIndex: zIndex + 2 || 2 });
* attribute seems to trigger it. The check is for version 7 and above to
* accommodate for MSIE 9 running in compatibility mode.
*/
- if (!imgLoaded && $.browser.msie && $.browser.version >= 7)
+ if (!imgLoaded && msie && msie >= 7)
img.src = img.src;
};