?? cropper.uncompressed.js
字號:
/**
* Image Cropper (v. 1.2.0 - 2006-10-30 )
* Copyright (c) 2006 David Spurr (http://www.defusion.org.uk/)
*
* The image cropper provides a way to draw a crop area on an image and capture
* the coordinates of the drawn crop area.
*
* Features include:
* - Based on Prototype and Scriptaculous
* - Image editing package styling, the crop area functions and looks
* like those found in popular image editing software
* - Dynamic inclusion of required styles
* - Drag to draw areas
* - Shift drag to draw/resize areas as squares
* - Selection area can be moved
* - Seleciton area can be resized using resize handles
* - Allows dimension ratio limited crop areas
* - Allows minimum dimension crop areas
* - Allows maximum dimesion crop areas
* - If both min & max dimension options set to the same value for a single axis,then the cropper will not
* display the resize handles as appropriate (when min & max dimensions are passed for both axes this
* results in a 'fixed size' crop area)
* - Allows dynamic preview of resultant crop ( if minimum width & height are provided ), this is
* implemented as a subclass so can be excluded when not required
* - Movement of selection area by arrow keys ( shift + arrow key will move selection area by
* 10 pixels )
* - All operations stay within bounds of image
* - All functionality & display compatible with most popular browsers supported by Prototype:
* PC: IE 7, 6 & 5.5, Firefox 1.5, Opera 8.5 (see known issues) & 9.0b
* MAC: Camino 1.0, Firefox 1.5, Safari 2.0
*
* Requires:
* - Prototype v. 1.5.0_rc0 > (as packaged with Scriptaculous 1.6.1)
* - Scriptaculous v. 1.6.1 > modules: builder, dragdrop
*
* Known issues:
* - Safari animated gifs, only one of each will animate, this seems to be a known Safari issue
*
* - After drawing an area and then clicking to start a new drag in IE 5.5 the rendered height
* appears as the last height until the user drags, this appears to be the related to the error
* that the forceReRender() method fixes for IE 6, i.e. IE 5.5 is not redrawing the box properly.
*
* - Lack of CSS opacity support in Opera before version 9 mean we disable those style rules, these
* could be fixed by using PNGs with transparency if Opera 8.5 support is high priority for you
*
* - Marching ants keep reloading in IE <6 (not tested in IE7), it is a known issue in IE and I have
* found no viable workarounds that can be included in the release. If this really is an issue for you
* either try this post: http://mir.aculo.us/articles/2005/08/28/internet-explorer-and-ajax-image-caching-woes
* or uncomment the 'FIX MARCHING ANTS IN IE' rules in the CSS file
*
* - Styling & borders on image, any CSS styling applied directly to the image itself (floats, borders, padding, margin, etc.) will
* cause problems with the cropper. The use of a wrapper element to apply these styles to is recommended.
*
* - overflow: auto or overflow: scroll on parent will cause cropper to burst out of parent in IE and Opera (maybe Mac browsers too)
* I'm not sure why yet.
*
* Usage:
* See Cropper.Img & Cropper.ImgWithPreview for usage details
*
* Changelog:
* v1.2.0 - 2006-10-30
* + Added id to the preview image element using 'imgCrop_[originalImageID]'
* * #00001 - Fixed bug: Doesn't account for scroll offsets
* * #00009 - Fixed bug: Placing the cropper inside differently positioned elements causes incorrect co-ordinates and display
* * #00013 - Fixed bug: I-bar cursor appears on drag plane
* * #00014 - Fixed bug: If ID for image tag is not found in document script throws error
* * Fixed bug with drag start co-ordinates if wrapper element has moved in browser (e.g. dragged to a new position)
* * Fixed bug with drag start co-ordinates if image contained in a wrapper with scrolling - this may be buggy if image
* has other ancestors with scrolling applied (except the body)
* * #00015 - Fixed bug: When cropper removed and then reapplied onEndCrop callback gets called multiple times, solution suggestion from Bill Smith
* * Various speed increases & code cleanup which meant improved performance in Mac - which allowed removal of different overlay methods for
* IE and all other browsers, which led to a fix for:
* * #00010 - Fixed bug: Select area doesn't adhere to image size when image resized using img attributes
* - #00006 - Removed default behaviour of automatically setting a ratio when both min width & height passed, the ratioDimensions must be passed in
* + #00005 - Added ability to set maximum crop dimensions, if both min & max set as the same value then we'll get a fixed cropper size on the axes as appropriate
* and the resize handles will not be displayed as appropriate
* * Switched keydown for keypress for moving select area with cursor keys (makes for nicer action) - doesn't appear to work in Safari
*
* v1.1.3 - 2006-08-21
* * Fixed wrong cursor on western handle in CSS
* + #00008 & #00003 - Added feature: Allow to set dimensions & position for cropper on load
* * #00002 - Fixed bug: Pressing 'remove cropper' twice removes image in IE
*
* v1.1.2 - 2006-06-09
* * Fixed bugs with ratios when GCD is low (patch submitted by Andy Skelton)
*
* v1.1.1 - 2006-06-03
* * Fixed bug with rendering issues fix in IE 5.5
* * Fixed bug with endCrop callback issues once cropper had been removed & reset in IE
*
* v1.1.0 - 2006-06-02
* * Fixed bug with IE constantly trying to reload select area background image
* * Applied more robust fix to Safari & IE rendering issues
* + Added method to reset parameters - useful for when dynamically changing img cropper attached to
* + Added method to remove cropper from image
*
* v1.0.0 - 2006-05-18
* + Initial verison
*
*
* Copyright (c) 2006, David Spurr (http://www.defusion.org.uk/)
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* * Neither the name of the David Spurr nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* http://www.opensource.org/licenses/bsd-license.php
*
* See scriptaculous.js for full scriptaculous licence
*/
/**
* Extend the Draggable class to allow us to pass the rendering
* down to the Cropper object.
*/
var CropDraggable = Class.create();
Object.extend( Object.extend( CropDraggable.prototype, Draggable.prototype), {
initialize: function(element) {
this.options = Object.extend(
{
/**
* The draw method to defer drawing to
*/
drawMethod: function() {}
},
arguments[1] || {}
);
this.element = $(element);
this.handle = this.element;
this.delta = this.currentDelta();
this.dragging = false;
this.eventMouseDown = this.initDrag.bindAsEventListener(this);
Event.observe(this.handle, "mousedown", this.eventMouseDown);
Draggables.register(this);
},
/**
* Defers the drawing of the draggable to the supplied method
*/
draw: function(point) {
var pos = Position.cumulativeOffset(this.element);
var d = this.currentDelta();
pos[0] -= d[0];
pos[1] -= d[1];
var p = [0,1].map(function(i) {
return (point[i]-pos[i]-this.offset[i])
}.bind(this));
this.options.drawMethod( p );
}
});
/**
* The Cropper object, this will attach itself to the provided image by wrapping it with
* the generated xHTML structure required by the cropper.
*
* Usage:
* @param obj Image element to attach to
* @param obj Optional options:
* - ratioDim obj
* The pixel dimensions to apply as a restrictive ratio, with properties x & y
*
* - minWidth int
* The minimum width for the select area in pixels
*
* - minHeight int
* The mimimum height for the select area in pixels
*
* - maxWidth int
* The maximum width for the select areas in pixels (if both minWidth & maxWidth set to same the width of the cropper will be fixed)
*
* - maxHeight int
* The maximum height for the select areas in pixels (if both minHeight & maxHeight set to same the height of the cropper will be fixed)
*
* - displayOnInit int
* Whether to display the select area on initialisation, only used when providing minimum width & height or ratio
*
* - onEndCrop func
* The callback function to provide the crop details to on end of a crop (see below)
*
* - captureKeys boolean
* Whether to capture the keys for moving the select area, as these can cause some problems at the moment
*
* - onloadCoords obj
* A coordinates object with properties x1, y1, x2 & y2; for the coordinates of the select area to display onload
*
*----------------------------------------------
*
* The callback function provided via the onEndCrop option should accept the following parameters:
* - coords obj
* The coordinates object with properties x1, y1, x2 & y2; for the coordinates of the select area
*
* - dimensions obj
* The dimensions object with properites width & height; for the dimensions of the select area
*
*
* Example:
* function onEndCrop( coords, dimensions ) {
* $( 'x1' ).value = coords.x1;
* $( 'y1' ).value = coords.y1;
* $( 'x2' ).value = coords.x2;
* $( 'y2' ).value = coords.y2;
* $( 'width' ).value = dimensions.width;
* $( 'height' ).value = dimensions.height;
* }
*
*/
var Cropper = {};
Cropper.Img = Class.create();
Cropper.Img.prototype = {
/**
* Initialises the class
*
* @access public
* @param obj Image element to attach to
* @param obj Options
* @return void
*/
initialize: function(element, options) {
this.options = Object.extend(
{
/**
* @var obj
* The pixel dimensions to apply as a restrictive ratio
*/
ratioDim: { x: 0, y: 0 },
/**
* @var int
* The minimum pixel width, also used as restrictive ratio if min height passed too
*/
minWidth: 0,
/**
* @var int
* The minimum pixel height, also used as restrictive ratio if min width passed too
*/
minHeight: 0,
/**
* @var boolean
* Whether to display the select area on initialisation, only used when providing minimum width & height or ratio
*/
displayOnInit: false,
/**
* @var function
* The call back function to pass the final values to
*/
onEndCrop: Prototype.emptyFunction,
/**
* @var boolean
* Whether to capture key presses or not
*/
captureKeys: true,
/**
* @var obj Coordinate object x1, y1, x2, y2
* The coordinates to optionally display the select area at onload
*/
onloadCoords: null,
/**
* @var int
* The maximum width for the select areas in pixels (if both minWidth & maxWidth set to same the width of the cropper will be fixed)
*/
maxWidth: 0,
/**
* @var int
* The maximum height for the select areas in pixels (if both minHeight & maxHeight set to same the height of the cropper will be fixed)
*/
maxHeight: 0
},
options || {}
);
/**
* @var obj
* The img node to attach to
*/
this.img = $( element );
/**
* @var obj
* The x & y coordinates of the click point
*/
this.clickCoords = { x: 0, y: 0 };
/**
* @var boolean
* Whether the user is dragging
*/
this.dragging = false;
/**
* @var boolean
* Whether the user is resizing
*/
this.resizing = false;
/**
* @var boolean
* Whether the user is on a webKit browser
*/
this.isWebKit = /Konqueror|Safari|KHTML/.test( navigator.userAgent );
/**
* @var boolean
* Whether the user is on IE
*/
this.isIE = /MSIE/.test( navigator.userAgent );
/**
* @var boolean
* Whether the user is on Opera below version 9
*/
this.isOpera8 = /Opera\s[1-8]/.test( navigator.userAgent );
/**
* @var int
* The x ratio
*/
this.ratioX = 0;
/**
* @var int
* The y ratio
*/
this.ratioY = 0;
/**
* @var boolean
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -