1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4 <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
5 <meta http-equiv="Content-Language" content="en-us" />
6 <title>Different dimensions test</title>
7 <script src="../lib/prototype.js" type="text/javascript"></script>
8 <script src="../lib/scriptaculous.js?load=builder,dragdrop" type="text/javascript"></script>
9 <script src="../cropper.js" type="text/javascript"></script>
12 <script type="text/javascript" charset="utf-8">
14 function onEndCrop( coords, dimensions ) {
15 $PR( 'x1' ).value = coords.x1;
16 $PR( 'y1' ).value = coords.y1;
17 $PR( 'x2' ).value = coords.x2;
18 $PR( 'y2' ).value = coords.y2;
19 $PR( 'width' ).value = dimensions.width;
20 $PR( 'height' ).value = dimensions.height;
25 // example with minimum dimensions
45 Event.observe( window, 'load',
47 Event.observe( 'dimensionsForm', 'submit', CropManager.attachCropper.bindAsEventListener( CropManager ) );
48 CropManager.attachCropper();
53 * A little manager that allows us to reset the options dynamically
57 * Holds the current Cropper.Img object
63 * Gets a min/max parameter from the form
66 * @param string Form element ID
69 getParam: function( name ) {
71 console.log( name + ' :: ' + val );
72 return parseInt( val );
76 * Attaches/resets the image cropper
79 * @param obj Event object
82 attachCropper: function( e ) {
83 if( this.curCrop == null ) {
84 this.curCrop = new Cropper.Img(
87 minWidth: this.getParam( 'minWidth' ),
88 minHeight: this.getParam( 'minHeight' ),
89 maxWidth: this.getParam( 'maxWidth' ),
90 maxHeight: this.getParam( 'maxHeight' ),
96 this.curCrop.initialize(
99 minWidth: this.getParam( 'minWidth' ),
100 minHeight: this.getParam( 'minHeight' ),
101 maxWidth: this.getParam( 'maxWidth' ),
102 maxHeight: this.getParam( 'maxHeight' ),
107 if( e != null ) Event.stop( e );
111 * Removes the cropper
116 removeCropper: function() {
117 if( this.curCrop != null ) {
118 this.curCrop.remove();
123 * Resets the cropper, either re-setting or re-applying
128 resetCropper: function() {
129 this.attachCropper();
134 if( typeof(dump) != 'function' ) {
135 Debug.init(true, '/');
137 function dump( msg ) {
138 // Debug.raise( msg );
140 } else dump( '---------------------------------------\n' );
144 <link rel="stylesheet" type="text/css" href="debug.css" media="all" />
145 <style type="text/css">
154 margin: 20px 0 0 50px; /* Just while testing, to make sure we return the correct positions for the image & not the window */
164 <h2>Multiple dimensions tests</h2>
166 Test of applying different dimension restrictions to the cropper
169 <form action="#" id="dimensionsForm">
171 Set the cropper with the following dimension restrictions:
173 <label for="minWidth">Min Width</label>
174 <input type="text" size="10" maxlength="3" value="200" id="minWidth" name="minWidth" />
177 <label for="maxWidth">Max Width</label>
178 <input type="text" size="10" maxlength="3" value="200" id="maxWidth" name="maxWidth" />
181 <label for="minHeight">Min Height</label>
182 <input type="text" size="10" maxlength="3" value="120" id="minHeight" name="minHeight" />
185 <label for="maxHeight">Max Height</label>
186 <input type="text" size="10" maxlength="3" value="120" id="maxHeight" name="maxHeight" />
188 <input type="submit" value="Set Cropper" />
193 <img src="castle.jpg" alt="test image" id="testImage" width="500" height="333" />
198 <label for="x1">x1:</label>
199 <input type="text" name="x1" id="x1" />
202 <label for="y1">y1:</label>
203 <input type="text" name="y1" id="y1" />
206 <label for="x2">x2:</label>
207 <input type="text" name="x2" id="x2" />
210 <label for="y2">y2:</label>
211 <input type="text" name="y2" id="y2" />
214 <label for="width">width:</label>
215 <input type="text" name="width" id="width" />
218 <label for="height">height</label>
219 <input type="text" name="height" id="height" />