The initialization of cropper currently looks like this:

$cropWrapperSummary.bind('click', function (e) {
  var $element = $(this).parents(cropWrapperSelector);
  setTimeout(function () {
    Drupal.imageWidgetCrop.initializeCropperOnChildren($element);
  }, 10);
  return true;
});

$verticalTabsMenuItem.click(function () {
  var tabId = $(this).find('a').attr('href');
  var $cropper = $(tabId).find(cropperSelector);
  Drupal.imageWidgetCrop.initializeCropper($cropper, $cropper.data('ratio'));
});

There are several issues with this:

  1. There is no event to bind on when a tab or details element is being shown or hidden.
  2. Since all events we currently can bind on fire before the cropping area is being displayed, we need to use the setTimeout() workaround to let it fire later on. We can only initialize Cropper on visible elements, since it need to calculate the dimensions.
  3. We bind on two events where it would totally be possible with one.
  4. Vertical tabs behave very weird responsively. They don't get initalized if the browser is too small and therefore the click handler doesn't work. #2625848: Fix responsive wrapping for mobile clients is postponed because of this.
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Lukas von Blarer created an issue. See original summary.

Lukas von Blarer’s picture

Issue summary: View changes
miro_dietiker’s picture

I guess this is a bit related, there are some references about unneeded attributes and ratio determination and scaling:
#2641970: Cropping coordinate determination

Lukas von Blarer’s picture

Not that much, actually. This is mainly related to flaws of vertical tabs in core.

miro_dietiker’s picture

I fully agree about that core origin.

So can you point me at the core issue that picks up the ball to add the missing events?
If not, please open an issue. We should promote the issue on our side and help resolve this.
Also if code contains workarounds, the code should contain a reference to the issue with a cleanup @todo.

woprrr’s picture

Issue tags: +D8Media

We have an issue in d.o or we need to create this issue ? I can talk this with fgm to view. I not sure to understand all problems in this issue.

miro_dietiker’s picture

Version: » 8.x-1.x-dev

I assigned it to someone of our team to investigate it.

I have the same problem as you do. It's a workaround without any explanation.
They first need to check the d.o issue queue to see if there is an issue, or create one and describe the problem.

sanja_m’s picture

Assigned: Unassigned » sanja_m

Assigning to me. I am checking the possibility of resolving these issues only with JS, without involving any other vertical tabs core issues.

sanja_m’s picture

Status: Active » Needs review
FileSize
2.45 KB

Created the patch that removes setTimeout() workaround and fixes cropper initialization for smaller devices.

woprrr’s picture

Status: Needs review » Needs work

After the merge of issue "https://www.drupal.org/node/2631712" i can not seem to apply you patch, for not make stupid error I can let you do the update? thanks a lot @sanja_m

woprrr’s picture

Now it's ok i ve re-create patch and apply is now ok for that. But i ve a new comportement now, when i upload / edit an image i open "crop image" tab nothing fire, when i click an vertical tabs cropper fire initilize and all is okay. My problem is for this "step" or you do not really know what to do after having just unfold the item. Should we Grisse you the picture and tell the user to choose a format on the left? What are your views on the matter?

I add a screenshot to illustrate my think.

Just after open "crop image" tab :
screenshot step 1

Now i click on 16:9 tab and cropper is initialize (cool :))
screenshot step 2

sanja_m’s picture

I will test it again and try to figure out what is the problem for that step when "crop image" tab opens, and try to fix that.

woprrr’s picture

Super !! thanks :) I trust you entirely on that subject.

miro_dietiker’s picture

Just firing the initialisation also for the default tab should be easy.

However i still say that the vertical tabs from core should offer an event that is fired where we can subscribe. That event would also need to be fired for the default tab initially.

While i appreciate a better solution without setTimeout in IWC without a core dependency, it's still critical that this lacking thing of core is escalated and need to be addressed.

sanja_m’s picture

Status: Needs work » Needs review
FileSize
2.66 KB
1.18 KB

Fixed bugs for chrome. Also created issue for missing events in vertical tabs: https://www.drupal.org/node/2653570.

woprrr’s picture

Status: Needs review » Reviewed & tested by the community

It's Ok for me :) Great job thanks.

  • woprrr committed 841c3e5 on 8.x-1.x authored by sanja_m
    Issue #2631710 by sanja_m, woprrr, miro_dietiker, Lukas von Blarer:...
woprrr’s picture

Status: Reviewed & tested by the community » Fixed
woprrr’s picture

Status: Fixed » Needs work
FileSize
152.04 KB

ERF !!! I ve found an error when you have few crop type in same field @see

txt

sanja_m’s picture

Status: Needs work » Needs review
FileSize
635 bytes

Fixed for multiple crop types too.

  • woprrr committed 38ab543 on authored by sanja_m
    Issue #2631710 by sanja_m, woprrr: Improve Cropper initialization
    
woprrr’s picture

Status: Needs review » Fixed

@sanja_m Great job :) it's okay now, i ve tested it in all case for me it's OK.

woprrr’s picture

@sanja_m i think we need your help in this issue few new js comportements (strange). #2654210

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.