+++ /dev/null
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\r
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\r
-<head>\r
- <meta http-equiv="Content-type" content="text/html; charset=utf-8" />\r
- <meta http-equiv="Content-Language" content="en-us" />\r
- <title>Dynamic image test</title>\r
- <script src="../lib/prototype.js" type="text/javascript"></script> \r
- <script src="../lib/scriptaculous.js?load=builder,dragdrop" type="text/javascript"></script>\r
- <script src="../cropper.js" type="text/javascript"></script>\r
- \r
- \r
- <script type="text/javascript" charset="utf-8">\r
- \r
- /**\r
- * A little manager that allows us to swap the image dynamically\r
- *\r
- */\r
- var CropImageManager = {\r
- /**\r
- * Holds the current Cropper.Img object\r
- * @var obj\r
- */\r
- curCrop: null,\r
- \r
- /**\r
- * Initialises the cropImageManager\r
- *\r
- * @access public\r
- * @return void\r
- */\r
- init: function() {\r
- this.attachCropper();\r
- },\r
- \r
- /**\r
- * Handles the changing of the select to change the image, the option value\r
- * is a pipe seperated list of imgSrc|width|height\r
- * \r
- * @access public\r
- * @param obj event\r
- * @return void\r
- */\r
- onChange: function( e ) {\r
- var vals = $F( Event.element( e ) ).split('|');\r
- this.setImage( vals[0], vals[1], vals[2] ); \r
- },\r
- \r
- /**\r
- * Sets the image within the element & attaches/resets the image cropper\r
- *\r
- * @access private\r
- * @param string Source path of new image\r
- * @param int Width of new image in pixels\r
- * @param int Height of new image in pixels\r
- * @return void\r
- */\r
- setImage: function( imgSrc, w, h ) {\r
- $PR( 'testImage' ).src = imgSrc;\r
- $PR( 'testImage' ).width = w;\r
- $PR( 'testImage' ).height = h;\r
- this.attachCropper();\r
- },\r
- \r
- /** \r
- * Attaches/resets the image cropper\r
- *\r
- * @access private\r
- * @return void\r
- */\r
- attachCropper: function() {\r
- if( this.curCrop == null ) this.curCrop = new Cropper.Img( 'testImage', { onEndCrop: onEndCrop } );\r
- else this.curCrop.reset();\r
- },\r
- \r
- /**\r
- * Removes the cropper\r
- *\r
- * @access public\r
- * @return void\r
- */\r
- removeCropper: function() {\r
- if( this.curCrop != null ) {\r
- this.curCrop.remove();\r
- }\r
- },\r
- \r
- /**\r
- * Resets the cropper, either re-setting or re-applying\r
- *\r
- * @access public\r
- * @return void\r
- */\r
- resetCropper: function() {\r
- this.attachCropper();\r
- }\r
- };\r
- \r
- \r
- // setup the callback function\r
- function onEndCrop( coords, dimensions ) {\r
- $PR( 'x1' ).value = coords.x1;\r
- $PR( 'y1' ).value = coords.y1;\r
- $PR( 'x2' ).value = coords.x2;\r
- $PR( 'y2' ).value = coords.y2;\r
- $PR( 'width' ).value = dimensions.width;\r
- $PR( 'height' ).value = dimensions.height;\r
- }\r
- \r
- // basic example\r
- Event.observe( \r
- window, \r
- 'load', \r
- function() { \r
- CropImageManager.init();\r
- Event.observe( $PR('removeCropper'), 'click', CropImageManager.removeCropper.bindAsEventListener( CropImageManager ), false );\r
- Event.observe( $PR('resetCropper'), 'click', CropImageManager.resetCropper.bindAsEventListener( CropImageManager ), false );\r
- Event.observe( $PR('imageChoice'), 'change', CropImageManager.onChange.bindAsEventListener( CropImageManager ), false );\r
- }\r
- ); \r
- \r
- \r
- /*\r
- if( typeof(dump) != 'function' ) {\r
- Debug.init(true, '/');\r
- \r
- function dump( msg ) {\r
- Debug.raise( msg );\r
- };\r
- } else dump( '---------------------------------------\n' );\r
- */\r
- \r
- </script>\r
- <link rel="stylesheet" type="text/css" href="debug.css" media="all" />\r
- <style type="text/css">\r
- label { \r
- clear: left;\r
- margin-left: 50px;\r
- float: left;\r
- width: 5em;\r
- }\r
- \r
- html, body { \r
- margin: 0;\r
- }\r
- \r
- #testWrap {\r
- margin: 20px 0 0 50px; /* Just while testing, to make sure we return the correct positions for the image & not the window */\r
- }\r
- </style>\r
-</head>\r
-<body>\r
- <h2>Dynamic image test</h2>\r
- <p>\r
- Test of dynamically changing images or removing & re-applying the cropper\r
- </p>\r
- \r
- <div id="testWrap">\r
- <img src="castle.jpg" alt="test image" id="testImage" width="500" height="333" />\r
- </div>\r
- \r
- <p>\r
- <label for="imageChoice">image:</label>\r
- <select name="imageChoice" id="imageChoice">\r
- <option value="castle.jpg|500|333">Castle</option>\r
- <option value="poppy.jpg|311|466">Flower</option>\r
- </select>\r
- </p>\r
- \r
- <p>\r
- <input type="button" id="removeCropper" value="Remove Cropper" />\r
- <input type="button" id="resetCropper" value="Reset Cropper" />\r
- </p>\r
- \r
- \r
- <p>\r
- <label for="x1">x1:</label>\r
- <input type="text" name="x1" id="x1" />\r
- </p>\r
- <p>\r
- <label for="y1">y1:</label>\r
- <input type="text" name="y1" id="y1" />\r
- </p>\r
- <p>\r
- <label for="x2">x2:</label>\r
- <input type="text" name="x2" id="x2" />\r
- </p>\r
- <p>\r
- <label for="y2">y2:</label>\r
- <input type="text" name="y2" id="y2" />\r
- </p>\r
- <p>\r
- <label for="width">width:</label>\r
- <input type="text" name="width" id="width" />\r
- </p>\r
- <p>\r
- <label for="height">height</label>\r
- <input type="text" name="height" id="height" />\r
- </p> \r
- \r
-</body>\r
-</html>\r
-\r
-\r