It seems collapsed fieldgroups prevent imagefield_crop to work properly.
Here are some simple steps to reproduce the issue :
- Create an imagefield_crop field inside CCK fieldgroup with the option 'collapsed by default'.
- Create a node, unfold the fieldgroup, upload an image and crop successfully, save the node.
- Edit the node you just created, unfold the fieldgroup. The crop area is not properly initialized, you can't actually see it.
- If you save your node again, the final crop might change as the cropping behavior is active but invisible.
Others have mentioned that updating the core JCore library solves the problem.
Comments
Comment #1
v.vanhala commentedI'm having the same issue.
On step 3 while editing the node the crop initializes properly if the field is unfolded before the image is fully loaded. If I wait for the image to load first and then unfold the crop is broken.
So crop only works if the image is visible (unfolded) while the load finishes.
Comment #2
Exploratus commentedSame here. Can't collapse a field with imagecrop -- the image crop window dissapears..
Comment #3
robby.smith commentedsubscribing
Comment #4
carsten müller commentedsubscribing
Comment #5
bleen commentedI believe the same problem is occurring if you use vertical tabs. In this case, the fieldgroup doesn't even need to be collapsible. It seems that the crop area mechanism somehow relies on the image being visible at the time it initializes. Hmmm...
Comment #6
yhager commented@bleen18, you are correct. I haven't found a way around this yet. If you are capable, or no someone who is, I will appreciate any help on this.
Comment #7
bleen commentedSo here is the issue ... when an image (or any html element) is hidden js *always* returns both its width & height as 0. That means that in the case when an imagefield_crop widget is in a collapsed fieldset or a non-active vertical tab all the Jcrop functionality thinks that the cropbox image is 0x0. FAIL.
So we have a few a options:
This patch does the latter. Note that the "rehiding" part is not at all elegant as it requires a setTimeout to give Jcrop time to finish attaching all the behaviors. This is VERY ugly, but I dont see how else to make this work.
(patched against RC2)
Comment #8
yhager commentedThanks for this patch. I am not sure the "better than nothing" is good here, so let's see what are our options.
I haven't found a way to attach to an event that fires when the image is shown (regardless of how). Is there anything of this kind?
As for option #1 - why would it complicate things? the patch does not solve the vertical tabs case (as far as I understand from reading the code. Correct me if I am wrong). Would you mind give a go to this option? you just need to find the enclosing fieldset (like in the current patch), and attach to the click event. I am not sure how to ensure not to conflict with the Drupal built in collapse handling though...
What do you say?
Comment #9
bleen commentedThe patch in #7 does work with v-tabs because vtabs uses fieldsets too ... but I agree that its not an ideal solution.
As for attaching the Jcrop behaviors on a click event attached to the fieldsets... this has a few complications:
These are just the ones off the top of my head... I'm not sure how I would even do the first one. The second and third are doable, but UGLY.
Thoughts?
Comment #10
jglynn commentedsubscribing
Comment #11
leon85321 commentedHello,
Thanks for the patch, #7 works ok with vertical tab modules.
However it is confusing clients that the cropped area is reset to the upper left corner and the cropped preview is also showing only the upper left corner cropped area which confuses the client to think that they need to do the crop again.
Comment #12
bleen commented@leon85321: can you post a screen shot of what your are talking about ... I'm not following
Comment #13
nicholasthompsonThe patch in #7 doesn't seem to help me.
I simply get the Crop Area set to 0x0 with both handles on top of each other. I've tried with/without the patch and with/without JQuery Update (2.x).
Comment #14
bleen commentednicholasThompson:
any chance I can get a look at the site you're testing on? I'm often on IRC (bleen) ... ping me if thats possible.
Comment #15
plan9 commentedI have the same problem with 5.x-1.3 version as described in #13: 'Crop Area set to 0x0 with both handles on top of each other'. I'm also using hidden fieldsets in tabs.
Comment #16
leon85321 commented@bleen18 -
Sure and here are the screenshots.
The 1st attachment is the node view after first uploaded it and cropped.
The 2nd attachment is in the edit view after the file was cropped and went to edit form.
You can see that the selected area is now to the top left corner. However as long as I do not touch that cropping area, the actual cropped image in the node view will not change after saving the editing form.
Thanks,
Leon
Comment #17
gg4 commentedsubbing
Comment #18
daniula commentedDoes anyone tried changing CSS for elements included in fieldset.collapsed?
I included this css and it fixed the problem:
I have to change line 25 in imagefiled_crop.js from:
to:
because of additional div.fieldset-wrapper added by collapsible.js, too.
Does this solution works for someone else?
Comment #19
betoaveigaNot for me :(
Comment #20
bleen commented#18 does not work for me either ... daniula, what browser are you using?
Comment #21
betoaveigaHi! I was playing with JQUERY and I made something that fixes the problem... at least for me...
I used some of the JQUERY code in this page: http://remysharp.com/2008/10/17/jquery-really-visible/
I made modifications ONLY at the beginning of imagefield_crop.js
Basically, it starts all javascript stuff only when the crop wrapper is really visible... and that fixes the problem.
BTW, this fix is based on comment 7 option 1, from Bleen18.
If this works then maybe someone can make a patch...
Hope that helps...
Comment #22
vood002 commentedThe fix in #21 solved the problem for me. Sorry, have yet to make a patch...
to clear up for anyone, edit imagefield_crop.js,
comment out line 6 like so:
Then add the following right below
Comment #23
Anonymous (not verified) commented@22: not quite. Now the Crop Area JS indeed works, however the original image is lost. I mean, you can't re-work your original cropping, because the source image is now the cropped image...
After re-saving the node, imagecache has nothing left to work with: a blank image (no image).
Just try it yourself, you'll see.
Comment #24
jdidelet commented+1
Comment #25
gekido commentedYour solution worked perfect for me - awesome!
Thanx
Comment #26
quadbyte commented#22 is working fine for me.
Attached a patch for review.
Comment #27
DaPooch commentedLooks close, seems to work okay for single image fields, but it's not working right if you allow for multiple image uploads via the "unlimited"- add another item setup. If it allows for multiple uploads I just get a blank space where the preview and cropper should be.
Comment #28
webadpro commented#22 Did the trick for me!
Comment #29
Michsk commentedIm not sure how this can work for you guys, but for me with the latest dev. The javascript isn't even added to the fields.
So this patch does not work for.
Comment #30
Michsk commentedSetting to critical, this module must work with groups/fieldsets
Comment #31
Michsk commentedPS; im using CCK3
Comment #32
sansui commentedI've also tried the patch with the latest dev, also using vertical tabs - if anything it's worse, definitely doesn't function within vertical tabs.
When you first upload a file and crop, it seems to work ok, but once you return to it after it's been hidden by the vertical tabs on page load, you get what's included in my screenshot.
Comment #33
sansui commentedI made this work for my personal setup by altering the javascript in the patch a bit. The class .vertical-tabs-group_profile_photo is the class of my fieldset in vertical tabs that contains the image crop field I've been trying to get working. I couldn't make it work with the generic values that referenced the wrapper fields parent fields unfortunately.
If someone can figure out why the general use code thinks the parent field is still hidden, even when it's not, maybe we can get this patch working
Comment #34
Rob T commentedThat patch in #26 (based on #22) worked for me. Thanks.
Comment #35
jox commentedI found a solution that works quite well for me so far.
I've had the same problem: I'm using the field_group module with horizontal tabs. A Cropbox that appeared within a (at first) hidden tab, would not display correctly (zero size) when shown.
The reason why it is messed up is because it gets dynamically generated with incorrect size values. The values are obtained from a jquery object which is not completly initialized at that point (obviously due to its hidden state).
My solution takes care that the Cropbox is created properly in the first place when the Jcrop behaviors are attached. It simply initializes the dimensions of the jquery object from the img element. When the img element is not loaded yet a temporary image is created to get the dimensions (happens in IE 7).
As soon this was working, another little problem came up. When the crop area was moved (grabbed) the very first time it would jump right to the top left corner (of the cropbox). After that it was working as expected. I fixed this by (re-)initializing the offset when a drag process starts.
These changes have to be made to the (external) Jcrop plugin though. I think this could be even considered a bug in Jcrop.
Please test this and if you can confirm and agree, I'll report it to the maintainer of Jcrop.
Although I'm workin with 7.x-1.x-dev it should apply to other versions equally since only the Jcrop plugin is affected.
Tested with the following browsers:
The patch only modifies the file Jcrop/js/jquery.Jcrop.js. The minimized jquery.Jcrop.min.js is there also, but is not used (from my observations). As well as the packed jquery.Jcrop.pack.js in 6.x. I think if they are used or for consistency they should also be fixed sooner or later (or removed).
Comment #36
univate commentedHere is the patch from #35 for 6.x-1.x
Not sure if the version of jcrop has changed between branches, but that patch wouldn't apply cleanly in 6.x.
Comment #37
jox commentedYes, indeed 6.x-1.x uses Jcrop v0.9.8 and 7.x-1.x uses v0.9.9. Didn't check that, thanks.
Comment #38
JamesK commented#35/36 is a much better solution since it doesn't leave the browser in an infinite loop waiting for the cropbox element to be visible. Unfortunately, it does not seem to work (tested on 6.x-1.x + Chrome 13 + both vertical tabs and collapsed fieldset). The patch applies, but it has no visible effect on the problem.
Comment #39
JamesK commentedClosed #779044: When outside main Vertical Tab it fails. and #1030746: Works fine first time - broken when edited as duplicate of this one since this one has some semi-working patches at least.
Comment #40
jox commentedJust a quick update.
I did some testing with a Drupal 6.22 installation and imagefield_crop-6.x-1.x-dev which indeed still has the problem.
First I tried to update Jcrop from v0.9.8 to v0.9.9 (as in D7). That did not help. After some some debugging I noted that there is some strange (jQuery-)behaviour happening.
Then I was a bit surprised to find that Drupal 6 uses the 3 year old jQuery v1.2.6 from 2008-05-24 (misc/jquery.js).
Drupal 7 is using jQuery v1.4.4 from 2010-11-11.
After copying the misc/jquery.js v1.4.4 from D7 to D6 (with Jcrop back to v0.9.8) the problem was solved!
But I'm not sure if it can be done that easily, without breaking other things.
I tried the jQuery Update module.
But all versions jquery_update-6.x-1.1 (has same jQuery v1.2.6 as current D6 core), jquery_update-6.x-2.0-alpha1 (jQuery v1.3.2), jquery_update-6.x-2.x-dev 2011-Apr-20 as well as the latest 6.x-2.x git branch (jQuery v1.3.2) do not fix it.
The only jQuery version so far (that I've tested), that fixes the problem, is v1.4.4.
Before I spend more time with it I'd like to see if anybody else has any other idea.
Comment #41
open social commentedapplied the patch of #36 by hand it works for http://drupal.org/node/1030746
Comment #42
DaPooch commentedI can't get the patch in 36 to work against 6.x-1.x either. Upgrading Jquery isn't a good option because a lot of other modules and core things depend on it. It could be possible to try to load it alongside the existing jquery using the noConflict mode as outlined here:http://drupal.org/node/1058168 but that's probably not ideal since it will bloat the page running 2 copies of jquery. Ideally we need to track down the issue and make it at least jQuery 1.3.2 compatible for the drupal 6 branches so it can run with jquery update.
Comment #43
DaPooch commented#33 worked for me and I made a slight modification of the first line of the function to allow this to work for any hidden fieldset that may contain images.
Change:
if (!($('.vertical-tabs-group_profile_photo').is(':hidden'))) {
to:
if (!($('.jcrop-preview-wrapper').parents('fieldset').is(':hidden'))) {
And it should work for any fieldset that contains the cropper.
Tested working on Chrome 13 with 1.0-RC2 and Patch from #36 applied. (Not sure if that patch application matters or not though)
Comment #44
jox commented@alanpuccinelli: I agree with #42 but cannot follow #43. I can't find that line.
Comment #45
DaPooch commentedSorry to be unclear, that was an edit of the suggestion in #33.
Comment #46
jox commentedOh sorry, my fault, I didn't notice the "#33".
Ok, but this is still more of a workaround than a solution. First because it's using a timeout and second because it requires to manually add code somewhere (if I understand that right).
Comment #47
jox commentedSorry again, your proposed change does not require to manually add code somewhere, that was the idea. But it's still the timeout that doesn't qualify it, in my opinion.
Comment #48
nampham commentedThank vood002 (#22), it works for me.
Comment #49
bryancasler commentedJox's patch in #35 works against the 7.x-2.x-dev (Aug 22nd) version on Drupal 7.7
I also tested it with the Jquery Update module enabled (Updates jQuery to jQuery 1.5.2 and jQuery UI 1.8.11.) and it works.
Tested in....
Chrome 13.0.782.215 m
Firefox 6.0.1
IE 9.0.8....
There was one problem. After saving a new image to the crop area and saving the node, the first person to view it (probably the person who just saved the node) will see a full resolution image. The second person visiting the page will see the correctly cropped photo. This side effect is less severe than the problem it fixes.
Comment #50
jox commented@animelion: thanks for your review. I have never experienced the problem you describe. Might that be some browser cache issue? Since the cropped image will have the same filename as the original image (the original will be renamed to the same name with "_0" attached).
When I try to reproduce it like you describe, the node is displayed right after saving it and always shows the correctly cropped image.
Does the problem occur for you really anytime you try it? Or sometimes it does and sometimes not?
Could you try to give more details in order to reproduce the problem?
Comment #51
bryancasler commentedThanks jox, played around some more and the problem only happens if the Jquery Update module is installed.
Comment #52
jox commented@animelion: unfortunately even with Jquery Update enabled, I'm not able to reproduce it...
Some questions:
Comment #53
bryancasler commentedAfter uninstalling and re-installing the jquery update module the problem seems to have gone away. If it "crops" up again I'll be sure to follow up and do the additional troubleshooting you requested.
1. Only tried in chrome
2. No, it has stopped actually
3. Whatever defaults the module configures. No additional fields other than the nested field groups.
4. The correct image would appear
5. Haven't been able to reproduce so I can't test this
6. A bunch, will post if the problem crops up again
7. If the problem crops up again I will give this a go
Comment #54
jox commentedThat's strange. But it makes me think it might not be related to my fix, but not sure.
Anyway thanks for your report, and get back if you experience it again.
Comment #55
kndr#26 works for me. Thank you. I am attaching the same patch for 6.x-1.0
Comment #56
yhager commented@jox, that your comment in #40 relate to the patched jcrop (from #35/#36). I prefer to patch jcrop if it solves the problem, but will retort to the looping method if it doesn't. Have you tried introducing that patch to Jcrop upstream?
If #35/#36 do not work for this case, I will implement one of the solutions in the patches here. Also found this: http://plugins.jquery.com/project/in-viewport-event, which might also be used.
Comment #57
kumkum29 commentedhello,
#55 works for me but a new problem exists.
If we edit multiple uploaded images, the patch works well for the first image but not for others. On the first image, the crop is present in the middle of the source image, it's ok. But for others images the crop takes the already cropped images.
Do you have a solution?
Comment #58
kumkum29 commentedHello,
nobody has this problem ? (see #57)
Thanks.
Comment #59
kumkum29 commented#57 #58
Hello,
The problem is the file name with the "FileField Paths" module.
if we apply the following patch "http://drupal.org/node/1172724" everything works normally.
Comment #60
jox commented@yhager #56: sorry for the delay. I have just contacted the author of Jcrop describing the problem and introducing the patch.
I am now waiting for a reply and will inform you about any news.
Comment #61
jox commentedGreat news. Kelly Hallman, author of Jcrop, was so kind to add the fix (#35/#36) to his project:
https://github.com/tapmodo/Jcrop/commit/6150bbad59283a33bcf8d36c7e3f8d7a...
He created also a little demo for this "new feature":
http://aji.tapmodo.com/~khallman/Jcrop/demos/jquery-ui.html
He announced the release 0.9.10 which includes this patch (among other improvents and fixes).
(https://github.com/tapmodo/Jcrop/commits/master.)
It should be available very soon:
http://deepliquid.com/content/Jcrop.html
Comment #62
yhager commentedThese are great news @jox! Thanks very much for pushing this.
I haven't tested yet, but this might even allow us to remove the notorious delay we have in the code as a guess for the time the image is loaded.
Once the release for Jcrop 0.9.10 is public, I'll update it. (if you notice it before me, feel free to nudge here)
Comment #63
Lankyman85 commentedHi, i am relatively new to drupal and have never applied a patch before. Any directions would be much appreciated.
Comment #64
yhager commented@Lankyman85: http://drupal.org/patch/apply
Comment #65
Lankyman85 commentedThanks for the reply, i ended up installing imagefield focus which works pretty much the same as image crop.
Comment #66
pgsengstock commentedThe latest Jcrop (v0.9.10), is available: http://deepliquid.com/content/Jcrop.html
And it totally fixes this issue!
Comment #67
aidanlis commentedConfirm that dropping the new v.9.10 Jcrop into imagefield_crop-6.x-1.0-rc2 fixes the problem. Moving to needs review so the module author can action.
Comment #68
pvdsteen commentedDropping in new v.9.10 Jcrop fixed my issue for Drupal 7.
Had the same problem, but with a custom image field attached to a user (not profile2).
Imagefield crop works fine, but when you put the field in a vertical tab Jcrop is not loaded properly while editing an already uploaded image.
Comment #69
jaxxed commentedHad the same problem. It's kind of ridiculous that it isn't patched yet, so I will submit this proper patch.
The only change I made here was to update the JCrop library to 0.9.12 (added the MIT license too)
Others have said that this fixes the problem for them.
Please check to see if there are any cases where the updated library breaks the system.
* patch applies to 7.x-1.x (7.x-2.x is still in dev)
** I will check the 7.x-2.x to see if it could use the update as well.
Comment #70
jaxxed commentedstatus change to trigger review
Comment #71
jaxxed commentedstatus change to trigger review
Comment #72
jox commentedI confirm Jcrop 0.9.12 does include my fix (it does since 0.9.10) and works generally well with imagefield_crop (7.x-1.1).
Imagefield_crop still includes Jcrop 0.9.9 in all versions (latest 7.x-1.x and 7.x-2.x).
@yhager (or some other maintainer): It would be great if you could update the library sometime.
Thanks.
Comment #74
joetsuihk commentedComment #75
jox commentedNot complaining about jaxxed getting (the) credit. It's not entirely fair though, that the one who did the significant part of the work was ignored. See Commit messages - providing history and credit
Thanks for commiting anyway.
Comment #76
joetsuihk commentedThanks jox. I have no means to discredit you in any way, but I cannot credit every contributors in the thread. I am crediting him just because he is the patch creator. Thank you for coordinating with Jcrop creator.
Comment #77
jox commentedI'm not every contributor in the thread. I'm the one who spend a couple of hours to fix the issue (programmatically). The coordinating was just some followup favor.
Comment #78
jox commented@joetsuihk: Let me add something. I think what you said is not perfectly true: "I cannot credit every contributors in the thread". Since you as a maintainer are actually encuraged to do so. The docs (link above) say "If others have contributed to the change you are committing, take the time to give them credit". Of course you're not supposed to add everybody in the thread. Thats why it says "take the time". It's quite common to see several contributors in the commit messages.
Only adding the contributor that posted the last patch is just to simple. Often enough patches are resubmitted by others due to changes in the original code, since issues sometimes take ages to finally get committed. They deserve credit, but the original author not less.
Some more relevant quotes from the docs:
"Each commit message should contain at least one contributor name, even if it refers to yourself."
"If a very very large list of people (eg. more than 10-12) contributed to a change, pick the major contributors and add et al to represent the rest"
"it's very valuable to know who actually wrote or contributed a certain change"
Please don't get me wrong. I do not insist by all means in getting this credit and I'm not angry or something. It would just be nice to see some consent so others get their deserved credit when you do further commits in the future.
Comment #79
yhager commented@jox, I'm sorry your name was dropped from the credit. We value and appreciate patches. It's heartwarming when someone else spends time to fix issues that are dear to them and then we can all benefit.
We can't edit the comment AFAIK. We'll strive to give credit where it's due in the future.
We hope you'll accept this apology and continue contributing to this module. It definitely needs some love.
Thanks
Comment #80
jox commentedThanks yhager. That's some nice words. It's all right. I'll gladly contribute more if there's a chance. :-)
Comment #81
WebbehConfirming that #69 works to fix the issue. Thanks to all for your hard work!
Comment #83
vinmassaro commentedThere is a patch for 7.x-2.x here: #2054767-4: Update Jcrop to v0.9.12