aboutsummaryrefslogtreecommitdiffstats
path: root/library/cropper/tests/example-Dimensions.htm
blob: f54f99683939e757b5a35280c517b45d969df5c6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
<!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>Different dimensions test</title>
	<script src="../lib/prototype.js" type="text/javascript"></script>	
 	<script src="../lib/scriptaculous.js?load=builder,dragdrop" type="text/javascript"></script>
	<script src="../cropper.js" type="text/javascript"></script>
	
	
	<script type="text/javascript" charset="utf-8">
		
		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;
		}
		
		/*
		
		// example with minimum dimensions
		Event.observe( 
			window, 
			'load', 
			function() { 
				new Cropper.Img( 
					'testImage', 
					{ 
						minWidth: 200, 
						minHeight: 120,
						maxWidth: 200,
						//maxHeight: 120,
						displayOnInit: true, 
						onEndCrop: onEndCrop 
					} 
				) 
			} 
		);
		*/
		
		Event.observe( window, 'load',
			function() {
				Event.observe( 'dimensionsForm', 'submit', CropManager.attachCropper.bindAsEventListener( CropManager ) );
				CropManager.attachCropper();
			}
		);
		
		/**
		 * A little manager that allows us to reset the options dynamically
		 */
		var CropManager = {
			/**
			 * Holds the current Cropper.Img object
			 * @var obj
			 */
			curCrop: null,
			
			/**
			 * Gets a min/max parameter from the form 
			 * 
			 * @access private
			 * @param string Form element ID
			 * @return int
			 */
			getParam: function( name ) {
				var val = $F( name );
				console.log( name + ' :: ' + val );
				return parseInt( val );
			},
									
			/** 
			 * Attaches/resets the image cropper
			 *
			 * @access private
			 * @param obj Event object
			 * @return void
			 */
			attachCropper: function( e ) {
				if( this.curCrop == null ) {
					this.curCrop = new Cropper.Img( 
						'testImage', 
						{ 
							minWidth: this.getParam( 'minWidth' ),
							minHeight: this.getParam( 'minHeight' ),
							maxWidth: this.getParam( 'maxWidth' ),
							maxHeight: this.getParam( 'maxHeight' ),
							onEndCrop: onEndCrop 
						} 
					);
				} else {
					this.removeCropper();
					this.curCrop.initialize( 
						'testImage', 
						{ 
							minWidth: this.getParam( 'minWidth' ),
							minHeight: this.getParam( 'minHeight' ),
							maxWidth: this.getParam( 'maxWidth' ),
							maxHeight: this.getParam( 'maxHeight' ),
							onEndCrop: onEndCrop 
						} 
					);
				}
				if( e != null ) Event.stop( e );
			},
			
			/**
			 * Removes the cropper
			 *
			 * @access public
			 * @return void
			 */
			removeCropper: function() {
				if( this.curCrop != null ) {
					this.curCrop.remove();
				}
			},
			
			/**
			 * Resets the cropper, either re-setting or re-applying
			 *
			 * @access public
			 * @return void
			 */
			resetCropper: function() {
				this.attachCropper();
			}
		};		
		
		/*
		if( typeof(dump) != 'function' ) {
			Debug.init(true, '/');
			
			function dump( msg ) {
				// Debug.raise( msg );
			};
		} else dump( '---------------------------------------\n' );
		*/
		
	</script>
	<link rel="stylesheet" type="text/css" href="debug.css" media="all" />
	<style type="text/css">
		label { 
			clear: left;
			margin-left: 50px;
			float: left;
			width: 5em;
		}
		
		#testWrap {
			margin: 20px 0 0 50px; /* Just while testing, to make sure we return the correct positions for the image & not the window */
		}
		
		#dimensionsForm {
			float: right;
			width: 350px;
		}
	</style>
</head>
<body>	
	<h2>Multiple dimensions tests</h2>
	<p>
		Test of applying different dimension restrictions to the cropper
	</p>
	
	<form action="#" id="dimensionsForm">
		<fieldset>
			Set the cropper with the following dimension restrictions:
			<p>
				<label for="minWidth">Min Width</label>
				<input type="text" size="10" maxlength="3" value="200" id="minWidth" name="minWidth" />
			</p>	
			<p>
				<label for="maxWidth">Max Width</label>
				<input type="text" size="10" maxlength="3" value="200" id="maxWidth" name="maxWidth" />
			</p>	
			<p>
				<label for="minHeight">Min Height</label>
				<input type="text" size="10" maxlength="3" value="120" id="minHeight" name="minHeight" />
			</p>	
			<p>
				<label for="maxHeight">Max Height</label>
				<input type="text" size="10" maxlength="3" value="120" id="maxHeight" name="maxHeight" />
			</p>	
			<input type="submit" value="Set Cropper" />
		</fieldset>
	</form>
	
	<div id="testWrap">
		<img src="castle.jpg" alt="test image" id="testImage" width="500" height="333" />
	</div>
	
	
	<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>