Test of dynamically changing images or removing and re-applying the cropper : Image Cropper « Page Components « JavaScript DHTML

JavaScript DHTML
1. Ajax Layer
2. Data Type
3. Date Time
4. Development
5. Document
6. Dojo toolkit
7. Event
8. Event onMethod
9. Ext JS
10. Form Control
11. GUI Components
12. HTML
13. Javascript Collections
14. Javascript Objects
15. Javascript Properties
16. jQuery
17. Language Basics
18. Mochkit
19. Mootools
20. Node Operation
21. Object Oriented
22. Page Components
23. Rico
24. Scriptaculous
25. Security
26. SmartClient
27. Style Layout
28. Table
29. Utilities
30. Window Browser
31. YUI Library
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
JavaScript DHTML » Page Components » Image Cropper 
Test of dynamically changing images or removing and re-applying the cropper


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



           
       
jsCropperUI-1.2.0.zip( 189 k)
Related examples in the same category
1. Static test for Image Cropper
2. Basic cropper test
3. Loading & displaying co-ordinates of crop area on attachment test
4. Loading & displaying co-ordinates (with ratio) of crop area on attachment test
5. CSS - Absolute positioned (and draggable) test
6. Test page with floating wrapper
7. Test page with relatively positioned wrapper
8. Test of applying different dimension restrictions to the cropper
9. Fixed ratio test
10. Minimum (both axes ) dimension test
11. Minimum (single axis) dimension test
12. Preview Cropped Image
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.