/[drupal]/contributions/modules/imagecrop/imagecrop.js
ViewVC logotype

Contents of /contributions/modules/imagecrop/imagecrop.js

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Mon Mar 24 16:29:28 2008 UTC (20 months ago) by swentel
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-5, DRUPAL-6--1
File MIME type: text/javascript
Initial import of imagecrop. This module provides an extra imagecache action called javascript_crop and hooks into modules or fields to manipulate images with a javascript toolbox
1
2 /*
3 * Toolbox @copyright from imagefield_crop module with some minor modifications
4 */
5
6 function imageCropSetDimensions(x, y, w, h) {
7 $(".edit-image-crop-x").val(x);
8 $(".edit-image-crop-y").val(y);
9 if (w) $(".edit-image-crop-width").val(w);
10 if (h) $(".edit-image-crop-height").val(h);
11 }
12
13 $(document).ready(function(){
14 var containerpos;
15 var resizeT;
16 var dragT;
17 if ($("#image-crop-container").size()) {
18 containerpos = findPos($("#image-crop-container").get(0));
19 }
20 else {
21 containerpos = {x:0, y:0};
22 }
23 function findPos(obj) {
24 var curleft = obj.offsetLeft || 0;
25 var curtop = obj.offsetTop || 0;
26 while (obj = obj.parent) {
27 curleft += obj.offsetLeft
28 curtop += obj.offsetTop
29 }
30 return {x:curleft,y:curtop};
31 }
32
33 $('#resizeMe').ready(function() {
34 /* this is needed to set the box initially according to the form values */
35 var obj = $('#resizeMe').get(0);
36 var newpos = {
37 left: parseInt($(".edit-image-crop-x").val()),
38 top: parseInt($(".edit-image-crop-y").val())
39 }
40 var newsize = {
41 width: parseInt($(".edit-image-crop-width").val()),
42 height: parseInt($(".edit-image-crop-height").val())
43 }
44 if ($('#resizeMe').size()) {
45 obj.style.backgroundPosition = (-1)*newpos.left + 'px ' + (-1)*newpos.top + 'px';
46 obj.style.left = (newpos.left + containerpos.x) + 'px';
47 obj.style.top = (newpos.top + containerpos.y) + 'px';
48 obj.style.width = newsize.width + 'px';
49 obj.style.height = newsize.height + 'px';
50 }
51 });
52
53 $('#resizeMe').Resizable(
54 {
55 minWidth: 20,
56 minHeight: 20,
57 maxWidth: 1 + $('#resizeMe').parents('.imagefield-crop-wrapper').width(),
58 maxHeight: 1 + $('#resizeMe').parents('.imagefield-crop-wrapper').height(),
59 minTop: 1,
60 minLeft: 1,
61 maxRight: $('#resizeMe').parents('.imagefield-crop-wrapper').width(),
62 maxBottom: $('#resizeMe').parents('.imagefield-crop-wrapper').height(),
63 dragHandle: true,
64 onDrag: function(x, y)
65 {
66 clearTimeout(dragT);
67 this.style.backgroundPosition = ((-1)*(x - containerpos.x)) + 'px ' + ((-1)*(y - containerpos.y)) + 'px';
68 xx = x-containerpos.x;
69 yy = y-containerpos.y;
70 dragT = setTimeout('imageCropSetDimensions (xx, yy)', 200);
71 },
72 handlers: {
73 se: '#resizeSE',
74 e: '#resizeE',
75 ne: '#resizeNE',
76 n: '#resizeN',
77 nw: '#resizeNW',
78 w: '#resizeW',
79 sw: '#resizeSW',
80 s: '#resizeS'
81 },
82 onResize : function(size, position) {
83 clearTimeout(resizeT);
84 this.style.backgroundPosition = ((-1)*(position.left - containerpos.x)) + 'px ' + ((-1)*(position.top - containerpos.y)) + 'px';
85 x = position.left-containerpos.x;
86 y = position.top-containerpos.y;
87 w = size.width;
88 h = size.height;
89 resizeT = setTimeout('imageCropSetDimensions (x, y, w, h)', 200);
90 }
91 }
92 );
93 });
94

  ViewVC Help
Powered by ViewVC 1.1.2