<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[20602] trunk/wp-includes: Update jQuery imgAreaSelect plugin to 0.9.8.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg > ul, #logmsg > ol { margin-left: 0; margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/20602">20602</a></dd>
<dt>Author</dt> <dd>nacin</dd>
<dt>Date</dt> <dd>2012-04-25 21:49:57 +0000 (Wed, 25 Apr 2012)</dd>
</dl>
<h3>Log Message</h3>
<pre>Update jQuery imgAreaSelect plugin to 0.9.8. props ocean90. fixes <a href="http://core.trac.wordpress.org/ticket/19881">#19881</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpincludesjsimgareaselectimgareaselectcss">trunk/wp-includes/js/imgareaselect/imgareaselect.css</a></li>
<li><a href="#trunkwpincludesjsimgareaselectjqueryimgareaselectdevjs">trunk/wp-includes/js/imgareaselect/jquery.imgareaselect.dev.js</a></li>
<li><a href="#trunkwpincludesscriptloaderphp">trunk/wp-includes/script-loader.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpincludesjsimgareaselectimgareaselectcss"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/js/imgareaselect/imgareaselect.css (20601 => 20602)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/imgareaselect/imgareaselect.css        2012-04-25 21:40:20 UTC (rev 20601)
+++ trunk/wp-includes/js/imgareaselect/imgareaselect.css        2012-04-25 21:49:57 UTC (rev 20602)
</span><span class="lines">@@ -20,21 +20,21 @@
</span><span class="cx">
</span><span class="cx"> .imgareaselect-border1, .imgareaselect-border2,
</span><span class="cx"> .imgareaselect-border3, .imgareaselect-border4 {
</span><ins>+ filter: alpha(opacity=50);
</ins><span class="cx">         opacity: 0.5;
</span><del>- filter: alpha(opacity=50);
</del><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> .imgareaselect-handle {
</span><span class="cx"> background-color: #fff;
</span><span class="cx">         border: solid 1px #000;
</span><del>-        opacity: 0.4;
-        filter: alpha(opacity=40);
</del><ins>+ filter: alpha(opacity=50);
+        opacity: 0.5;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> .imgareaselect-outer {
</span><span class="cx">         background-color: #000;
</span><del>-        opacity: 0.4;
- filter: alpha(opacity=40);
</del><ins>+ filter: alpha(opacity=50);
+        opacity: 0.5;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> .imgareaselect-selection {
</span></span></pre></div>
<a id="trunkwpincludesjsimgareaselectjqueryimgareaselectdevjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/js/imgareaselect/jquery.imgareaselect.dev.js (20601 => 20602)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/imgareaselect/jquery.imgareaselect.dev.js        2012-04-25 21:40:20 UTC (rev 20601)
+++ trunk/wp-includes/js/imgareaselect/jquery.imgareaselect.dev.js        2012-04-25 21:49:57 UTC (rev 20602)
</span><span class="lines">@@ -1,6 +1,6 @@
</span><span class="cx"> /*
</span><span class="cx"> * imgAreaSelect jQuery plugin
</span><del>- * version 0.9.6
</del><ins>+ * version 0.9.8
</ins><span class="cx"> *
</span><span class="cx"> * Copyright (c) 2008-2011 Michal Wojciechowski (odyniec.net)
</span><span class="cx"> *
</span><span class="lines">@@ -13,90 +13,201 @@
</span><span class="cx">
</span><span class="cx"> (function($) {
</span><span class="cx">
</span><ins>+/*
+ * Math functions will be used extensively, so it's convenient to make a few
+ * shortcuts
+ */
</ins><span class="cx"> var abs = Math.abs,
</span><span class="cx"> max = Math.max,
</span><span class="cx"> min = Math.min,
</span><span class="cx"> round = Math.round;
</span><span class="cx">
</span><ins>+/**
+ * Create a new HTML div element
+ *
+ * @return A jQuery object representing the new element
+ */
</ins><span class="cx"> function div() {
</span><span class="cx"> return $('<div/>');
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+/**
+ * imgAreaSelect initialization
+ *
+ * @param img
+ * A HTML image element to attach the plugin to
+ * @param options
+ * An options object
+ */
</ins><span class="cx"> $.imgAreaSelect = function (img, options) {
</span><span class="cx"> var
</span><del>-
</del><ins>+ /* jQuery object representing the image */
</ins><span class="cx"> $img = $(img),
</span><span class="cx">
</span><ins>+ /* Has the image finished loading? */
</ins><span class="cx"> imgLoaded,
</span><span class="cx">
</span><ins>+ /* Plugin elements */
+
+ /* Container box */
</ins><span class="cx"> $box = div(),
</span><ins>+ /* Selection area */
</ins><span class="cx"> $area = div(),
</span><ins>+ /* Border (four divs) */
</ins><span class="cx"> $border = div().add(div()).add(div()).add(div()),
</span><ins>+ /* Outer area (four divs) */
</ins><span class="cx"> $outer = div().add(div()).add(div()).add(div()),
</span><ins>+ /* Handles (empty by default, initialized in setOptions()) */
</ins><span class="cx"> $handles = $([]),
</span><span class="cx">
</span><ins>+ /*
+ * Additional element to work around a cursor problem in Opera
+ * (explained later)
+ */
</ins><span class="cx"> $areaOpera,
</span><span class="cx">
</span><ins>+ /* Image position (relative to viewport) */
</ins><span class="cx"> left, top,
</span><span class="cx">
</span><ins>+ /* Image offset (as returned by .offset()) */
</ins><span class="cx"> imgOfs = { left: 0, top: 0 },
</span><span class="cx">
</span><ins>+ /* Image dimensions (as returned by .width() and .height()) */
</ins><span class="cx"> imgWidth, imgHeight,
</span><span class="cx">
</span><ins>+ /*
+ * jQuery object representing the parent element that the plugin
+ * elements are appended to
+ */
</ins><span class="cx"> $parent,
</span><span class="cx">
</span><ins>+ /* Parent element offset (as returned by .offset()) */
</ins><span class="cx"> parOfs = { left: 0, top: 0 },
</span><span class="cx">
</span><ins>+ /* Base z-index for plugin elements */
</ins><span class="cx"> zIndex = 0,
</span><span class="cx">
</span><ins>+ /* Plugin elements position */
</ins><span class="cx"> position = 'absolute',
</span><span class="cx">
</span><ins>+ /* X/Y coordinates of the starting point for move/resize operations */
</ins><span class="cx"> startX, startY,
</span><span class="cx">
</span><ins>+ /* Horizontal and vertical scaling factors */
</ins><span class="cx"> scaleX, scaleY,
</span><span class="cx">
</span><del>- resizeMargin = 10,
-
</del><ins>+ /* Current resize mode ("nw", "se", etc.) */
</ins><span class="cx"> resize,
</span><span class="cx">
</span><ins>+ /* Selection area constraints */
</ins><span class="cx"> minWidth, minHeight, maxWidth, maxHeight,
</span><span class="cx">
</span><ins>+ /* Aspect ratio to maintain (floating point number) */
</ins><span class="cx"> aspectRatio,
</span><span class="cx">
</span><ins>+ /* Are the plugin elements currently displayed? */
</ins><span class="cx"> shown,
</span><span class="cx">
</span><ins>+ /* Current selection (relative to parent element) */
</ins><span class="cx"> x1, y1, x2, y2,
</span><span class="cx">
</span><ins>+ /* Current selection (relative to scaled image) */
</ins><span class="cx"> selection = { x1: 0, y1: 0, x2: 0, y2: 0, width: 0, height: 0 },
</span><span class="cx">
</span><ins>+ /* Document element */
</ins><span class="cx"> docElem = document.documentElement,
</span><span class="cx">
</span><ins>+ /* Various helper variables used throughout the code */
</ins><span class="cx"> $p, d, i, o, w, h, adjusted;
</span><span class="cx">
</span><ins>+ /*
+ * Translate selection coordinates (relative to scaled image) to viewport
+ * coordinates (relative to parent element)
+ */
+
+ /**
+ * Translate selection X to viewport X
+ *
+ * @param x
+ * Selection X
+ * @return Viewport X
+ */
</ins><span class="cx"> function viewX(x) {
</span><span class="cx"> return x + imgOfs.left - parOfs.left;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Translate selection Y to viewport Y
+ *
+ * @param y
+ * Selection Y
+ * @return Viewport Y
+ */
</ins><span class="cx"> function viewY(y) {
</span><span class="cx"> return y + imgOfs.top - parOfs.top;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /*
+ * Translate viewport coordinates to selection coordinates
+ */
+
+ /**
+ * Translate viewport X to selection X
+ *
+ * @param x
+ * Viewport X
+ * @return Selection X
+ */
</ins><span class="cx"> function selX(x) {
</span><span class="cx"> return x - imgOfs.left + parOfs.left;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Translate viewport Y to selection Y
+ *
+ * @param y
+ * Viewport Y
+ * @return Selection Y
+ */
</ins><span class="cx"> function selY(y) {
</span><span class="cx"> return y - imgOfs.top + parOfs.top;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /*
+ * Translate event coordinates (relative to document) to viewport
+ * coordinates
+ */
+
+ /**
+ * Get event X and translate it to viewport X
+ *
+ * @param event
+ * The event object
+ * @return Viewport X
+ */
</ins><span class="cx"> function evX(event) {
</span><span class="cx"> return event.pageX - parOfs.left;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Get event Y and translate it to viewport Y
+ *
+ * @param event
+ * The event object
+ * @return Viewport Y
+ */
</ins><span class="cx"> function evY(event) {
</span><span class="cx"> return event.pageY - parOfs.top;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Get the current selection
+ *
+ * @param noScale
+ * If set to <code>true</code>, scaling is not applied to the
+ * returned selection
+ * @return Selection object
+ */
</ins><span class="cx"> function getSelection(noScale) {
</span><span class="cx"> var sx = noScale || scaleX, sy = noScale || scaleY;
</span><span class="cx">
</span><span class="lines">@@ -108,6 +219,21 @@
</span><span class="cx"> height: round(selection.y2 * sy) - round(selection.y1 * sy) };
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Set the current selection
+ *
+ * @param x1
+ * X coordinate of the upper left corner of the selection area
+ * @param y1
+ * Y coordinate of the upper left corner of the selection area
+ * @param x2
+ * X coordinate of the lower right corner of the selection area
+ * @param y2
+ * Y coordinate of the lower right corner of the selection area
+ * @param noScale
+ * If set to <code>true</code>, scaling is not applied to the
+ * new selection
+ */
</ins><span class="cx"> function setSelection(x1, y1, x2, y2, noScale) {
</span><span class="cx"> var sx = noScale || scaleX, sy = noScale || scaleY;
</span><span class="cx">
</span><span class="lines">@@ -122,23 +248,41 @@
</span><span class="cx"> selection.height = selection.y2 - selection.y1;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Recalculate image and parent offsets
+ */
</ins><span class="cx"> function adjust() {
</span><ins>+ /*
+ * 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.
+ */
</ins><span class="cx"> if (!$img.width())
</span><span class="cx"> return;
</span><span class="cx">
</span><ins>+ /*
+ * Get image offset. The .offset() method returns float values, so they
+ * need to be rounded.
+ */
</ins><span class="cx"> imgOfs = { left: round($img.offset().left), top: round($img.offset().top) };
</span><span class="cx">
</span><ins>+ /* Get image dimensions */
</ins><span class="cx"> imgWidth = $img.innerWidth();
</span><span class="cx"> imgHeight = $img.innerHeight();
</span><span class="cx">
</span><span class="cx"> imgOfs.top += ($img.outerHeight() - imgHeight) >> 1;
</span><span class="cx"> imgOfs.left += ($img.outerWidth() - imgWidth) >> 1;
</span><span class="cx">
</span><del>- minWidth = options.minWidth || 0;
- minHeight = options.minHeight || 0;
- maxWidth = min(options.maxWidth || 1<<24, imgWidth);
- maxHeight = min(options.maxHeight || 1<<24, imgHeight);
</del><ins>+ /* Set minimum and maximum selection area dimensions */
+ minWidth = round(options.minWidth / scaleX) || 0;
+ minHeight = round(options.minHeight / scaleY) || 0;
+ maxWidth = round(min(options.maxWidth / scaleX || 1<<24, imgWidth));
+ maxHeight = round(min(options.maxHeight / scaleY || 1<<24, imgHeight));
</ins><span class="cx">
</span><ins>+ /*
+ * Workaround for jQuery 1.3.2 incorrect offset calculation, originally
+ * observed in Safari 3. Firefox 2 is also affected.
+ */
</ins><span class="cx"> if ($().jquery == '1.3.2' && position == 'fixed' &&
</span><span class="cx"> !docElem['getBoundingClientRect'])
</span><span class="cx"> {
</span><span class="lines">@@ -146,7 +290,8 @@
</span><span class="cx"> imgOfs.left += max(document.body.scrollLeft, docElem.scrollLeft);
</span><span class="cx"> }
</span><span class="cx">
</span><del>- parOfs = $.inArray($parent.css('position'), ['absolute', 'relative']) + 1 ?
</del><ins>+ /* Determine parent element offset */
+ parOfs = /absolute|relative/.test($parent.css('position')) ?
</ins><span class="cx"> { left: round($parent.offset().left) - $parent.scrollLeft(),
</span><span class="cx"> top: round($parent.offset().top) - $parent.scrollTop() } :
</span><span class="cx"> position == 'fixed' ?
</span><span class="lines">@@ -156,22 +301,44 @@
</span><span class="cx"> left = viewX(0);
</span><span class="cx"> top = viewY(0);
</span><span class="cx">
</span><ins>+ /*
+ * Check if selection area is within image boundaries, adjust if
+ * necessary
+ */
</ins><span class="cx"> if (selection.x2 > imgWidth || selection.y2 > imgHeight)
</span><span class="cx"> doResize();
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Update plugin elements
+ *
+ * @param resetKeyPress
+ * If set to <code>false</code>, this instance's keypress
+ * event handler is not activated
+ */
</ins><span class="cx"> function update(resetKeyPress) {
</span><ins>+ /* If plugin elements are hidden, do nothing */
</ins><span class="cx"> if (!shown) return;
</span><span class="cx">
</span><ins>+ /*
+ * Set the position and size of the container box and the selection area
+ * inside it
+ */
</ins><span class="cx"> $box.css({ left: viewX(selection.x1), top: viewY(selection.y1) })
</span><span class="cx"> .add($area).width(w = selection.width).height(h = selection.height);
</span><span class="cx">
</span><ins>+ /*
+ * Reset the position of selection area, borders, and handles (IE6/IE7
+ * position them incorrectly if we don't do this)
+ */
</ins><span class="cx"> $area.add($border).add($handles).css({ left: 0, top: 0 });
</span><span class="cx">
</span><ins>+ /* Set border dimensions */
</ins><span class="cx"> $border
</span><span class="cx"> .width(max(w - $border.outerWidth() + $border.innerWidth(), 0))
</span><span class="cx"> .height(max(h - $border.outerHeight() + $border.innerHeight(), 0));
</span><span class="cx">
</span><ins>+ /* Arrange the outer area elements */
</ins><span class="cx"> $($outer[0]).css({ left: left, top: top,
</span><span class="cx"> width: selection.x1, height: imgHeight });
</span><span class="cx"> $($outer[1]).css({ left: left + selection.x1, top: top,
</span><span class="lines">@@ -184,6 +351,7 @@
</span><span class="cx"> w -= $handles.outerWidth();
</span><span class="cx"> h -= $handles.outerHeight();
</span><span class="cx">
</span><ins>+ /* Arrange handles */
</ins><span class="cx"> switch ($handles.length) {
</span><span class="cx"> case 8:
</span><span class="cx"> $($handles[4]).css({ left: w >> 1 });
</span><span class="lines">@@ -196,21 +364,49 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> if (resetKeyPress !== false) {
</span><ins>+ /*
+ * Need to reset the document keypress event handler -- unbind the
+ * current handler
+ */
</ins><span class="cx"> if ($.imgAreaSelect.keyPress != docKeyPress)
</span><span class="cx"> $(document).unbind($.imgAreaSelect.keyPress,
</span><span class="cx"> $.imgAreaSelect.onKeyPress);
</span><span class="cx">
</span><span class="cx"> if (options.keys)
</span><ins>+ /*
+ * Set the document keypress event handler to this instance's
+ * docKeyPress() function
+ */
</ins><span class="cx"> $(document)[$.imgAreaSelect.keyPress](
</span><span class="cx"> $.imgAreaSelect.onKeyPress = docKeyPress);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /*
+ * Internet Explorer displays 1px-wide dashed borders incorrectly by
+ * filling the spaces between dashes with white. Toggling the margin
+ * property between 0 and "auto" fixes this in IE6 and IE7 (IE8 is still
+ * broken). This workaround is not perfect, as it requires setTimeout()
+ * and thus causes the border to flicker a bit, but I haven't found a
+ * better solution.
+ *
+ * Note: This only happens with CSS borders, set with the borderWidth,
+ * borderOpacity, borderColor1, and borderColor2 options (which are now
+ * deprecated). Borders created with GIF background images are fine.
+ */
</ins><span class="cx"> if ($.browser.msie && $border.outerWidth() - $border.innerWidth() == 2) {
</span><span class="cx"> $border.css('margin', 0);
</span><span class="cx"> setTimeout(function () { $border.css('margin', 'auto'); }, 0);
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Do the complete update sequence: recalculate offsets, update the
+ * elements, and set the correct values of x1, y1, x2, and y2.
+ *
+ * @param resetKeyPress
+ * If set to <code>false</code>, this instance's keypress
+ * event handler is not activated
+ */
</ins><span class="cx"> function doUpdate(resetKeyPress) {
</span><span class="cx"> adjust();
</span><span class="cx"> update(resetKeyPress);
</span><span class="lines">@@ -218,11 +414,24 @@
</span><span class="cx"> x2 = viewX(selection.x2); y2 = viewY(selection.y2);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Hide or fade out an element (or multiple elements)
+ *
+ * @param $elem
+ * A jQuery object containing the element(s) to hide/fade out
+ * @param fn
+ * Callback function to be called when fadeOut() completes
+ */
</ins><span class="cx"> function hide($elem, fn) {
</span><span class="cx"> options.fadeSpeed ? $elem.fadeOut(options.fadeSpeed, fn) : $elem.hide();
</span><del>-
</del><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Selection area mousemove event handler
+ *
+ * @param event
+ * The event object
+ */
</ins><span class="cx"> function areaMouseMove(event) {
</span><span class="cx"> var x = selX(evX(event)) - selection.x1,
</span><span class="cx"> y = selY(evY(event)) - selection.y1;
</span><span class="lines">@@ -234,9 +443,14 @@
</span><span class="cx"> $box.one('mouseout', function () { adjusted = false; });
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /* Clear the resize mode */
</ins><span class="cx"> resize = '';
</span><span class="cx">
</span><span class="cx"> if (options.resizable) {
</span><ins>+ /*
+ * Check if the mouse pointer is over the resize margin area and set
+ * the resize mode accordingly
+ */
</ins><span class="cx"> if (y <= options.resizeMargin)
</span><span class="cx"> resize = 'n';
</span><span class="cx"> else if (y >= selection.height - options.resizeMargin)
</span><span class="lines">@@ -253,8 +467,19 @@
</span><span class="cx"> $areaOpera.toggle();
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Document mouseup event handler
+ *
+ * @param event
+ * The event object
+ */
</ins><span class="cx"> function docMouseUp(event) {
</span><ins>+ /* Set back the default cursor */
</ins><span class="cx"> $('body').css('cursor', '');
</span><ins>+ /*
+ * If autoHide is enabled, or if the selection has zero width/height,
+ * hide the selection and the outer area
+ */
</ins><span class="cx"> if (options.autoHide || selection.width * selection.height == 0)
</span><span class="cx"> hide($box.add($outer), function () { $(this).hide(); });
</span><span class="cx">
</span><span class="lines">@@ -264,12 +489,20 @@
</span><span class="cx"> options.onSelectEnd(img, getSelection());
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Selection area mousedown event handler
+ *
+ * @param event
+ * The event object
+ * @return false
+ */
</ins><span class="cx"> function areaMouseDown(event) {
</span><span class="cx"> if (event.which != 1) return false;
</span><span class="cx">
</span><span class="cx"> adjust();
</span><span class="cx">
</span><span class="cx"> if (resize) {
</span><ins>+ /* Resize mode is in effect */
</ins><span class="cx"> $('body').css('cursor', resize + '-resize');
</span><span class="cx">
</span><span class="cx"> x1 = viewX(selection[/w/.test(resize) ? 'x2' : 'x1']);
</span><span class="lines">@@ -299,12 +532,18 @@
</span><span class="cx"> return false;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Adjust the x2/y2 coordinates to maintain aspect ratio (if defined)
+ *
+ * @param xFirst
+ * If set to <code>true</code>, calculate x2 first. Otherwise,
+ * calculate y2 first.
+ */
</ins><span class="cx"> function fixAspectRatio(xFirst) {
</span><span class="cx"> if (aspectRatio)
</span><span class="cx"> if (xFirst) {
</span><span class="cx"> x2 = max(left, min(left + imgWidth,
</span><span class="cx"> x1 + abs(y2 - y1) * aspectRatio * (x2 > x1 || -1)));
</span><del>-
</del><span class="cx"> y2 = round(max(top, min(top + imgHeight,
</span><span class="cx"> y1 + abs(x2 - x1) / aspectRatio * (y2 > y1 || -1))));
</span><span class="cx"> x2 = round(x2);
</span><span class="lines">@@ -318,11 +557,21 @@
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Resize the selection area respecting the minimum/maximum dimensions and
+ * aspect ratio
+ */
</ins><span class="cx"> function doResize() {
</span><ins>+ /*
+ * Make sure the top left corner of the selection area stays within
+ * image boundaries (it might not if the image source was dynamically
+ * changed).
+ */
</ins><span class="cx"> x1 = min(x1, left + imgWidth);
</span><span class="cx"> y1 = min(y1, top + imgHeight);
</span><span class="cx">
</span><span class="cx"> if (abs(x2 - x1) < minWidth) {
</span><ins>+ /* Selection width is smaller than minWidth */
</ins><span class="cx"> x2 = x1 - minWidth * (x2 < x1 || -1);
</span><span class="cx">
</span><span class="cx"> if (x2 < left)
</span><span class="lines">@@ -332,6 +581,7 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> if (abs(y2 - y1) < minHeight) {
</span><ins>+ /* Selection height is smaller than minHeight */
</ins><span class="cx"> y2 = y1 - minHeight * (y2 < y1 || -1);
</span><span class="cx">
</span><span class="cx"> if (y2 < top)
</span><span class="lines">@@ -346,11 +596,13 @@
</span><span class="cx"> fixAspectRatio(abs(x2 - x1) < abs(y2 - y1) * aspectRatio);
</span><span class="cx">
</span><span class="cx"> if (abs(x2 - x1) > maxWidth) {
</span><ins>+ /* Selection width is greater than maxWidth */
</ins><span class="cx"> x2 = x1 - maxWidth * (x2 < x1 || -1);
</span><span class="cx"> fixAspectRatio();
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> if (abs(y2 - y1) > maxHeight) {
</span><ins>+ /* Selection height is greater than maxHeight */
</ins><span class="cx"> y2 = y1 - maxHeight * (y2 < y1 || -1);
</span><span class="cx"> fixAspectRatio(true);
</span><span class="cx"> }
</span><span class="lines">@@ -364,16 +616,30 @@
</span><span class="cx"> options.onSelectChange(img, getSelection());
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Mousemove event handler triggered when the user is selecting an area
+ *
+ * @param event
+ * The event object
+ * @return false
+ */
</ins><span class="cx"> function selectingMouseMove(event) {
</span><del>- x2 = resize == '' || /w|e/.test(resize) || aspectRatio ? evX(event) : viewX(selection.x2);
- y2 = resize == '' || /n|s/.test(resize) || aspectRatio ? evY(event) : viewY(selection.y2);
</del><ins>+ x2 = /w|e|^$/.test(resize) || aspectRatio ? evX(event) : viewX(selection.x2);
+ y2 = /n|s|^$/.test(resize) || aspectRatio ? evY(event) : viewY(selection.y2);
</ins><span class="cx">
</span><span class="cx"> doResize();
</span><span class="cx">
</span><span class="cx"> return false;
</span><del>-
</del><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Move the selection area
+ *
+ * @param newX1
+ * New viewport X1
+ * @param newY1
+ * New viewport Y1
+ */
</ins><span class="cx"> function doMove(newX1, newY1) {
</span><span class="cx"> x2 = (x1 = newX1) + selection.width;
</span><span class="cx"> y2 = (y1 = newY1) + selection.height;
</span><span class="lines">@@ -386,6 +652,13 @@
</span><span class="cx"> options.onSelectChange(img, getSelection());
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Mousemove event handler triggered when the selection area is being moved
+ *
+ * @param event
+ * The event object
+ * @return false
+ */
</ins><span class="cx"> function movingMouseMove(event) {
</span><span class="cx"> x1 = max(left, min(startX + evX(event), left + imgWidth - selection.width));
</span><span class="cx"> y1 = max(top, min(startY + evY(event), top + imgHeight - selection.height));
</span><span class="lines">@@ -393,22 +666,24 @@
</span><span class="cx"> doMove(x1, y1);
</span><span class="cx">
</span><span class="cx"> event.preventDefault();
</span><del>-
</del><span class="cx"> return false;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Start selection
+ */
</ins><span class="cx"> function startSelection() {
</span><span class="cx"> $(document).unbind('mousemove', startSelection);
</span><span class="cx"> adjust();
</span><span class="cx">
</span><span class="cx"> x2 = x1;
</span><span class="cx"> y2 = y1;
</span><del>-
</del><span class="cx"> doResize();
</span><span class="cx">
</span><span class="cx"> resize = '';
</span><span class="cx">
</span><del>- if ($outer.is(':not(:visible)'))
</del><ins>+ if (!$outer.is(':visible'))
+ /* Show the plugin elements */
</ins><span class="cx"> $box.add($outer).hide().fadeIn(options.fadeSpeed||0);
</span><span class="cx">
</span><span class="cx"> shown = true;
</span><span class="lines">@@ -420,6 +695,9 @@
</span><span class="cx"> options.onSelectStart(img, getSelection());
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Cancel selection
+ */
</ins><span class="cx"> function cancelSelection() {
</span><span class="cx"> $(document).unbind('mousemove', startSelection)
</span><span class="cx"> .unbind('mouseup', cancelSelection);
</span><span class="lines">@@ -427,29 +705,49 @@
</span><span class="cx">
</span><span class="cx"> setSelection(selX(x1), selY(y1), selX(x1), selY(y1));
</span><span class="cx">
</span><del>- options.onSelectChange(img, getSelection());
- options.onSelectEnd(img, getSelection());
</del><ins>+ /* If this is an API call, callback functions should not be triggered */
+ if (!this instanceof $.imgAreaSelect) {
+ options.onSelectChange(img, getSelection());
+ options.onSelectEnd(img, getSelection());
+ }
</ins><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Image mousedown event handler
+ *
+ * @param event
+ * The event object
+ * @return false
+ */
</ins><span class="cx"> function imgMouseDown(event) {
</span><ins>+ /* Ignore the event if animation is in progress */
</ins><span class="cx"> if (event.which != 1 || $outer.is(':animated')) return false;
</span><span class="cx">
</span><span class="cx"> adjust();
</span><span class="cx"> startX = x1 = evX(event);
</span><span class="cx"> startY = y1 = evY(event);
</span><span class="cx">
</span><ins>+ /* Selection will start when the mouse is moved */
</ins><span class="cx"> $(document).mousemove(startSelection).mouseup(cancelSelection);
</span><span class="cx">
</span><span class="cx"> return false;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Window resize event handler
+ */
</ins><span class="cx"> function windowResize() {
</span><span class="cx"> doUpdate(false);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Image load event handler. This is the final part of the initialization
+ * process.
+ */
</ins><span class="cx"> function imgLoad() {
</span><span class="cx"> imgLoaded = true;
</span><span class="cx">
</span><ins>+ /* Set options */
</ins><span class="cx"> setOptions(options = $.extend({
</span><span class="cx"> classPrefix: 'imgareaselect',
</span><span class="cx"> movable: true,
</span><span class="lines">@@ -471,9 +769,21 @@
</span><span class="cx"> $box.add($outer).hide().fadeIn(options.fadeSpeed||0);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /*
+ * Call the onInit callback. The setTimeout() call is used to ensure
+ * that the plugin has been fully initialized and the object instance is
+ * available (so that it can be obtained in the callback).
+ */
</ins><span class="cx"> setTimeout(function () { options.onInit(img, getSelection()); }, 0);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Document keypress event handler
+ *
+ * @param event
+ * The event object
+ * @return false
+ */
</ins><span class="cx"> var docKeyPress = function(event) {
</span><span class="cx"> var k = options.keys, d, t, key = event.keyCode;
</span><span class="cx">
</span><span class="lines">@@ -486,18 +796,24 @@
</span><span class="cx"> (k.ctrl == 'resize' && event.ctrlKey) ||
</span><span class="cx"> (k.alt == 'resize' && (event.altKey || event.originalEvent.altKey)))
</span><span class="cx"> {
</span><ins>+ /* Resize selection */
+
</ins><span class="cx"> switch (key) {
</span><span class="cx"> case 37:
</span><ins>+ /* Left */
</ins><span class="cx"> d = -d;
</span><span class="cx"> case 39:
</span><ins>+ /* Right */
</ins><span class="cx"> t = max(x1, x2);
</span><span class="cx"> x1 = min(x1, x2);
</span><span class="cx"> x2 = max(t + d, x1);
</span><span class="cx"> fixAspectRatio();
</span><span class="cx"> break;
</span><span class="cx"> case 38:
</span><ins>+ /* Up */
</ins><span class="cx"> d = -d;
</span><span class="cx"> case 40:
</span><ins>+ /* Down */
</ins><span class="cx"> t = max(y1, y2);
</span><span class="cx"> y1 = min(y1, y2);
</span><span class="cx"> y2 = max(t + d, y1);
</span><span class="lines">@@ -510,20 +826,26 @@
</span><span class="cx"> doResize();
</span><span class="cx"> }
</span><span class="cx"> else {
</span><ins>+ /* Move selection */
+
</ins><span class="cx"> x1 = min(x1, x2);
</span><span class="cx"> y1 = min(y1, y2);
</span><span class="cx">
</span><span class="cx"> switch (key) {
</span><span class="cx"> case 37:
</span><ins>+ /* Left */
</ins><span class="cx"> doMove(max(x1 - d, left), y1);
</span><span class="cx"> break;
</span><span class="cx"> case 38:
</span><ins>+ /* Up */
</ins><span class="cx"> doMove(x1, max(y1 - d, top));
</span><span class="cx"> break;
</span><span class="cx"> case 39:
</span><ins>+ /* Right */
</ins><span class="cx"> doMove(x1 + min(d, imgWidth - selX(x2)), y1);
</span><span class="cx"> break;
</span><span class="cx"> case 40:
</span><ins>+ /* Down */
</ins><span class="cx"> doMove(x1, y1 + min(d, imgHeight - selY(y2)));
</span><span class="cx"> break;
</span><span class="cx"> default:
</span><span class="lines">@@ -534,21 +856,38 @@
</span><span class="cx"> return false;
</span><span class="cx"> };
</span><span class="cx">
</span><ins>+ /**
+ * Apply style options to plugin element (or multiple elements)
+ *
+ * @param $elem
+ * A jQuery object representing the element(s) to style
+ * @param props
+ * An object that maps option names to corresponding CSS
+ * properties
+ */
</ins><span class="cx"> function styleOptions($elem, props) {
</span><span class="cx"> for (option in props)
</span><span class="cx"> if (options[option] !== undefined)
</span><span class="cx"> $elem.css(props[option], options[option]);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Set plugin options
+ *
+ * @param newOptions
+ * The new options object
+ */
</ins><span class="cx"> function setOptions(newOptions) {
</span><span class="cx"> if (newOptions.parent)
</span><span class="cx"> ($parent = $(newOptions.parent)).append($box.add($outer));
</span><span class="cx">
</span><ins>+ /* Merge the new options with the existing ones */
</ins><span class="cx"> $.extend(options, newOptions);
</span><span class="cx">
</span><span class="cx"> adjust();
</span><span class="cx">
</span><span class="cx"> if (newOptions.handles != null) {
</span><ins>+ /* Recreate selection area handles */
</ins><span class="cx"> $handles.remove();
</span><span class="cx"> $handles = $([]);
</span><span class="cx">
</span><span class="lines">@@ -557,26 +896,42 @@
</span><span class="cx"> while (i--)
</span><span class="cx"> $handles = $handles.add(div());
</span><span class="cx">
</span><ins>+ /* Add a class to handles and set the CSS properties */
</ins><span class="cx"> $handles.addClass(options.classPrefix + '-handle').css({
</span><span class="cx"> position: 'absolute',
</span><ins>+ /*
+ * The font-size property needs to be set to zero, otherwise
+ * Internet Explorer makes the handles too large
+ */
</ins><span class="cx"> fontSize: 0,
</span><span class="cx"> zIndex: zIndex + 1 || 1
</span><span class="cx"> });
</span><span class="cx">
</span><ins>+ /*
+ * If handle width/height has not been set with CSS rules, set the
+ * default 5px
+ */
</ins><span class="cx"> if (!parseInt($handles.css('width')) >= 0)
</span><span class="cx"> $handles.width(5).height(5);
</span><span class="cx">
</span><ins>+ /*
+ * If the borderWidth option is in use, add a solid border to
+ * handles
+ */
</ins><span class="cx"> if (o = options.borderWidth)
</span><span class="cx"> $handles.css({ borderWidth: o, borderStyle: 'solid' });
</span><span class="cx">
</span><ins>+ /* Apply other style options */
</ins><span class="cx"> styleOptions($handles, { borderColor1: 'border-color',
</span><span class="cx"> borderColor2: 'background-color',
</span><span class="cx"> borderOpacity: 'opacity' });
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /* Calculate scale factors */
</ins><span class="cx"> scaleX = options.imageWidth / imgWidth || 1;
</span><span class="cx"> scaleY = options.imageHeight / imgHeight || 1;
</span><span class="cx">
</span><ins>+ /* Set selection */
</ins><span class="cx"> if (newOptions.x1 != null) {
</span><span class="cx"> setSelection(newOptions.x1, newOptions.y1, newOptions.x2,
</span><span class="cx"> newOptions.y2);
</span><span class="lines">@@ -584,14 +939,17 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> if (newOptions.keys)
</span><ins>+ /* Enable keyboard support */
</ins><span class="cx"> options.keys = $.extend({ shift: 1, ctrl: 'resize' },
</span><span class="cx"> newOptions.keys);
</span><span class="cx">
</span><ins>+ /* Add classes to plugin elements */
</ins><span class="cx"> $outer.addClass(options.classPrefix + '-outer');
</span><span class="cx"> $area.addClass(options.classPrefix + '-selection');
</span><span class="cx"> for (i = 0; i++ < 4;)
</span><span class="cx"> $($border[i-1]).addClass(options.classPrefix + '-border' + i);
</span><span class="cx">
</span><ins>+ /* Apply style options */
</ins><span class="cx"> styleOptions($area, { selectionColor: 'background-color',
</span><span class="cx"> selectionOpacity: 'opacity' });
</span><span class="cx"> styleOptions($border, { borderOpacity: 'opacity',
</span><span class="lines">@@ -603,12 +961,13 @@
</span><span class="cx"> if (o = options.borderColor2)
</span><span class="cx"> $($border[1]).css({ borderStyle: 'dashed', borderColor: o });
</span><span class="cx">
</span><ins>+ /* Append all the selection area elements to the container box */
</ins><span class="cx"> $box.append($area.add($border).add($areaOpera).add($handles));
</span><span class="cx">
</span><span class="cx"> if ($.browser.msie) {
</span><del>- if (o = $outer.css('filter').match(/opacity=([0-9]+)/))
</del><ins>+ if (o = $outer.css('filter').match(/opacity=(\d+)/))
</ins><span class="cx"> $outer.css('opacity', o[1]/100);
</span><del>- if (o = $border.css('filter').match(/opacity=([0-9]+)/))
</del><ins>+ if (o = $border.css('filter').match(/opacity=(\d+)/))
</ins><span class="cx"> $border.css('opacity', o[1]/100);
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -620,16 +979,19 @@
</span><span class="cx"> doUpdate();
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /* Calculate the aspect ratio factor */
</ins><span class="cx"> aspectRatio = (d = (options.aspectRatio || '').split(/:/))[0] / d[1];
</span><span class="cx">
</span><span class="cx"> $img.add($outer).unbind('mousedown', imgMouseDown);
</span><span class="cx">
</span><span class="cx"> if (options.disable || options.enable === false) {
</span><ins>+ /* Disable the plugin */
</ins><span class="cx"> $box.unbind('mousemove', areaMouseMove).unbind('mousedown', areaMouseDown);
</span><span class="cx"> $(window).unbind('resize', windowResize);
</span><span class="cx"> }
</span><span class="cx"> else {
</span><span class="cx"> if (options.enable || options.disable === false) {
</span><ins>+ /* Enable the plugin */
</ins><span class="cx"> if (options.resizable || options.movable)
</span><span class="cx"> $box.mousemove(areaMouseMove).mousedown(areaMouseDown);
</span><span class="cx">
</span><span class="lines">@@ -643,69 +1005,179 @@
</span><span class="cx"> options.enable = options.disable = undefined;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Remove plugin completely
+ */
</ins><span class="cx"> this.remove = function () {
</span><ins>+ /*
+ * Call setOptions with { disable: true } to unbind the event handlers
+ */
</ins><span class="cx"> setOptions({ disable: true });
</span><span class="cx"> $box.add($outer).remove();
</span><span class="cx"> };
</span><span class="cx">
</span><ins>+ /*
+ * Public API
+ */
+
+ /**
+ * Get current options
+ *
+ * @return An object containing the set of options currently in use
+ */
</ins><span class="cx"> this.getOptions = function () { return options; };
</span><span class="cx">
</span><ins>+ /**
+ * Set plugin options
+ *
+ * @param newOptions
+ * The new options object
+ */
</ins><span class="cx"> this.setOptions = setOptions;
</span><span class="cx">
</span><ins>+ /**
+ * Get the current selection
+ *
+ * @param noScale
+ * If set to <code>true</code>, scaling is not applied to the
+ * returned selection
+ * @return Selection object
+ */
</ins><span class="cx"> this.getSelection = getSelection;
</span><span class="cx">
</span><ins>+ /**
+ * Set the current selection
+ *
+ * @param x1
+ * X coordinate of the upper left corner of the selection area
+ * @param y1
+ * Y coordinate of the upper left corner of the selection area
+ * @param x2
+ * X coordinate of the lower right corner of the selection area
+ * @param y2
+ * Y coordinate of the lower right corner of the selection area
+ * @param noScale
+ * If set to <code>true</code>, scaling is not applied to the
+ * new selection
+ */
</ins><span class="cx"> this.setSelection = setSelection;
</span><span class="cx">
</span><ins>+ /**
+ * Cancel selection
+ */
+ this.cancelSelection = cancelSelection;
+
+ /**
+ * Update plugin elements
+ *
+ * @param resetKeyPress
+ * If set to <code>false</code>, this instance's keypress
+ * event handler is not activated
+ */
</ins><span class="cx"> this.update = doUpdate;
</span><span class="cx">
</span><ins>+ /*
+ * Traverse the image's parent elements (up to <body>) and find the
+ * highest z-index
+ */
</ins><span class="cx"> $p = $img;
</span><span class="cx">
</span><span class="cx"> while ($p.length) {
</span><span class="cx"> zIndex = max(zIndex,
</span><span class="cx"> !isNaN($p.css('z-index')) ? $p.css('z-index') : zIndex);
</span><ins>+ /* Also check if any of the ancestor elements has fixed position */
</ins><span class="cx"> if ($p.css('position') == 'fixed')
</span><span class="cx"> position = 'fixed';
</span><span class="cx">
</span><span class="cx"> $p = $p.parent(':not(body)');
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /*
+ * If z-index is given as an option, it overrides the one found by the
+ * above loop
+ */
</ins><span class="cx"> zIndex = options.zIndex || zIndex;
</span><span class="cx">
</span><span class="cx"> if ($.browser.msie)
</span><span class="cx"> $img.attr('unselectable', 'on');
</span><span class="cx">
</span><ins>+ /*
+ * In MSIE and WebKit, we need to use the keydown event instead of keypress
+ */
</ins><span class="cx"> $.imgAreaSelect.keyPress = $.browser.msie ||
</span><span class="cx"> $.browser.safari ? 'keydown' : 'keypress';
</span><span class="cx">
</span><ins>+ /*
+ * There is a bug affecting the CSS cursor property in Opera (observed in
+ * versions up to 10.00) that prevents the cursor from being updated unless
+ * the mouse leaves and enters the element again. To trigger the mouseover
+ * event, we're adding an additional div to $box and we're going to toggle
+ * it when mouse moves inside the selection area.
+ */
</ins><span class="cx"> if ($.browser.opera)
</span><span class="cx"> $areaOpera = div().css({ width: '100%', height: '100%',
</span><span class="cx"> position: 'absolute', zIndex: zIndex + 2 || 2 });
</span><span class="cx">
</span><ins>+ /*
+ * We initially set visibility to "hidden" as a workaround for a weird
+ * behaviour observed in Google Chrome 1.0.154.53 (on Windows XP). Normally
+ * we would just set display to "none", but, for some reason, if we do so
+ * then Chrome refuses to later display the element with .show() or
+ * .fadeIn().
+ */
</ins><span class="cx"> $box.add($outer).css({ visibility: 'hidden', position: position,
</span><span class="cx"> overflow: 'hidden', zIndex: zIndex || '0' });
</span><span class="cx"> $box.css({ zIndex: zIndex + 2 || 2 });
</span><span class="cx"> $area.add($border).css({ position: 'absolute', fontSize: 0 });
</span><span class="cx">
</span><ins>+ /*
+ * If the image has been fully loaded, or if it is not really an image (eg.
+ * a div), call imgLoad() immediately; otherwise, bind it to be called once
+ * on image load event.
+ */
</ins><span class="cx"> img.complete || img.readyState == 'complete' || !$img.is('img') ?
</span><span class="cx"> imgLoad() : $img.one('load', imgLoad);
</span><span class="cx">
</span><del>- if ($.browser.msie && $.browser.version >= 9)
</del><ins>+ /*
+ * MSIE 9.0 doesn't always fire the image load event -- resetting the src
+ * attribute seems to trigger it. The check is for version 7 and above to
+ * accommodate for MSIE 9 running in compatibility mode.
+ */
+ if ($.browser.msie && $.browser.version >= 7)
</ins><span class="cx"> img.src = img.src;
</span><span class="cx"> };
</span><span class="cx">
</span><ins>+/**
+ * Invoke imgAreaSelect on a jQuery object containing the image(s)
+ *
+ * @param options
+ * Options object
+ * @return The jQuery object or a reference to imgAreaSelect instance (if the
+ * <code>instance</code> option was specified)
+ */
</ins><span class="cx"> $.fn.imgAreaSelect = function (options) {
</span><span class="cx"> options = options || {};
</span><span class="cx">
</span><span class="cx"> this.each(function () {
</span><ins>+ /* Is there already an imgAreaSelect instance bound to this element? */
</ins><span class="cx"> if ($(this).data('imgAreaSelect')) {
</span><ins>+ /* Yes there is -- is it supposed to be removed? */
</ins><span class="cx"> if (options.remove) {
</span><ins>+ /* Remove the plugin */
</ins><span class="cx"> $(this).data('imgAreaSelect').remove();
</span><span class="cx"> $(this).removeData('imgAreaSelect');
</span><span class="cx"> }
</span><span class="cx"> else
</span><ins>+ /* Reset options */
</ins><span class="cx"> $(this).data('imgAreaSelect').setOptions(options);
</span><span class="cx"> }
</span><span class="cx"> else if (!options.remove) {
</span><ins>+ /* No exising instance -- create a new one */
+
+ /*
+ * If neither the "enable" nor the "disable" option is present, add
+ * "enable" as the default
+ */
</ins><span class="cx"> if (options.enable === undefined && options.disable === undefined)
</span><span class="cx"> options.enable = true;
</span><span class="cx">
</span><span class="lines">@@ -714,6 +1186,10 @@
</span><span class="cx"> });
</span><span class="cx">
</span><span class="cx"> if (options.instance)
</span><ins>+ /*
+ * Return the imgAreaSelect instance bound to the first element in the
+ * set
+ */
</ins><span class="cx"> return $(this).data('imgAreaSelect');
</span><span class="cx">
</span><span class="cx"> return this;
</span></span></pre></div>
<a id="trunkwpincludesscriptloaderphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/script-loader.php (20601 => 20602)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/script-loader.php        2012-04-25 21:40:20 UTC (rev 20601)
+++ trunk/wp-includes/script-loader.php        2012-04-25 21:49:57 UTC (rev 20602)
</span><span class="lines">@@ -252,7 +252,7 @@
</span><span class="cx">
</span><span class="cx">         $scripts->add( 'json2', "/wp-includes/js/json2$suffix.js", array(), '2011-02-23');
</span><span class="cx">
</span><del>-        $scripts->add( 'imgareaselect', "/wp-includes/js/imgareaselect/jquery.imgareaselect$suffix.js", array('jquery'), '0.9.6-20110515', 1 );
</del><ins>+        $scripts->add( 'imgareaselect', "/wp-includes/js/imgareaselect/jquery.imgareaselect$suffix.js", array('jquery'), '0.9.8', 1 );
</ins><span class="cx">
</span><span class="cx">         $scripts->add( 'password-strength-meter', "/wp-admin/js/password-strength-meter$suffix.js", array('jquery'), false, 1 );
</span><span class="cx">         $scripts->localize( 'password-strength-meter', 'pwsL10n', array(
</span><span class="lines">@@ -474,7 +474,7 @@
</span><span class="cx">         $styles->add( 'thickbox', '/wp-includes/js/thickbox/thickbox.css' );
</span><span class="cx">         $styles->add( 'farbtastic', '/wp-admin/css/farbtastic.css', array(), '1.3u1' );
</span><span class="cx">         $styles->add( 'jcrop', '/wp-includes/js/jcrop/jquery.Jcrop.css', array(), '0.9.8' );
</span><del>-        $styles->add( 'imgareaselect', '/wp-includes/js/imgareaselect/imgareaselect.css', array(), '0.9.1' );
</del><ins>+        $styles->add( 'imgareaselect', '/wp-includes/js/imgareaselect/imgareaselect.css', array(), '0.9.8' );
</ins><span class="cx">         $styles->add( 'admin-bar', "/wp-includes/css/admin-bar$suffix.css" );
</span><span class="cx">         $styles->add( 'wp-jquery-ui-dialog', "/wp-includes/css/jquery-ui-dialog$suffix.css" );
</span><span class="cx">         $styles->add( 'editor-buttons', "/wp-includes/css/editor$suffix.css" );
</span></span></pre>
</div>
</div>
</body>
</html>