Index: trunk/wp-includes/js/imgareaselect/jquery.imgareaselect.js
===================================================================
--- trunk/wp-includes/js/imgareaselect/jquery.imgareaselect.js	(revision 40213)
+++ trunk/wp-includes/js/imgareaselect/jquery.imgareaselect.js	(working copy)
@@ -1,11 +1,11 @@
 /*
  * imgAreaSelect jQuery plugin
- * version 0.9.10-monkey
+ * version 1.0.0-rc.1
  *
  * Copyright (c) 2008-2013 Michal Wojciechowski (odyniec.net)
  *
- * Dual licensed under the MIT (MIT-LICENSE.txt)
- * and GPL (GPL-LICENSE.txt) licenses.
+ * Dual licensed under the MIT (http://opensource.org/licenses/MIT)
+ * and GPL (http://opensource.org/licenses/GPL-2.0) licenses.
  *
  * http://odyniec.net/projects/imgareaselect/
  *
@@ -16,7 +16,7 @@
 /*
  * Math functions will be used extensively, so it's convenient to make a few
  * shortcuts
- */
+ */    
 var abs = Math.abs,
     max = Math.max,
     min = Math.min,
@@ -24,7 +24,7 @@
 
 /**
  * Create a new HTML div element
- *
+ * 
  * @return A jQuery object representing the new element
  */
 function div() {
@@ -33,7 +33,7 @@
 
 /**
  * imgAreaSelect initialization
- *
+ * 
  * @param img
  *            A HTML image element to attach the plugin to
  * @param options
@@ -40,15 +40,15 @@
  *            An options object
  */
 $.imgAreaSelect = function (img, options) {
-    var
-        /* jQuery object representing the image */
+    var 
+        /* jQuery object representing the image */ 
         $img = $(img),
-
+        
         /* Has the image finished loading? */
         imgLoaded,
-
+        
         /* Plugin elements */
-
+        
         /* Container box */
         $box = div(),
         /* Selection area */
@@ -55,44 +55,44 @@
         $area = div(),
         /* Border (four divs) */
         $border = div().add(div()).add(div()).add(div()),
-        /* Outer area (four divs) */
-        $outer = div().add(div()).add(div()).add(div()),
+        /* Outer area */
+        $outer = div(),
         /* Handles (empty by default, initialized in setOptions()) */
         $handles = $([]),
-
-        /*
-         * Additional element to work around a cursor problem in Opera
-         * (explained later)
-         */
-        $areaOpera,
-
+        
         /* Image position (relative to viewport) */
         left, top,
-
+        
         /* Image offset (as returned by .offset()) */
         imgOfs = { left: 0, top: 0 },
-
+        
         /* Image dimensions (as returned by .width() and .height()) */
         imgWidth, imgHeight,
-
+        
         /*
          * jQuery object representing the parent element that the plugin
          * elements are appended to
          */
         $parent,
-
+        
         /* Parent element offset (as returned by .offset()) */
         parOfs = { left: 0, top: 0 },
-
+        
         /* Base z-index for plugin elements */
         zIndex = 0,
-
+                
         /* Plugin elements position */
         position = 'absolute',
-
-        /* X/Y coordinates of the starting point for move/resize operations */
+        
+        /* X/Y coordinates of the starting point for move/resize operations */ 
         startX, startY,
 
+        /*
+         * Distance between the mouse cursor (or touch point) and selection area
+         * edges (when resizing)
+         */
+        edgeX, edgeY,
+        
         /* Horizontal and vertical scaling factors */
         scaleX, scaleY,
 
@@ -114,13 +114,13 @@
         /* Current selection (relative to scaled image) */
         selection = { x1: 0, y1: 0, x2: 0, y2: 0, width: 0, height: 0 },
 
-        /* Document element */
-        docElem = document.documentElement,
-
         /* User agent */
         ua = navigator.userAgent,
+        
+        /* Is the user performing a touch action? */
+        touch,
 
-        /* Various helper variables used throughout the code */
+        /* Various helper variables used throughout the code */ 
         $p, d, i, o, w, h, adjusted;
 
     /*
@@ -127,10 +127,10 @@
      * 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
@@ -141,7 +141,7 @@
 
     /**
      * Translate selection Y to viewport Y
-     *
+     * 
      * @param y
      *            Selection Y
      * @return Viewport Y
@@ -153,10 +153,10 @@
     /*
      * Translate viewport coordinates to selection coordinates
      */
-
+    
     /**
      * Translate viewport X to selection X
-     *
+     * 
      * @param x
      *            Viewport X
      * @return Selection X
@@ -167,7 +167,7 @@
 
     /**
      * Translate viewport Y to selection Y
-     *
+     * 
      * @param y
      *            Viewport Y
      * @return Selection Y
@@ -175,53 +175,57 @@
     function selY(y) {
         return y - imgOfs.top + parOfs.top;
     }
-
+    
     /*
      * 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
      */
     function evX(event) {
-        return max(event.pageX || 0, touchCoords(event).x) - parOfs.left;
+        var coords = touchCoords(event) || event, x;
+
+        if (x = parseInt(coords.pageX))
+            return x - parOfs.left;
     }
 
     /**
      * Get event Y and translate it to viewport Y
-     *
+     * 
      * @param event
      *            The event object
      * @return Viewport Y
      */
     function evY(event) {
-        return max(event.pageY || 0, touchCoords(event).y) - parOfs.top;
+        var coords = touchCoords(event) || event, y;
+
+        if (y = parseInt(coords.pageY))
+            return y - parOfs.top;
     }
-
+    
     /**
-     * Get X and Y coordinates of a touch event
+     * Get the first touch object in an event
      *
      * @param event
      *            The event object
-     * @return Coordinates object
+     * @return The first touch object found in the event object, or false if
+     *         none are found
      */
     function touchCoords(event) {
         var oev = event.originalEvent || {};
-
-        if (oev.touches && oev.touches.length)
-            return { x: oev.touches[0].pageX, y: oev.touches[0].pageY };
-        else
-            return { x: 0, y: 0 };
+        
+        return oev.touches && oev.touches.length ? oev.touches[0] : false;
     }
 
     /**
      * Get the current selection
-     *
+     * 
      * @param noScale
      *            If set to <code>true</code>, scaling is not applied to the
      *            returned selection
@@ -229,18 +233,18 @@
      */
     function getSelection(noScale) {
         var sx = noScale || scaleX, sy = noScale || scaleY;
-
+        
         return { x1: round(selection.x1 * sx),
             y1: round(selection.y1 * sy),
-            x2: round(selection.x2 * sx),
-            y2: round(selection.y2 * sy),
+            x2: round(selection.x2 * sx) - 1,
+            y2: round(selection.y2 * sy) - 1,
             width: round(selection.x2 * sx) - round(selection.x1 * sx),
             height: round(selection.y2 * sy) - round(selection.y1 * sy) };
     }
-
+    
     /**
      * Set the current selection
-     *
+     * 
      * @param x1
      *            X coordinate of the upper left corner of the selection area
      * @param y1
@@ -255,14 +259,14 @@
      */
     function setSelection(x1, y1, x2, y2, noScale) {
         var sx = noScale || scaleX, sy = noScale || scaleY;
-
+        
         selection = {
             x1: round(x1 / sx || 0),
             y1: round(y1 / sy || 0),
-            x2: round(x2 / sx || 0),
-            y2: round(y2 / sy || 0)
+            x2: round(++x2 / sx || 0),
+            y2: round(++y2 / sy || 0)
         };
-
+        
         selection.width = selection.x2 - selection.x1;
         selection.height = selection.y2 - selection.y1;
     }
@@ -278,17 +282,17 @@
          */
         if (!imgLoaded || !$img.width())
             return;
-
+        
         /*
          * Get image offset. The .offset() method returns float values, so they
          * need to be rounded.
          */
         imgOfs = { left: round($img.offset().left), top: round($img.offset().top) };
-
+        
         /* Get image dimensions */
         imgWidth = $img.innerWidth();
         imgHeight = $img.innerHeight();
-
+        
         imgOfs.top += ($img.outerHeight() - imgHeight) >> 1;
         imgOfs.left += ($img.outerWidth() - imgWidth) >> 1;
 
@@ -297,40 +301,33 @@
         minHeight = round(options.minHeight / scaleY) || 0;
         maxWidth = round(min(options.maxWidth / scaleX || 1<<24, imgWidth));
         maxHeight = round(min(options.maxHeight / scaleY || 1<<24, imgHeight));
+        
+        /* Determine parent element offset */ 
+        parOfs = position == 'fixed' ?
+            /* Plugin elements position set to fixed */
+            { left: $(document).scrollLeft(), top: $(document).scrollTop() } :
+            /* Check parent element position */
+            /static|^$/.test($parent.css('position')) ?
+                /* Static */
+                { left: 0, top: 0 } :
+                /* Absolute or relative */
+                { left: round($parent.offset().left) - $parent.scrollLeft(),
+                    top: round($parent.offset().top) - $parent.scrollTop() };
 
-        /*
-         * Workaround for jQuery 1.3.2 incorrect offset calculation, originally
-         * observed in Safari 3. Firefox 2 is also affected.
-         */
-        if ($().jquery == '1.3.2' && position == 'fixed' &&
-            !docElem['getBoundingClientRect'])
-        {
-            imgOfs.top += max(document.body.scrollTop, docElem.scrollTop);
-            imgOfs.left += max(document.body.scrollLeft, docElem.scrollLeft);
-        }
-
-        /* Determine parent element offset */
-        parOfs = /absolute|relative/.test($parent.css('position')) ?
-            { left: round($parent.offset().left) - $parent.scrollLeft(),
-                top: round($parent.offset().top) - $parent.scrollTop() } :
-            position == 'fixed' ?
-                { left: $(document).scrollLeft(), top: $(document).scrollTop() } :
-                { left: 0, top: 0 };
-
         left = viewX(0);
         top = viewY(0);
-
+        
         /*
          * Check if selection area is within image boundaries, adjust if
          * necessary
          */
         if (selection.x2 > imgWidth || selection.y2 > imgHeight)
-            doResize();
+            fixAreaCoords();
     }
 
     /**
      * Update plugin elements
-     *
+     * 
      * @param resetKeyPress
      *            If set to <code>false</code>, this instance's keypress
      *            event handler is not activated
@@ -349,27 +346,29 @@
         /*
          * Reset the position of selection area, borders, and handles (IE6/IE7
          * position them incorrectly if we don't do this)
-         */
+         */ 
         $area.add($border).add($handles).css({ left: 0, top: 0 });
 
         /* Set border dimensions */
-        $border
+        $border.add($outer)
             .width(max(w - $border.outerWidth() + $border.innerWidth(), 0))
             .height(max(h - $border.outerHeight() + $border.innerHeight(), 0));
 
-        /* Arrange the outer area elements */
-        $($outer[0]).css({ left: left, top: top,
-            width: selection.x1, height: imgHeight });
-        $($outer[1]).css({ left: left + selection.x1, top: top,
-            width: w, height: selection.y1 });
-        $($outer[2]).css({ left: left + selection.x2, top: top,
-            width: imgWidth - selection.x2, height: imgHeight });
-        $($outer[3]).css({ left: left + selection.x1, top: top + selection.y2,
-            width: w, height: imgHeight - selection.y2 });
+        /* Set the dimensions and border styles of the outer area */
+        $outer.css({
+            left: left,
+            top: top,
+            width: w,
+            height: h,
+            borderStyle: 'solid',
+            borderWidth: selection.y1 + 'px ' +
+                (imgWidth - selection.x2) + 'px ' + (imgHeight - selection.y2) +
+                'px ' + selection.x1 + 'px'
+        });
 
         w -= $handles.outerWidth();
         h -= $handles.outerHeight();
-
+        
         /* Arrange handles */
         switch ($handles.length) {
         case 8:
@@ -387,7 +386,7 @@
              * Need to reset the document keypress event handler -- unbind the
              * current handler
              */
-            if ($.imgAreaSelect.onKeyPress != docKeyPress)
+            if ($.imgAreaSelect.keyPress != docKeyPress)
                 $(document).unbind($.imgAreaSelect.keyPress,
                     $.imgAreaSelect.onKeyPress);
 
@@ -399,29 +398,12 @@
                 $(document)[$.imgAreaSelect.keyPress](
                     $.imgAreaSelect.onKeyPress = docKeyPress);
         }
-
-        /*
-         * 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.
-         */
-        if (msie && $border.outerWidth() - $border.innerWidth() == 2) {
-            $border.css('margin', 0);
-            setTimeout(function () { $border.css('margin', 'auto'); }, 0);
-        }
     }
-
+    
     /**
      * 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
@@ -432,10 +414,10 @@
         x1 = viewX(selection.x1); y1 = viewY(selection.y1);
         x2 = viewX(selection.x2); y2 = viewY(selection.y2);
     }
-
+    
     /**
      * Hide or fade out an element (or multiple elements)
-     *
+     * 
      * @param $elem
      *            A jQuery object containing the element(s) to hide/fade out
      * @param fn
@@ -442,26 +424,32 @@
      *            Callback function to be called when fadeOut() completes
      */
     function hide($elem, fn) {
-        options.fadeSpeed ? $elem.fadeOut(options.fadeSpeed, fn) : $elem.hide();
+        options.fadeDuration ? $elem.fadeOut(options.fadeDuration, fn) : $elem.hide();
     }
 
     /**
-     * Selection area mousemove event handler
+     * Check if a touch event is expected and if the passed event object really
+     * is a touch event
      *
      * @param event
      *            The event object
+     * @return True if the event handler should be interrupted
      */
-    function areaMouseMove(event) {
+    function breakWhenNoTouch(event) {
+        return touch && !/^touch/.test(event.type);
+    }
+
+    /**
+     * Check event coordinates to determine if the selection area should be
+     * resized or moved
+     *
+     * @param event
+     *            The event object
+     */
+    function checkResize(event) {
         var x = selX(evX(event)) - selection.x1,
             y = selY(evY(event)) - selection.y1;
 
-        if (!adjusted) {
-            adjust();
-            adjusted = true;
-
-            $box.one('mouseout', function () { adjusted = false; });
-        }
-
         /* Clear the resize mode */
         resize = '';
 
@@ -482,17 +470,37 @@
 
         $box.css('cursor', resize ? resize + '-resize' :
             options.movable ? 'move' : '');
-        if ($areaOpera)
-            $areaOpera.toggle();
     }
 
     /**
+     * Selection area mousemove event handler
+     * 
+     * @param event
+     *            The event object
+     */
+    function areaMouseMove(event) {
+        if (breakWhenNoTouch(event))
+            return;
+
+        if (!adjusted) {
+            adjust();
+            adjusted = true;
+
+            $box.one('mouseout', function () { adjusted = false; });
+        }
+
+        checkResize(event);
+    }
+
+    /**
      * Document mouseup event handler
-     *
+     * 
      * @param event
      *            The event object
      */
     function docMouseUp(event) {
+        /* Reset touch action flag */
+        touch = false;
         /* Set back the default cursor */
         $('body').css('cursor', '');
         /*
@@ -504,13 +512,19 @@
 
         $(document).off('mousemove touchmove', selectingMouseMove);
         $box.on('mousemove touchmove', areaMouseMove);
-
-        options.onSelectEnd(img, getSelection());
+        
+        /*
+         * If docMouseUp() is called by areaMouseDown() to work around the issue
+         * with Android Chrome, there is no event object, and we don't want to
+         * run the onSelectEnd callback function.
+         */
+        if (event)
+            options.onSelectEnd(img, getSelection());
     }
 
     /**
      * Selection area mousedown event handler
-     *
+     * 
      * @param event
      *            The event object
      * @return false
@@ -517,23 +531,46 @@
      */
     function areaMouseDown(event) {
         if (event.type == 'mousedown' && event.which != 1) return false;
+        
+        if (event.type == 'touchstart') {
+            /*
+             * Android Chrome often does not produce a touchend event
+             * (https://code.google.com/p/chromium/issues/detail?id=152913), so
+             * if it appears that the touch flag is still set, we call the
+             * mouseup/touchend event handler to clean up after the previous
+             * touch action.
+             */
+            if (touch)
+                docMouseUp();
 
-    	/*
-    	 * With mobile browsers, there is no "moving the pointer over" action,
-    	 * so we need to simulate one mousemove event happening prior to
-    	 * mousedown/touchstart.
-    	 */
-    	areaMouseMove(event);
+            /* This is a start of a touch action */
+            touch = true;
 
-        adjust();
+            /* 
+             * Normally, checkResize() is called by the mousemove event handler
+             * triggered just before mousedown, but with a touch action there
+             * is no mousemove, so we need to call it explicitly.
+             */
+            checkResize(event);
+        }
+        else
+            adjust();
 
         if (resize) {
             /* Resize mode is in effect */
-            $('body').css('cursor', resize + '-resize');
 
-            x1 = viewX(selection[/w/.test(resize) ? 'x2' : 'x1']);
-            y1 = viewY(selection[/n/.test(resize) ? 'y2' : 'y1']);
+            /*
+             * Set (x1, y1) to the fixed corner of the selection area, and (x2,
+             * y2) to the corner that's being moved.
+             */
+            x1 = viewX(selection['x' + (1 + /w/.test(resize))]);
+            y1 = viewY(selection['y' + (1 + /n/.test(resize))]);
+            x2 = viewX(selection['x' + (1 + !/w/.test(resize))]);
+            y2 = viewY(selection['y' + (1 + !/n/.test(resize))]);
 
+            edgeX = x2 - evX(event);
+            edgeY = y2 - evY(event);
+
             $(document).on('mousemove touchmove', selectingMouseMove)
                 .one('mouseup touchend', docMouseUp);
             $box.off('mousemove touchmove', areaMouseMove);
@@ -546,6 +583,7 @@
 
             $(document).on('mousemove touchmove', movingMouseMove)
                 .one('mouseup touchend', function () {
+                    touch = false;
                     options.onSelectEnd(img, getSelection());
 
                     $(document).off('mousemove touchmove', movingMouseMove);
@@ -560,7 +598,7 @@
 
     /**
      * 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.
@@ -569,7 +607,7 @@
         if (aspectRatio)
             if (xFirst) {
                 x2 = max(left, min(left + imgWidth,
-                    x1 + abs(y2 - y1) * aspectRatio * (x2 > x1 || -1)));
+                    x1 + abs(y2 - y1) * aspectRatio * (x2 > x1 || -1)));    
                 y2 = round(max(top, min(top + imgHeight,
                     y1 + abs(x2 - x1) / aspectRatio * (y2 > y1 || -1))));
                 x2 = round(x2);
@@ -584,10 +622,10 @@
     }
 
     /**
-     * Resize the selection area respecting the minimum/maximum dimensions and
-     * aspect ratio
+     * Check if the coordinates of the selection area are within the required
+     * limits and conform to the aspect ratio; adjust if necessary
      */
-    function doResize() {
+    function fixAreaCoords() {
         /*
          * Make sure the top left corner of the selection area stays within
          * image boundaries (it might not if the image source was dynamically
@@ -595,7 +633,7 @@
          */
         x1 = min(x1, left + imgWidth);
         y1 = min(y1, top + imgHeight);
-
+        
         if (abs(x2 - x1) < minWidth) {
             /* Selection width is smaller than minWidth */
             x2 = x1 - minWidth * (x2 < x1 || -1);
@@ -618,7 +656,7 @@
 
         x2 = max(left, min(x2, left + imgWidth));
         y2 = max(top, min(y2, top + imgHeight));
-
+        
         fixAspectRatio(abs(x2 - x1) < abs(y2 - y1) * aspectRatio);
 
         if (abs(x2 - x1) > maxWidth) {
@@ -636,7 +674,15 @@
         selection = { x1: selX(min(x1, x2)), x2: selX(max(x1, x2)),
             y1: selY(min(y1, y2)), y2: selY(max(y1, y2)),
             width: abs(x2 - x1), height: abs(y2 - y1) };
+    }
 
+    /**
+     * Resize the selection area respecting the minimum/maximum dimensions and
+     * aspect ratio
+     */
+    function doResize() {
+        fixAreaCoords();
+
         update();
 
         options.onSelectChange(img, getSelection());
@@ -644,23 +690,28 @@
 
     /**
      * Mousemove event handler triggered when the user is selecting an area
-     *
+     * 
      * @param event
      *            The event object
      * @return false
      */
     function selectingMouseMove(event) {
-        x2 = /w|e|^$/.test(resize) || aspectRatio ? evX(event) : viewX(selection.x2);
-        y2 = /n|s|^$/.test(resize) || aspectRatio ? evY(event) : viewY(selection.y2);
+        if (breakWhenNoTouch(event))
+            return;
+        
+        fixAreaCoords();
 
+        x2 = /w|e|^$/.test(resize) || aspectRatio ? evX(event) + edgeX : viewX(selection.x2);
+        y2 = /n|s|^$/.test(resize) || aspectRatio ? evY(event) + edgeY : viewY(selection.y2);
+
         doResize();
 
-        return false;
+        return false;        
     }
 
     /**
      * Move the selection area
-     *
+     * 
      * @param newX1
      *            New viewport X1
      * @param newY1
@@ -680,18 +731,21 @@
 
     /**
      * Mousemove event handler triggered when the selection area is being moved
-     *
+     * 
      * @param event
      *            The event object
      * @return false
      */
     function movingMouseMove(event) {
+        if (breakWhenNoTouch(event))
+            return;
+
         x1 = max(left, min(startX + evX(event), left + imgWidth - selection.width));
         y1 = max(top, min(startY + evY(event), top + imgHeight - selection.height));
 
         doMove(x1, y1);
 
-        event.preventDefault();
+        event.preventDefault();     
         return false;
     }
 
@@ -703,7 +757,7 @@
         adjust();
 
         x2 = x1;
-        y2 = y1;
+        y2 = y1;       
         doResize();
 
         resize = '';
@@ -710,7 +764,7 @@
 
         if (!$outer.is(':visible'))
             /* Show the plugin elements */
-            $box.add($outer).hide().fadeIn(options.fadeSpeed||0);
+            $box.add($outer).hide().fadeIn(options.fadeDuration||0)
 
         shown = true;
 
@@ -729,9 +783,9 @@
         $(document).off('mousemove touchmove', startSelection)
             .off('mouseup touchend', cancelSelection);
         hide($box.add($outer));
-
+        
         setSelection(selX(x1), selY(y1), selX(x1), selY(y1));
-
+        
         /* If this is an API call, callback functions should not be triggered */
         if (!(this instanceof $.imgAreaSelect)) {
             options.onSelectChange(img, getSelection());
@@ -741,7 +795,7 @@
 
     /**
      * Image mousedown event handler
-     *
+     * 
      * @param event
      *            The event object
      * @return false
@@ -748,11 +802,17 @@
      */
     function imgMouseDown(event) {
         /* Ignore the event if animation is in progress */
-        if (event.which != 1 || $outer.is(':animated')) return false;
+        if (event.type == 'mousedown' && event.which != 1 ||
+                $outer.is(':animated'))
+            return false;
 
+        /* If it's a touch action, set the touch flag */
+        touch = event.type == 'touchstart';
+
         adjust();
         startX = x1 = evX(event);
         startY = y1 = evY(event);
+        edgeX = edgeY = 0;
 
         /* Selection will start when the mouse is moved */
         $(document).on({ 'mousemove touchmove': startSelection,
@@ -760,7 +820,7 @@
 
         return false;
     }
-
+    
     /**
      * Window resize event handler
      */
@@ -788,13 +848,11 @@
             onSelectEnd: function () {}
         }, options));
 
-        $box.add($outer).css({ visibility: '' });
-
         if (options.show) {
             shown = true;
             adjust();
             update();
-            $box.add($outer).hide().fadeIn(options.fadeSpeed||0);
+            $box.add($outer).hide().fadeIn(options.fadeDuration||0)
         }
 
         /*
@@ -807,7 +865,7 @@
 
     /**
      * Document keypress event handler
-     *
+     * 
      * @param event
      *            The event object
      * @return false
@@ -814,7 +872,7 @@
      */
     var docKeyPress = function(event) {
         var k = options.keys, d, t, key = event.keyCode;
-
+        
         d = !isNaN(k.alt) && (event.altKey || event.originalEvent.altKey) ? k.alt :
             !isNaN(k.ctrl) && event.ctrlKey ? k.ctrl :
             !isNaN(k.shift) && event.shiftKey ? k.shift :
@@ -825,7 +883,7 @@
             (k.alt == 'resize' && (event.altKey || event.originalEvent.altKey)))
         {
             /* Resize selection */
-
+            
             switch (key) {
             case 37:
                 /* Left */
@@ -855,7 +913,7 @@
         }
         else {
             /* Move selection */
-
+            
             x1 = min(x1, x2);
             y1 = min(y1, y2);
 
@@ -885,30 +943,15 @@
     };
 
     /**
-     * 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
-     */
-    function styleOptions($elem, props) {
-        for (var option in props)
-            if (options[option] !== undefined)
-                $elem.css(props[option], options[option]);
-    }
-
-    /**
      * Set plugin options
-     *
+     * 
      * @param newOptions
      *            The new options object
      */
     function setOptions(newOptions) {
         if (newOptions.parent)
-            ($parent = $(newOptions.parent)).append($box.add($outer));
-
+            ($parent = $(newOptions.parent)).append($box).append($outer);
+        
         /* Merge the new options with the existing ones */
         $.extend(options, newOptions);
 
@@ -923,7 +966,7 @@
 
             while (i--)
                 $handles = $handles.add(div());
-
+            
             /* Add a class to handles and set the CSS properties */
             $handles.addClass(options.classPrefix + '-handle').css({
                 position: 'absolute',
@@ -934,7 +977,7 @@
                 fontSize: 0,
                 zIndex: zIndex + 1 || 1
             });
-
+            
             /*
              * If handle width/height has not been set with CSS rules, set the
              * default 5px
@@ -941,18 +984,6 @@
              */
             if (!parseInt($handles.css('width')) >= 0)
                 $handles.width(5).height(5);
-
-            /*
-             * If the borderWidth option is in use, add a solid border to
-             * handles
-             */
-            if (o = options.borderWidth)
-                $handles.css({ borderWidth: o, borderStyle: 'solid' });
-
-            /* Apply other style options */
-            styleOptions($handles, { borderColor1: 'border-color',
-                borderColor2: 'background-color',
-                borderOpacity: 'opacity' });
         }
 
         /* Calculate scale factors */
@@ -977,20 +1008,8 @@
         for (i = 0; i++ < 4;)
             $($border[i-1]).addClass(options.classPrefix + '-border' + i);
 
-        /* Apply style options */
-        styleOptions($area, { selectionColor: 'background-color',
-            selectionOpacity: 'opacity' });
-        styleOptions($border, { borderOpacity: 'opacity',
-            borderWidth: 'border-width' });
-        styleOptions($outer, { outerColor: 'background-color',
-            outerOpacity: 'opacity' });
-        if (o = options.borderColor1)
-            $($border[0]).css({ borderStyle: 'solid', borderColor: o });
-        if (o = options.borderColor2)
-            $($border[1]).css({ borderStyle: 'dashed', borderColor: o });
-
         /* Append all the selection area elements to the container box */
-        $box.append($area.add($border).add($areaOpera)).append($handles);
+        $box.append($area.add($border)).append($handles);
 
         if (msie) {
             if (o = ($outer.css('filter')||'').match(/opacity=(\d+)/))
@@ -998,12 +1017,12 @@
             if (o = ($border.css('filter')||'').match(/opacity=(\d+)/))
                 $border.css('opacity', o[1]/100);
         }
-
+        
         if (newOptions.hide)
             hide($box.add($outer));
         else if (newOptions.show && imgLoaded) {
             shown = true;
-            $box.add($outer).fadeIn(options.fadeSpeed||0);
+            $box.add($outer).fadeIn(options.fadeDuration||0)
             doUpdate();
         }
 
@@ -1010,8 +1029,8 @@
         /* Calculate the aspect ratio factor */
         aspectRatio = (d = (options.aspectRatio || '').split(/:/))[0] / d[1];
 
-        $img.add($outer).unbind('mousedown', imgMouseDown);
-
+        $img.add($outer).off('mousedown touchstart', imgMouseDown);
+        
         if (options.disable || options.enable === false) {
             /* Disable the plugin */
             $box.off({ 'mousemove touchmove': areaMouseMove,
@@ -1024,7 +1043,7 @@
                 if (options.resizable || options.movable)
                     $box.on({ 'mousemove touchmove': areaMouseMove,
                         'mousedown touchstart': areaMouseDown });
-
+    
                 $(window).resize(windowResize);
             }
 
@@ -1031,10 +1050,10 @@
             if (!options.persistent)
                 $img.add($outer).on('mousedown touchstart', imgMouseDown);
         }
-
+        
         options.enable = options.disable = undefined;
     }
-
+    
     /**
      * Remove plugin completely
      */
@@ -1045,29 +1064,29 @@
         setOptions({ disable: true });
         $box.add($outer).remove();
     };
-
+    
     /*
      * Public API
      */
-
+    
     /**
      * Get current options
-     *
+     * 
      * @return An object containing the set of options currently in use
      */
     this.getOptions = function () { return options; };
-
+    
     /**
      * Set plugin options
-     *
+     * 
      * @param newOptions
      *            The new options object
      */
     this.setOptions = setOptions;
-
+    
     /**
      * Get the current selection
-     *
+     * 
      * @param noScale
      *            If set to <code>true</code>, scaling is not applied to the
      *            returned selection
@@ -1074,10 +1093,10 @@
      * @return Selection object
      */
     this.getSelection = getSelection;
-
+    
     /**
      * Set the current selection
-     *
+     * 
      * @param x1
      *            X coordinate of the upper left corner of the selection area
      * @param y1
@@ -1091,15 +1110,15 @@
      *            new selection
      */
     this.setSelection = setSelection;
-
+    
     /**
      * 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
@@ -1108,10 +1127,9 @@
 
     /* 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
      */
@@ -1120,8 +1138,11 @@
     while ($p.length) {
         zIndex = max(zIndex,
             !isNaN($p.css('z-index')) ? $p.css('z-index') : zIndex);
-        /* Also check if any of the ancestor elements has fixed position */
-        if ($p.css('position') == 'fixed')
+        /*
+         * If the parent element is not set explicitly, check if any of the
+         * ancestor elements has fixed position
+         */ 
+        if (!options.parent && $p.css('position') == 'fixed')
             position = 'fixed';
 
         $p = $p.parent(':not(body)');
@@ -1133,37 +1154,16 @@
      */
     zIndex = options.zIndex || zIndex;
 
-    if (msie)
-        $img.attr('unselectable', 'on');
-
     /*
      * In MSIE and WebKit, we need to use the keydown event instead of keypress
      */
     $.imgAreaSelect.keyPress = msie || safari ? 'keydown' : 'keypress';
 
-    /*
-     * 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.
-     */
-    if (opera)
-        $areaOpera = div().css({ width: '100%', height: '100%',
-            position: 'absolute', zIndex: zIndex + 2 || 2 });
-
-    /*
-     * 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().
-     */
-    $box.add($outer).css({ visibility: 'hidden', position: position,
-        overflow: 'hidden', zIndex: zIndex || '0' });
+    $box.add($outer).hide().css({ position: position, overflow: 'hidden',
+        zIndex: zIndex || '0' });
     $box.css({ zIndex: zIndex + 2 || 2 });
     $area.add($border).css({ position: 'absolute', fontSize: 0 });
-
+    
     /*
      * 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
@@ -1172,7 +1172,7 @@
     img.complete || img.readyState == 'complete' || !$img.is('img') ?
         imgLoad() : $img.one('load', imgLoad);
 
-    /*
+    /* 
      * 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.
@@ -1183,7 +1183,7 @@
 
 /**
  * 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
@@ -1207,11 +1207,11 @@
         }
         else if (!options.remove) {
             /* No exising instance -- create a new one */
-
+            
             /*
              * If neither the "enable" nor the "disable" option is present, add
              * "enable" as the default
-             */
+             */ 
             if (options.enable === undefined && options.disable === undefined)
                 options.enable = true;
 
@@ -1218,7 +1218,7 @@
             $(this).data('imgAreaSelect', new $.imgAreaSelect(this, options));
         }
     });
-
+    
     if (options.instance)
         /*
          * Return the imgAreaSelect instance bound to the first element in the
Index: trunk/wp-includes/js/imgareaselect/jquery.imgareaselect.min.js
===================================================================
--- trunk/wp-includes/js/imgareaselect/jquery.imgareaselect.min.js	(revision 40213)
+++ trunk/wp-includes/js/imgareaselect/jquery.imgareaselect.min.js	(working copy)
@@ -1 +1 @@
-!function(e){function t(){return e("<div/>")}var o=Math.abs,i=Math.max,s=Math.min,n=Math.round;e.imgAreaSelect=function(r,c){function d(e){return e+gt.left-vt.left}function a(e){return e+gt.top-vt.top}function u(e){return e-gt.left+vt.left}function l(e){return e-gt.top+vt.top}function h(e){return i(e.pageX||0,m(e).x)-vt.left}function f(e){return i(e.pageY||0,m(e).y)-vt.top}function m(e){var t=e.originalEvent||{};return t.touches&&t.touches.length?{x:t.touches[0].pageX,y:t.touches[0].pageY}:{x:0,y:0}}function p(e){var t=e||B,o=e||Q;return{x1:n(wt.x1*t),y1:n(wt.y1*o),x2:n(wt.x2*t),y2:n(wt.y2*o),width:n(wt.x2*t)-n(wt.x1*t),height:n(wt.y2*o)-n(wt.y1*o)}}function y(e,t,o,i,s){var r=s||B,c=s||Q;wt={x1:n(e/r||0),y1:n(t/c||0),x2:n(o/r||0),y2:n(i/c||0)},wt.width=wt.x2-wt.x1,wt.height=wt.y2-wt.y1}function g(){T&&lt.width()&&(gt={left:n(lt.offset().left),top:n(lt.offset().top)},R=lt.innerWidth(),X=lt.innerHeight(),gt.top+=lt.outerHeight()-X>>1,gt.left+=lt.outerWidth()-R>>1,G=n(c.minWidth/B)||0,J=n(c.minHeight/Q)||0,U=n(s(c.maxWidth/B||1<<24,R)),V=n(s(c.maxHeight/Q||1<<24,X)),"1.3.2"!=e().jquery||"fixed"!=xt||St.getBoundingClientRect||(gt.top+=i(document.body.scrollTop,St.scrollTop),gt.left+=i(document.body.scrollLeft,St.scrollLeft)),vt=/absolute|relative/.test(Y.css("position"))?{left:n(Y.offset().left)-Y.scrollLeft(),top:n(Y.offset().top)-Y.scrollTop()}:"fixed"==xt?{left:e(document).scrollLeft(),top:e(document).scrollTop()}:{left:0,top:0},j=d(0),D=a(0),(wt.x2>R||wt.y2>X)&&C())}function v(t){if(_){switch(ht.css({left:d(wt.x1),top:a(wt.y1)}).add(ft).width(dt=wt.width).height(at=wt.height),ft.add(mt).add(yt).css({left:0,top:0}),mt.width(i(dt-mt.outerWidth()+mt.innerWidth(),0)).height(i(at-mt.outerHeight()+mt.innerHeight(),0)),e(pt[0]).css({left:j,top:D,width:wt.x1,height:X}),e(pt[1]).css({left:j+wt.x1,top:D,width:dt,height:wt.y1}),e(pt[2]).css({left:j+wt.x2,top:D,width:R-wt.x2,height:X}),e(pt[3]).css({left:j+wt.x1,top:D+wt.y2,width:dt,height:X-wt.y2}),dt-=yt.outerWidth(),at-=yt.outerHeight(),yt.length){case 8:e(yt[4]).css({left:dt>>1}),e(yt[5]).css({left:dt,top:at>>1}),e(yt[6]).css({left:dt>>1,top:at}),e(yt[7]).css({top:at>>1});case 4:yt.slice(1,3).css({left:dt}),yt.slice(2,4).css({top:at})}t!==!1&&(e.imgAreaSelect.onKeyPress!=kt&&e(document).unbind(e.imgAreaSelect.keyPress,e.imgAreaSelect.onKeyPress),c.keys&&e(document)[e.imgAreaSelect.keyPress](e.imgAreaSelect.onKeyPress=kt)),Ct&&mt.outerWidth()-mt.innerWidth()==2&&(mt.css("margin",0),setTimeout(function(){mt.css("margin","auto")},0))}}function b(e){g(),v(e),et=d(wt.x1),tt=a(wt.y1),ot=d(wt.x2),it=a(wt.y2)}function x(e,t){c.fadeSpeed?e.fadeOut(c.fadeSpeed,t):e.hide()}function w(e){var t=u(h(e))-wt.x1,o=l(f(e))-wt.y1;ut||(g(),ut=!0,ht.one("mouseout",function(){ut=!1})),F="",c.resizable&&(o<=c.resizeMargin?F="n":o>=wt.height-c.resizeMargin&&(F="s"),t<=c.resizeMargin?F+="w":t>=wt.width-c.resizeMargin&&(F+="e")),ht.css("cursor",F?F+"-resize":c.movable?"move":""),L&&L.toggle()}function S(){e("body").css("cursor",""),(c.autoHide||wt.width*wt.height==0)&&x(ht.add(pt),function(){e(this).hide()}),e(document).off("mousemove touchmove",A),ht.on("mousemove touchmove",w),c.onSelectEnd(r,p())}function z(t){return"mousedown"==t.type&&1!=t.which?!1:(w(t),g(),F?(e("body").css("cursor",F+"-resize"),et=d(wt[/w/.test(F)?"x2":"x1"]),tt=a(wt[/n/.test(F)?"y2":"y1"]),e(document).on("mousemove touchmove",A).one("mouseup touchend",S),ht.off("mousemove touchmove",w)):c.movable?($=j+wt.x1-h(t),q=D+wt.y1-f(t),ht.off("mousemove touchmove",w),e(document).on("mousemove touchmove",I).one("mouseup touchend",function(){c.onSelectEnd(r,p()),e(document).off("mousemove touchmove",I),ht.on("mousemove touchmove",w)})):lt.mousedown(t),!1)}function k(e){Z&&(e?(ot=i(j,s(j+R,et+o(it-tt)*Z*(ot>et||-1))),it=n(i(D,s(D+X,tt+o(ot-et)/Z*(it>tt||-1)))),ot=n(ot)):(it=i(D,s(D+X,tt+o(ot-et)/Z*(it>tt||-1))),ot=n(i(j,s(j+R,et+o(it-tt)*Z*(ot>et||-1)))),it=n(it)))}function C(){et=s(et,j+R),tt=s(tt,D+X),o(ot-et)<G&&(ot=et-G*(et>ot||-1),j>ot?et=j+G:ot>j+R&&(et=j+R-G)),o(it-tt)<J&&(it=tt-J*(tt>it||-1),D>it?tt=D+J:it>D+X&&(tt=D+X-J)),ot=i(j,s(ot,j+R)),it=i(D,s(it,D+X)),k(o(ot-et)<o(it-tt)*Z),o(ot-et)>U&&(ot=et-U*(et>ot||-1),k()),o(it-tt)>V&&(it=tt-V*(tt>it||-1),k(!0)),wt={x1:u(s(et,ot)),x2:u(i(et,ot)),y1:l(s(tt,it)),y2:l(i(tt,it)),width:o(ot-et),height:o(it-tt)},v(),c.onSelectChange(r,p())}function A(e){return ot=/w|e|^$/.test(F)||Z?h(e):d(wt.x2),it=/n|s|^$/.test(F)||Z?f(e):a(wt.y2),C(),!1}function W(t,o){ot=(et=t)+wt.width,it=(tt=o)+wt.height,e.extend(wt,{x1:u(et),y1:l(tt),x2:u(ot),y2:l(it)}),v(),c.onSelectChange(r,p())}function I(e){return et=i(j,s($+h(e),j+R-wt.width)),tt=i(D,s(q+f(e),D+X-wt.height)),W(et,tt),e.preventDefault(),!1}function K(){e(document).off("mousemove touchmove",K),g(),ot=et,it=tt,C(),F="",pt.is(":visible")||ht.add(pt).hide().fadeIn(c.fadeSpeed||0),_=!0,e(document).off("mouseup touchend",P).on("mousemove touchmove",A).one("mouseup touchend",S),ht.off("mousemove touchmove",w),c.onSelectStart(r,p())}function P(){e(document).off("mousemove touchmove",K).off("mouseup touchend",P),x(ht.add(pt)),y(u(et),l(tt),u(et),l(tt)),this instanceof e.imgAreaSelect||(c.onSelectChange(r,p()),c.onSelectEnd(r,p()))}function N(t){return 1!=t.which||pt.is(":animated")?!1:(g(),$=et=h(t),q=tt=f(t),e(document).on({"mousemove touchmove":K,"mouseup touchend":P}),!1)}function H(){b(!1)}function M(){T=!0,O(c=e.extend({classPrefix:"imgareaselect",movable:!0,parent:"body",resizable:!0,resizeMargin:10,onInit:function(){},onSelectStart:function(){},onSelectChange:function(){},onSelectEnd:function(){}},c)),ht.add(pt).css({visibility:""}),c.show&&(_=!0,g(),v(),ht.add(pt).hide().fadeIn(c.fadeSpeed||0)),setTimeout(function(){c.onInit(r,p())},0)}function E(e,t){for(var o in t)void 0!==c[o]&&e.css(t[o],c[o])}function O(o){if(o.parent&&(Y=e(o.parent)).append(ht.add(pt)),e.extend(c,o),g(),null!=o.handles){for(yt.remove(),yt=e([]),rt=o.handles?"corners"==o.handles?4:8:0;rt--;)yt=yt.add(t());yt.addClass(c.classPrefix+"-handle").css({position:"absolute",fontSize:0,zIndex:bt+1||1}),!parseInt(yt.css("width"))>=0&&yt.width(5).height(5),(ct=c.borderWidth)&&yt.css({borderWidth:ct,borderStyle:"solid"}),E(yt,{borderColor1:"border-color",borderColor2:"background-color",borderOpacity:"opacity"})}for(B=c.imageWidth/R||1,Q=c.imageHeight/X||1,null!=o.x1&&(y(o.x1,o.y1,o.x2,o.y2),o.show=!o.hide),o.keys&&(c.keys=e.extend({shift:1,ctrl:"resize"},o.keys)),pt.addClass(c.classPrefix+"-outer"),ft.addClass(c.classPrefix+"-selection"),rt=0;rt++<4;)e(mt[rt-1]).addClass(c.classPrefix+"-border"+rt);E(ft,{selectionColor:"background-color",selectionOpacity:"opacity"}),E(mt,{borderOpacity:"opacity",borderWidth:"border-width"}),E(pt,{outerColor:"background-color",outerOpacity:"opacity"}),(ct=c.borderColor1)&&e(mt[0]).css({borderStyle:"solid",borderColor:ct}),(ct=c.borderColor2)&&e(mt[1]).css({borderStyle:"dashed",borderColor:ct}),ht.append(ft.add(mt).add(L)).append(yt),Ct&&((ct=(pt.css("filter")||"").match(/opacity=(\d+)/))&&pt.css("opacity",ct[1]/100),(ct=(mt.css("filter")||"").match(/opacity=(\d+)/))&&mt.css("opacity",ct[1]/100)),o.hide?x(ht.add(pt)):o.show&&T&&(_=!0,ht.add(pt).fadeIn(c.fadeSpeed||0),b()),Z=(nt=(c.aspectRatio||"").split(/:/))[0]/nt[1],lt.add(pt).unbind("mousedown",N),c.disable||c.enable===!1?(ht.off({"mousemove touchmove":w,"mousedown touchstart":z}),e(window).off("resize",H)):((c.enable||c.disable===!1)&&((c.resizable||c.movable)&&ht.on({"mousemove touchmove":w,"mousedown touchstart":z}),e(window).resize(H)),c.persistent||lt.add(pt).on("mousedown touchstart",N)),c.enable=c.disable=void 0}var T,L,j,D,R,X,Y,$,q,B,Q,F,G,J,U,V,Z,_,et,tt,ot,it,st,nt,rt,ct,dt,at,ut,lt=e(r),ht=t(),ft=t(),mt=t().add(t()).add(t()).add(t()),pt=t().add(t()).add(t()).add(t()),yt=e([]),gt={left:0,top:0},vt={left:0,top:0},bt=0,xt="absolute",wt={x1:0,y1:0,x2:0,y2:0,width:0,height:0},St=document.documentElement,zt=navigator.userAgent,kt=function(e){var t,o,n=c.keys,r=e.keyCode;if(t=isNaN(n.alt)||!e.altKey&&!e.originalEvent.altKey?!isNaN(n.ctrl)&&e.ctrlKey?n.ctrl:!isNaN(n.shift)&&e.shiftKey?n.shift:isNaN(n.arrows)?10:n.arrows:n.alt,"resize"==n.arrows||"resize"==n.shift&&e.shiftKey||"resize"==n.ctrl&&e.ctrlKey||"resize"==n.alt&&(e.altKey||e.originalEvent.altKey)){switch(r){case 37:t=-t;case 39:o=i(et,ot),et=s(et,ot),ot=i(o+t,et),k();break;case 38:t=-t;case 40:o=i(tt,it),tt=s(tt,it),it=i(o+t,tt),k(!0);break;default:return}C()}else switch(et=s(et,ot),tt=s(tt,it),r){case 37:W(i(et-t,j),tt);break;case 38:W(et,i(tt-t,D));break;case 39:W(et+s(t,R-u(ot)),tt);break;case 40:W(et,tt+s(t,X-l(it)));break;default:return}return!1};this.remove=function(){O({disable:!0}),ht.add(pt).remove()},this.getOptions=function(){return c},this.setOptions=O,this.getSelection=p,this.setSelection=y,this.cancelSelection=P,this.update=b;var Ct=(/msie ([\w.]+)/i.exec(zt)||[])[1],At=/opera/i.test(zt),Wt=/webkit/i.test(zt)&&!/chrome/i.test(zt);for(st=lt;st.length;)bt=i(bt,isNaN(st.css("z-index"))?bt:st.css("z-index")),"fixed"==st.css("position")&&(xt="fixed"),st=st.parent(":not(body)");bt=c.zIndex||bt,Ct&&lt.attr("unselectable","on"),e.imgAreaSelect.keyPress=Ct||Wt?"keydown":"keypress",At&&(L=t().css({width:"100%",height:"100%",position:"absolute",zIndex:bt+2||2})),ht.add(pt).css({visibility:"hidden",position:xt,overflow:"hidden",zIndex:bt||"0"}),ht.css({zIndex:bt+2||2}),ft.add(mt).css({position:"absolute",fontSize:0}),r.complete||"complete"==r.readyState||!lt.is("img")?M():lt.one("load",M),!T&&Ct&&Ct>=7&&(r.src=r.src)},e.fn.imgAreaSelect=function(t){return t=t||{},this.each(function(){e(this).data("imgAreaSelect")?t.remove?(e(this).data("imgAreaSelect").remove(),e(this).removeData("imgAreaSelect")):e(this).data("imgAreaSelect").setOptions(t):t.remove||(void 0===t.enable&&void 0===t.disable&&(t.enable=!0),e(this).data("imgAreaSelect",new e.imgAreaSelect(this,t)))}),t.instance?e(this).data("imgAreaSelect"):this}}(jQuery);
\ No newline at end of file
+/*! imgareaselect 1.0.0-rc.1 */ (function(e){function t(){return e("<div/>")}var o=Math.abs,n=Math.max,i=Math.min,s=Math.round;e.imgAreaSelect=function(a,c){function r(e){return e+bt.left-St.left}function d(e){return e+bt.top-St.top}function u(e){return e-bt.left+St.left}function h(e){return e-bt.top+St.top}function f(e){var t,o=m(e)||e;return(t=parseInt(o.pageX))?t-St.left:void 0}function l(e){var t,o=m(e)||e;return(t=parseInt(o.pageY))?t-St.top:void 0}function m(e){var t=e.originalEvent||{};return t.touches&&t.touches.length?t.touches[0]:!1}function p(e){var t=e||G,o=e||J;return{x1:s(At.x1*t),y1:s(At.y1*o),x2:s(At.x2*t)-1,y2:s(At.y2*o)-1,width:s(At.x2*t)-s(At.x1*t),height:s(At.y2*o)-s(At.y1*o)}}function v(e,t,o,n,i){var a=i||G,c=i||J;At={x1:s(e/a||0),y1:s(t/c||0),x2:s(++o/a||0),y2:s(++n/c||0)},At.width=At.x2-At.x1,At.height=At.y2-At.y1}function y(){$&&pt.width()&&(bt={left:s(pt.offset().left),top:s(pt.offset().top)},Q=pt.innerWidth(),R=pt.innerHeight(),bt.top+=pt.outerHeight()-R>>1,bt.left+=pt.outerWidth()-Q>>1,V=s(c.minWidth/G)||0,Z=s(c.minHeight/J)||0,_=s(i(c.maxWidth/G||1<<24,Q)),et=s(i(c.maxHeight/J||1<<24,R)),St="fixed"==kt?{left:e(document).scrollLeft(),top:e(document).scrollTop()}:/static|^$/.test(X.css("position"))?{left:0,top:0}:{left:s(X.offset().left)-X.scrollLeft(),top:s(X.offset().top)-X.scrollTop()},L=r(0),j=d(0),(At.x2>Q||At.y2>R)&&P())}function g(t){if(ot){switch(vt.css({left:r(At.x1),top:d(At.y1)}).add(yt).width(ft=At.width).height(lt=At.height),yt.add(gt).add(wt).css({left:0,top:0}),gt.add(xt).width(n(ft-gt.outerWidth()+gt.innerWidth(),0)).height(n(lt-gt.outerHeight()+gt.innerHeight(),0)),xt.css({left:L,top:j,width:ft,height:lt,borderStyle:"solid",borderWidth:At.y1+"px "+(Q-At.x2)+"px "+(R-At.y2)+"px "+At.x1+"px"}),ft-=wt.outerWidth(),lt-=wt.outerHeight(),wt.length){case 8:e(wt[4]).css({left:ft>>1}),e(wt[5]).css({left:ft,top:lt>>1}),e(wt[6]).css({left:ft>>1,top:lt}),e(wt[7]).css({top:lt>>1});case 4:wt.slice(1,3).css({left:ft}),wt.slice(2,4).css({top:lt})}t!==!1&&(e.imgAreaSelect.keyPress!=Pt&&e(document).unbind(e.imgAreaSelect.keyPress,e.imgAreaSelect.onKeyPress),c.keys&&e(document)[e.imgAreaSelect.keyPress](e.imgAreaSelect.onKeyPress=Pt))}}function x(e){y(),g(e),nt=r(At.x1),it=d(At.y1),st=r(At.x2),at=d(At.y2)}function w(e,t){c.fadeDuration?e.fadeOut(c.fadeDuration,t):e.hide()}function b(e){return ct&&!/^touch/.test(e.type)}function S(e){var t=u(f(e))-At.x1,o=h(l(e))-At.y1;U="",c.resizable&&(c.resizeMargin>=o?U="n":o>=At.height-c.resizeMargin&&(U="s"),c.resizeMargin>=t?U+="w":t>=At.width-c.resizeMargin&&(U+="e")),vt.css("cursor",U?U+"-resize":c.movable?"move":"")}function z(e){b(e)||(mt||(y(),mt=!0,vt.one("mouseout",function(){mt=!1})),S(e))}function k(t){ct=!1,e("body").css("cursor",""),(c.autoHide||0==At.width*At.height)&&w(vt.add(xt),function(){e(this).hide()}),e(document).off("mousemove touchmove",N),vt.on("mousemove touchmove",z),t&&c.onSelectEnd(a,p())}function A(t){return"mousedown"==t.type&&1!=t.which?!1:("touchstart"==t.type?(ct&&k(),ct=!0,S(t)):y(),U?(nt=r(At["x"+(1+/w/.test(U))]),it=d(At["y"+(1+/n/.test(U))]),st=r(At["x"+(1+!/w/.test(U))]),at=d(At["y"+(1+!/n/.test(U))]),B=st-f(t),F=at-l(t),e(document).on("mousemove touchmove",N).one("mouseup touchend",k),vt.off("mousemove touchmove",z)):c.movable?(Y=L+At.x1-f(t),q=j+At.y1-l(t),vt.off("mousemove touchmove",z),e(document).on("mousemove touchmove",H).one("mouseup touchend",function(){ct=!1,c.onSelectEnd(a,p()),e(document).off("mousemove touchmove",H),vt.on("mousemove touchmove",z)})):pt.mousedown(t),!1)}function I(e){tt&&(e?(st=n(L,i(L+Q,nt+o(at-it)*tt*(st>nt||-1))),at=s(n(j,i(j+R,it+o(st-nt)/tt*(at>it||-1)))),st=s(st)):(at=n(j,i(j+R,it+o(st-nt)/tt*(at>it||-1))),st=s(n(L,i(L+Q,nt+o(at-it)*tt*(st>nt||-1)))),at=s(at)))}function P(){nt=i(nt,L+Q),it=i(it,j+R),V>o(st-nt)&&(st=nt-V*(nt>st||-1),L>st?nt=L+V:st>L+Q&&(nt=L+Q-V)),Z>o(at-it)&&(at=it-Z*(it>at||-1),j>at?it=j+Z:at>j+R&&(it=j+R-Z)),st=n(L,i(st,L+Q)),at=n(j,i(at,j+R)),I(o(st-nt)<o(at-it)*tt),o(st-nt)>_&&(st=nt-_*(nt>st||-1),I()),o(at-it)>et&&(at=it-et*(it>at||-1),I(!0)),At={x1:u(i(nt,st)),x2:u(n(nt,st)),y1:h(i(it,at)),y2:h(n(it,at)),width:o(st-nt),height:o(at-it)}}function K(){P(),g(),c.onSelectChange(a,p())}function N(e){return b(e)?void 0:(P(),st=/w|e|^$/.test(U)||tt?f(e)+B:r(At.x2),at=/n|s|^$/.test(U)||tt?l(e)+F:d(At.y2),K(),!1)}function C(t,o){st=(nt=t)+At.width,at=(it=o)+At.height,e.extend(At,{x1:u(nt),y1:h(it),x2:u(st),y2:h(at)}),g(),c.onSelectChange(a,p())}function H(e){return b(e)?void 0:(nt=n(L,i(Y+f(e),L+Q-At.width)),it=n(j,i(q+l(e),j+R-At.height)),C(nt,it),e.preventDefault(),!1)}function M(){e(document).off("mousemove touchmove",M),y(),st=nt,at=it,K(),U="",xt.is(":visible")||vt.add(xt).hide().fadeIn(c.fadeDuration||0),ot=!0,e(document).off("mouseup touchend",W).on("mousemove touchmove",N).one("mouseup touchend",k),vt.off("mousemove touchmove",z),c.onSelectStart(a,p())}function W(){e(document).off("mousemove touchmove",M).off("mouseup touchend",W),w(vt.add(xt)),v(u(nt),h(it),u(nt),h(it)),this instanceof e.imgAreaSelect||(c.onSelectChange(a,p()),c.onSelectEnd(a,p()))}function D(t){return"mousedown"==t.type&&1!=t.which||xt.is(":animated")?!1:(ct="touchstart"==t.type,y(),Y=nt=f(t),q=it=l(t),B=F=0,e(document).on({"mousemove touchmove":M,"mouseup touchend":W}),!1)}function E(){x(!1)}function O(){$=!0,T(c=e.extend({classPrefix:"imgareaselect",movable:!0,parent:"body",resizable:!0,resizeMargin:10,onInit:function(){},onSelectStart:function(){},onSelectChange:function(){},onSelectEnd:function(){}},c)),c.show&&(ot=!0,y(),g(),vt.add(xt).hide().fadeIn(c.fadeDuration||0)),setTimeout(function(){c.onInit(a,p())},0)}function T(o){if(o.parent&&(X=e(o.parent)).append(vt).append(xt),e.extend(c,o),y(),null!=o.handles){for(wt.remove(),wt=e([]),ut=o.handles?"corners"==o.handles?4:8:0;ut--;)wt=wt.add(t());wt.addClass(c.classPrefix+"-handle").css({position:"absolute",fontSize:0,zIndex:zt+1||1}),!parseInt(wt.css("width"))>=0&&wt.width(5).height(5)}for(G=c.imageWidth/Q||1,J=c.imageHeight/R||1,null!=o.x1&&(v(o.x1,o.y1,o.x2,o.y2),o.show=!o.hide),o.keys&&(c.keys=e.extend({shift:1,ctrl:"resize"},o.keys)),xt.addClass(c.classPrefix+"-outer"),yt.addClass(c.classPrefix+"-selection"),ut=0;4>ut++;)e(gt[ut-1]).addClass(c.classPrefix+"-border"+ut);vt.append(yt.add(gt)).append(wt),Kt&&((ht=(xt.css("filter")||"").match(/opacity=(\d+)/))&&xt.css("opacity",ht[1]/100),(ht=(gt.css("filter")||"").match(/opacity=(\d+)/))&&gt.css("opacity",ht[1]/100)),o.hide?w(vt.add(xt)):o.show&&$&&(ot=!0,vt.add(xt).fadeIn(c.fadeDuration||0),x()),tt=(dt=(c.aspectRatio||"").split(/:/))[0]/dt[1],pt.add(xt).off("mousedown touchstart",D),c.disable||c.enable===!1?(vt.off({"mousemove touchmove":z,"mousedown touchstart":A}),e(window).off("resize",E)):((c.enable||c.disable===!1)&&((c.resizable||c.movable)&&vt.on({"mousemove touchmove":z,"mousedown touchstart":A}),e(window).resize(E)),c.persistent||pt.add(xt).on("mousedown touchstart",D)),c.enable=c.disable=void 0}var $,L,j,Q,R,X,Y,q,B,F,G,J,U,V,Z,_,et,tt,ot,nt,it,st,at,ct,rt,dt,ut,ht,ft,lt,mt,pt=e(a),vt=t(),yt=t(),gt=t().add(t()).add(t()).add(t()),xt=t(),wt=e([]),bt={left:0,top:0},St={left:0,top:0},zt=0,kt="absolute",At={x1:0,y1:0,x2:0,y2:0,width:0,height:0},It=navigator.userAgent,Pt=function(e){var t,o,s=c.keys,a=e.keyCode;if(t=isNaN(s.alt)||!e.altKey&&!e.originalEvent.altKey?!isNaN(s.ctrl)&&e.ctrlKey?s.ctrl:!isNaN(s.shift)&&e.shiftKey?s.shift:isNaN(s.arrows)?10:s.arrows:s.alt,"resize"==s.arrows||"resize"==s.shift&&e.shiftKey||"resize"==s.ctrl&&e.ctrlKey||"resize"==s.alt&&(e.altKey||e.originalEvent.altKey)){switch(a){case 37:t=-t;case 39:o=n(nt,st),nt=i(nt,st),st=n(o+t,nt),I();break;case 38:t=-t;case 40:o=n(it,at),it=i(it,at),at=n(o+t,it),I(!0);break;default:return}K()}else switch(nt=i(nt,st),it=i(it,at),a){case 37:C(n(nt-t,L),it);break;case 38:C(nt,n(it-t,j));break;case 39:C(nt+i(t,Q-u(st)),it);break;case 40:C(nt,it+i(t,R-h(at)));break;default:return}return!1};this.remove=function(){T({disable:!0}),vt.add(xt).remove()},this.getOptions=function(){return c},this.setOptions=T,this.getSelection=p,this.setSelection=v,this.cancelSelection=W,this.update=x;var Kt=(/msie ([\w.]+)/i.exec(It)||[])[1],Nt=/webkit/i.test(It)&&!/chrome/i.test(It);for(rt=pt;rt.length;)zt=n(zt,isNaN(rt.css("z-index"))?zt:rt.css("z-index")),c.parent||"fixed"!=rt.css("position")||(kt="fixed"),rt=rt.parent(":not(body)");zt=c.zIndex||zt,e.imgAreaSelect.keyPress=Kt||Nt?"keydown":"keypress",vt.add(xt).hide().css({position:kt,overflow:"hidden",zIndex:zt||"0"}),vt.css({zIndex:zt+2||2}),yt.add(gt).css({position:"absolute",fontSize:0}),a.complete||"complete"==a.readyState||!pt.is("img")?O():pt.one("load",O),!$&&Kt&&Kt>=7&&(a.src=a.src)},e.fn.imgAreaSelect=function(t){return t=t||{},this.each(function(){e(this).data("imgAreaSelect")?t.remove?(e(this).data("imgAreaSelect").remove(),e(this).removeData("imgAreaSelect")):e(this).data("imgAreaSelect").setOptions(t):t.remove||(void 0===t.enable&&void 0===t.disable&&(t.enable=!0),e(this).data("imgAreaSelect",new e.imgAreaSelect(this,t)))}),t.instance?e(this).data("imgAreaSelect"):this}})(jQuery);
\ No newline at end of file
