Skip to content

Instantly share code, notes, and snippets.

@thewilkybarkid
Last active December 21, 2015 03:19
Show Gist options
  • Save thewilkybarkid/6241365 to your computer and use it in GitHub Desktop.
Save thewilkybarkid/6241365 to your computer and use it in GitHub Desktop.
Patch for the Drupal Image javascript crop module that fixes images problems introduced in Drupal 7.20. This follows the changes in https://drupal.org/node/1924078, but is applied to version 7.x-1.0-rc3 rather than 7.x-1.x-dev
diff --git a/includes/imagecrop.admin.inc b/includes/imagecrop.admin.inc
index ae3d663..ac04f15 100644
--- a/includes/imagecrop.admin.inc
+++ b/includes/imagecrop.admin.inc
@@ -153,7 +153,7 @@ function imagecrop_image_styles_overview($fid, $style_name, $entity_type = NULL,
$imagecrop->addImagecropUi(TRUE);
$image_url = image_style_url($style_name, $imagecrop->getFile()->uri);
- $image_url .= (variable_get('clean_url', 0) ? '?' : '&');
+ $image_url .= (!variable_get('clean_url', 0) || strpos($image_url, '?') !== FALSE) ? '&' : '?';
$image_url .= 'time=' . $_SERVER['REQUEST_TIME'];
return theme('imagecrop_overview', array(
diff --git a/includes/imagecrop.class.inc b/includes/imagecrop.class.inc
index 0af9a60..714daca 100644
--- a/includes/imagecrop.class.inc
+++ b/includes/imagecrop.class.inc
@@ -299,7 +299,8 @@ class ImageCrop {
*/
public function getCropDestination($filepath = TRUE) {
$image_url = ($filepath) ? file_create_url($this->cropDestination) : $this->cropDestination;
- $image_url .= '?time=' . $_SERVER['REQUEST_TIME'];
+ $image_url .= (strpos($image_url, '?') !== FALSE) ? '&' : '?';
+ $image_url .= 'time=' . $_SERVER['REQUEST_TIME'];
return $image_url;
}
diff --git a/js/imagecrop.js b/js/imagecrop.js
index 6d457e6..e752560 100644
--- a/js/imagecrop.js
+++ b/js/imagecrop.js
@@ -26,7 +26,8 @@ Drupal.Imagecrop.changeViewedImage = function(style_name) {
*/
Drupal.Imagecrop.refreshImage = function() {
var source = $(this).attr('src');
- $(this).attr('src', (source + '?time=' + new Date().getTime()));
+ var delimiter = source.indexOf('?') === -1 ? '?' : '&';
+ $(this).attr('src', (source + delimiter + 'time=' + new Date().getTime()));
}
})(jQuery);
\ No newline at end of file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment