? fono.patch
Index: imagefield_crop.css
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/imagefield_crop/imagefield_crop.css,v
retrieving revision 1.1
diff -u -u -p -r1.1 imagefield_crop.css
--- imagefield_crop.css	13 Jan 2008 20:54:34 -0000	1.1
+++ imagefield_crop.css	9 Jul 2008 17:33:25 -0000
@@ -4,16 +4,16 @@ body{margin: 0;padding: 0;height: 100%;}
 
 
 .imagefield-crop-wrapper{height: 100%;background-color: #ccc;/*position:relative (FF bug?) */)}
-  #resizeMe{position: absolute;cursor: move;background-position: 0 0;background-repeat: no-repeat;border: 1px dashed black;}
-    #resizeSE,#resizeE,#resizeNE,#resizeN,#resizeNW,#resizeW,#resizeSW,#resizeS{position: absolute;width: 8px;height: 8px;background-color: #333;border: 1px solid #fff;overflow: hidden;}
-    #resizeSE{bottom: -10px;right: -10px;cursor: se-resize;}
-    #resizeE {top: 50%;right: -10px;margin-top: -5px;cursor: e-resize;}
-    #resizeNE{top: -10px;right: -10px;cursor: ne-resize;}
-    #resizeN {top: -10px;left: 50%;margin-left: -5px;cursor: n-resize;}
-    #resizeNW{top: -10px;left: -10px;cursor: nw-resize;}
-    #resizeW {top: 50%;left: -10px;margin-top: -5px;cursor: w-resize;}
-    #resizeSW{left: -10px;bottom: -10px;cursor: sw-resize;}
-    #resizeS{bottom: -10px;left: 50%;margin-left: -5px;cursor: s-resize;}
-  #image-crop-container{position: absolute;top: 50%;left: 50%;width: 320px;height: 240px;background-color: #ccc;background-repeat: no-repeat;opacity:.2;filter: alpha(opacity=20);-moz-opacity: 0.2;}
+  .resizeMe{position: absolute;cursor: move;background-position: 0 0;background-repeat: no-repeat;border: 1px dashed black;}
+    .resizeSE,.resizeE,.resizeNE,.resizeN,.resizeNW,.resizeW,.resizeSW,.resizeS{position: absolute;width: 8px;height: 8px;background-color: #333;border: 1px solid #fff;overflow: hidden;}
+    .resizeSE{bottom: -10px;right: -10px;cursor: se-resize;}
+    .resizeE {top: 50%;right: -10px;margin-top: -5px;cursor: e-resize;}
+    .resizeNE{top: -10px;right: -10px;cursor: ne-resize;}
+    .resizeN {top: -10px;left: 50%;margin-left: -5px;cursor: n-resize;}
+    .resizeNW{top: -10px;left: -10px;cursor: nw-resize;}
+    .resizeW {top: 50%;left: -10px;margin-top: -5px;cursor: w-resize;}
+    .resizeSW{left: -10px;bottom: -10px;cursor: sw-resize;}
+    .resizeS{bottom: -10px;left: 50%;margin-left: -5px;cursor: s-resize;}
+  .image-crop-container{position: absolute;top: 50%;left: 50%;width: 320px;height: 240px;background-color: #ccc;background-repeat: no-repeat;opacity:.2;filter: alpha(opacity=20);-moz-opacity: 0.2;}
   .imagefield-crop-preview{position:relative;background:url(images/img_bg.gif) repeat left top;margin:4px;border:1px solid #000;}
   .imagefield-crop-image-preview { border:1px solid #000 }
Index: imagefield_crop.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/imagefield_crop/imagefield_crop.js,v
retrieving revision 1.1.2.3
diff -u -u -p -r1.1.2.3 imagefield_crop.js
--- imagefield_crop.js	3 Apr 2008 13:48:28 -0000	1.1.2.3
+++ imagefield_crop.js	9 Jul 2008 17:33:26 -0000
@@ -1,24 +1,27 @@
 /* $Id: imagefield_crop.js,v 1.1.2.3 2008/04/03 13:48:28 yhager Exp $ */
-function imagefieldCropSetDimensions(x, y, w, h) {
-    $(".edit-image-crop-x").val(x);
-    $(".edit-image-crop-y").val(y);
-    if (w) $(".edit-image-crop-width").val(w);
-    if (h) $(".edit-image-crop-height").val(h);
+
+var cropIds = new Array();
+
+function imagefieldCropSetDimensions(cropId, x, y, w, h) {
+    $('#resizeMe_' + cropId).parents('#imagefield-edit-image-row').find(".edit-image-crop-x").val(x);
+    $('#resizeMe_' + cropId).parents('#imagefield-edit-image-row').find(".edit-image-crop-y").val(y);
+    if (w) $('#resizeMe_' + cropId).parents('#imagefield-edit-image-row').find(".edit-image-crop-width").val(w);
+    if (h) $('#resizeMe_' + cropId).parents('#imagefield-edit-image-row').find(".edit-image-crop-height").val(h);
 }
 
-function imagefieldCropInit() {
+function imagefieldCropInit(cropId) {
     var containerpos;
     var resizeT;
     var dragT;
     var changed = false;
-    if ($("#image-crop-container").size()) {
-        containerpos = findPos($("#image-crop-container").get(0));
+    if ($("#image-crop-container_" + cropId).size()) {
+        containerpos = findPos($("#image-crop-container_" + cropId, cropId).get(0));
     }
     else {
         containerpos = {x:0, y:0};
     }
 
-	function findPos(obj) {
+	function findPos(obj, cropId) {
 		var curleft = obj.offsetLeft || 0;
 		var curtop = obj.offsetTop || 0;
 		while (obj = obj.parent) {
@@ -28,18 +31,18 @@ function imagefieldCropInit() {
 		return {x:curleft,y:curtop};
 	}
 
-    $('#resizeMe').ready(function() {
+    $('#resizeMe_' + cropId).ready(function() {
         /* this is needed to set the box initially according to the form values */
-        var obj = $('#resizeMe').get(0);
+        var obj = $('#resizeMe_' + cropId).get(0);
         var newpos = {
-            left: parseInt($(".edit-image-crop-x").val()), 
-            top:  parseInt($(".edit-image-crop-y").val())
+            left: parseInt($('#resizeMe_' + cropId).parents('#imagefield-edit-image-row').find(".edit-image-crop-x").val()), 
+            top:  parseInt($('#resizeMe_' + cropId).parents('#imagefield-edit-image-row').find(".edit-image-crop-y").val())
         }
         var newsize = {
-            width:  parseInt($(".edit-image-crop-width").val()), 
-            height: parseInt($(".edit-image-crop-height").val())
+            width:  parseInt($('#resizeMe_' + cropId).parents('#imagefield-edit-image-row').find(".edit-image-crop-width").val()), 
+            height: parseInt($('#resizeMe_' + cropId).parents('#imagefield-edit-image-row').find(".edit-image-crop-height").val())
         }
-        if ($('#resizeMe').size()) {
+        if ($('#resizeMe_' + cropId).size()) {
 		    obj.style.backgroundPosition = (-1)*newpos.left + 'px ' + (-1)*newpos.top + 'px';
             obj.style.left = (newpos.left + containerpos.x) + 'px';
             obj.style.top  = (newpos.top  + containerpos.y) + 'px';
@@ -48,16 +51,16 @@ function imagefieldCropInit() {
         }
     });
 
-	$('#resizeMe').Resizable(
+	$('#resizeMe_' + cropId).Resizable(
 		{
 			minWidth: 20,
 			minHeight: 20,
-			maxWidth: 1 + $('#resizeMe').parents('.imagefield-crop-wrapper').width(),
-			maxHeight: 1 + $('#resizeMe').parents('.imagefield-crop-wrapper').height(),
+			maxWidth: 1 + $('#resizeMe_' + cropId).parents('.imagefield-crop-wrapper').width(),
+			maxHeight: 1 + $('#resizeMe_' + cropId).parents('.imagefield-crop-wrapper').height(),
 			minTop: 1,
 			minLeft: 1,
-            maxRight: $('#resizeMe').parents('.imagefield-crop-wrapper').width(),
-			maxBottom: $('#resizeMe').parents('.imagefield-crop-wrapper').height(),
+            maxRight: $('#resizeMe_' + cropId).parents('.imagefield-crop-wrapper').width(),
+			maxBottom: $('#resizeMe_' + cropId).parents('.imagefield-crop-wrapper').height(),
 			dragHandle: true,
             ratio: Drupal.imagefield_crop.ratio,
 			onDrag: function(x, y)
@@ -65,63 +68,75 @@ function imagefieldCropInit() {
                 clearTimeout(dragT);
                 if (!changed) {
                     changed = true;
-                    $(".edit-image-crop-changed").val(1);
+                    $('#resizeMe_' + cropId).parents('#imagefield-edit-image-row').find(".edit-image-crop-changed").val(1);
                 }
 				this.style.backgroundPosition = ((-1)*(x - containerpos.x)) + 'px ' + ((-1)*(y - containerpos.y)) + 'px';
                 xx = x-containerpos.x;
                 yy = y-containerpos.y;
-                dragT = setTimeout('imagefieldCropSetDimensions (xx, yy)', 200);
+                dragT = setTimeout('imagefieldCropSetDimensions (cropId, xx, yy)', 200);
 			},
 			handlers: {
-				se: '#resizeSE',
-				e: '#resizeE',
-				ne: '#resizeNE',
-				n: '#resizeN',
-				nw: '#resizeNW',
-				w: '#resizeW',
-				sw: '#resizeSW',
-				s: '#resizeS'
+				se: '#resizeSE_' + cropId,
+				e: '#resizeE_' + cropId,
+				ne: '#resizeNE_' + cropId,
+				n: '#resizeN_' + cropId,
+				nw: '#resizeNW_' + cropId,
+				w: '#resizeW_' + cropId,
+				sw: '#resizeSW_' + cropId,
+				s: '#resizeS_' + cropId
 			},
 			onResize : function(size, position) {
                 clearTimeout(resizeT);
                 if (!changed) {
                     changed = true;
-                    $(".edit-image-crop-changed").val(1);
+                    $('#resizeMe_' + cropId).parents('#imagefield-edit-image-row').find(".edit-image-crop-changed").val(1);
                 }
 				this.style.backgroundPosition = ((-1)*(position.left - containerpos.x)) + 'px ' + ((-1)*(position.top - containerpos.y)) + 'px';
                 x = position.left-containerpos.x;
                 y = position.top-containerpos.y;
                 w = size.width;
                 h = size.height;
-                resizeT = setTimeout('imagefieldCropSetDimensions (x, y, w, h)', 200);
+                resizeT = setTimeout('imagefieldCropSetDimensions (cropId, x, y, w, h)', 200);
 			}
 		}
 	);
 }
 
 var imageFieldCropInterval;
-function imageFieldCropGo() {
-    if ($("#image-crop-container").is(':visible')) {
+function imageFieldCropGo(cropId) {
+    if ($("#image-crop-container_" + cropId).is(':visible')) {
         clearInterval(imageFieldCropInterval);
-        imagefieldCropInit();
+        imagefieldCropInit(cropId);
     }
 }
 
-function imageFieldCropBind() {
+function imageFieldCropBind(cropId) {
     $('fieldset.collapsible > legend a').click(function(event) {
         var $target = $(event.target);
-        if ($target.parents('fieldset').find('#image-crop-container').length > 0) {
-            imageFieldCropInterval = setInterval('imageFieldCropGo()', 300);
+        if ($target.parents('fieldset').find('#image-crop-container_' + cropId).length > 0) {
+            imageFieldCropInterval = setInterval('imageFieldCropGo(cropId)', 300);
         }
     });
 }
 
 $(document).ready(function(){
-    imageFieldCropGo();
-    // We have to bind using a timeout, since the object is created after page load
-    // Do we need setInterval here instead?
-    setTimeout('imageFieldCropBind()', 200);
-});
 
+	divs = document.getElementsByTagName("div");
+	if (divs) {
+		for (var i = 0; i < divs.length; i++) {
+			if (divs[i].id.indexOf("image-crop-container") > -1) {
+				cropId = divs[i].id.substr(21);
+				cropIds[cropIds.length] = cropId;
+				 imageFieldCropGo(cropId);
+
+				 // We have to bind using a timeout, since the object is created after page load
+				 // Do we need setInterval here instead?
+				 setTimeout('imageFieldCropBind(cropId)', 200);
+
+			}
+		}
+	}
+
+});
 
 
Index: imagefield_crop.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/imagefield_crop/imagefield_crop.module,v
retrieving revision 1.1.2.11
diff -u -u -p -r1.1.2.11 imagefield_crop.module
--- imagefield_crop.module	3 Apr 2008 13:45:10 -0000	1.1.2.11
+++ imagefield_crop.module	9 Jul 2008 17:33:27 -0000
@@ -403,8 +403,11 @@ function _imagefield_crop_widget_form($n
       'height' => array('weight' => 8, 'default' => $h ? $h : 50),
       'changed' => array('weight' => 0, 'default' => 0),
     );
-    
+
+// ###
 //    drupal_set_message('node_field is <pre>'. print_r($node_field, TRUE)  .'</pre>');
+// ###
+
     foreach ($node_field as $delta => $file) {
       if ($file['filepath'] && !$file['flags']['delete']) {
         $form[$fieldname][$delta] = array(
@@ -469,7 +472,9 @@ function _imagefield_crop_widget_form($n
         );
 
 
-//      drupal_set_message('imagefield['. $fieldname .'] '. $op .' node field: <pre>'. print_r($node_field, true) .'</pre>');
+// ###
+//        drupal_set_message('imagefield['. $fieldname .'] '. $op .' node field: <pre>'. print_r($node_field, true) .'</pre>');
+// ###
 
         $form[$fieldname][$delta]['description'] = array(
           '#type' => 'markup',
@@ -661,6 +666,7 @@ function _imagefield_crop_scale_image($f
   return $file;
 }
 
+
 function theme_imagefield_crop_edit_crop_image_row($element) {
 
   list($cropw, $croph) = explode('x', $element['#croparea']);
@@ -668,7 +674,8 @@ function theme_imagefield_crop_edit_crop
   $output .= '<div class="imagefield-crop-preview" style="width:'. $cropw .'px; height:'. $croph .'px">';
   $output .= drupal_render($element['preview']) .'</div>';
   if ($element['crop']) {
-    $output .= '<div class="imagefield-edit-image-detail">';
+
+	 $output .= '<div class="imagefield-edit-image-detail" id="imagefield-edit-image-detail">';
     
     // REFACTOR: Don't 'flags' only if  multiple is unsupported
     $output .= '<div class="imagefield-edit-image-flags">'. drupal_render($element['flags']) .'</div>';
@@ -680,7 +687,7 @@ function theme_imagefield_crop_edit_crop
     $output .= drupal_render($element['title']);
     $output .= '</div>';
   }
-  $output = '<div class="imagefield-edit-image-row clear-block">'. $output .'</div>';
+  $output = '<div class="imagefield-edit-image-row clear-block" id="imagefield-edit-image-row">'. $output .'</div>';
   if (isset($element['replace'])) {
     $output .= '<div class="imagefield-edit-image-replace">'. drupal_render($element['replace']) .'</div>';
   }
@@ -690,33 +697,37 @@ function theme_imagefield_crop_edit_crop
 function theme_imagefield_crop_crop_image($file = NULL, $alt = '', $title = '', $attributes = NULL, $getsize = TRUE) {
   $output = '<div class="imagefield-crop-wrapper">';
 
+// ###
+//        drupal_set_message('theme_imagefield_crop_crop_image $file: <pre>'. print_r($file, true) .'</pre>');
+// ###
+
+
   if (!empty($file)) {
     $file = (array)$file;
     if (!$getsize || (is_file($file['filepath']) && (list($width, $height, $type, $image_attributes) = @getimagesize($file['filepath'])))) {
       //$attributes = drupal_attributes($attributes);
 
-      $path = $file['fid'] == 'upload' ? $file['preview'] : $file['filepath'];
       $alt = empty($alt) ? $file['alt'] : $alt;
       $title = empty($title) ? $file['title'] : $title;
       
-      $url = file_create_url($path);
+      $url = $file['fid'] == 'upload' ? url($file['preview']) : file_create_url($file['filepath']);
+		
+		$cropId = $file['fid'].'_'.str_replace("/", "", str_replace(".", "", $file['preview']));
 
       $output .= '
-<div id="image-crop-container"                                             
+<div id="image-crop-container_'.$cropId.'" class="image-crop-container"                                             
      style="background-image: url(\''. $url .'\'); width:'. $width  .'px; height:'. $height  .'px; margin-left:-'. $width/2  .'px; margin-top:-'. $height/2 .'px;">   
 </div>                                                          
                                                                 
-<div id="resizeMe"                                              
-     style="background-image: url(\''. $url .'\')">   
-	<div id="resizeSE"></div>                                   
-	<div id="resizeE"></div>                                    
-	<div id="resizeNE"></div>                                   
-	<div id="resizeN"></div>                                    
-	<div id="resizeNW"></div>                                   
-	<div id="resizeW"></div>                                    
-	<div id="resizeSW"></div>                                   
-	<div id="resizeS"></div>                                    
-
+<div id="resizeMe_'.$cropId.'" class="resizeMe" style="background-image: url(\''. $url .'\')">   
+	<div id="resizeSE_'.$cropId.'" class="resizeSE"></div>                                   
+	<div id="resizeE_'.$cropId.'" class="resizeE"></div>                                    
+	<div id="resizeNE_'.$cropId.'" class="resizeNE"></div>                                   
+	<div id="resizeN_'.$cropId.'" class="resizeN"></div>                                    
+	<div id="resizeNW_'.$cropId.'" class="resizeNW"></div>                                   
+	<div id="resizeW_'.$cropId.'" class="resizeW"></div>                                    
+	<div id="resizeSW_'.$cropId.'" class="resizeSW"></div>                                   
+	<div id="resizeS_'.$cropId.'" class="resizeS"></div>                                    
 </div>';
     }
   }
