Problem/Motivation

When the content of one of the media browser tabs is updated (using JavaScript and DOM), the height if the dialog is not modified to fit the updated content.

Proposed resolution

When the content of the media browser is updated, the existing Drupal.behaviors.experimentalMediaBrowser should invoke Drupal.media.browser.resizeIframe().

Comments

pbuyle’s picture

Status: Active » Needs review
StatusFileSize
new792 bytes

The attached patch implements the proposed solution.

bforchhammer’s picture

Out of curiosity: what happens if the required height out-grows the window-size? (I haven't actually tested the patch yet)

pbuyle’s picture

The dialog grows outside the visible area, which activate the browser scrollbar. Note that it also happens without the patch in #1 when you switch to another tab and then come back to the updated one.

idflood’s picture

StatusFileSize
new451 bytes

The code looks good and is working well on my tests (changing the exposed filter of the "view library" tab). The patch had a little whitespace error, so here is a simple reroll.

bforchhammer’s picture

Status: Needs review » Reviewed & tested by the community

Patch looks good and works as advertised.

jamiecuthill’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new566 bytes

I have a problem even with the above patch in that the resizeIframe call occurs before the images have finished loading. As the images load the iframe also needs to expand. I firstly experimented with a simple interval function that is started (and stopped) with the media browser popup. It worked, however it's not an ideal situation to be checking the iframe height every second when nothing is really happening.

Here are the code snippets I tried in media.popups.js for that though I have a better solution.

Drupal.media.popups.mediaBrowser.mediaBrowserOnLoad = function (e) {
  var options = e.data;
  Drupal.media.popups.watcher = setInterval(function() {
    if (window.frames["mediaBrowser"]) {
      //window.frames["mediaBrowser"].Drupal.media.browser.resizeIframe();
    }
  }, 1000);
...

Drupal.media.popups.mediaBrowser.finalizeSelection = function () {
  clearInterval(Drupal.media.popups.watcher);
...

Now the better solution is to attach a load event handler on each image within the library view results that will resize the iframe. Patch attached.

Status: Needs review » Needs work

The last submitted patch, resize_media_browser-1298962-6.patch, failed testing.

jamiecuthill’s picture

Status: Needs work » Needs review
StatusFileSize
new567 bytes

That might not apply cleanly. Here is a fixed version.

idflood’s picture

Status: Needs review » Needs work

Nice catch. I would choose the setInterval option. It's the most reliable method and it will not have much impact on performance.
according to http://api.jquery.com/load-event/

Caveats of the load event when used with images
...

  • It doesn't work consistently nor reliably cross-browser
  • It doesn't fire correctly in WebKit if the image src is set to the same src as before
  • It doesn't correctly bubble up the DOM tree
  • Can cease to fire for images that already live in the browser's cache
idflood’s picture

Status: Needs work » Needs review
jamiecuthill’s picture

Status: Needs review » Needs work

I didn't realise the load event had those issues. Shall I create a patch for the interval implementation?

jamiecuthill’s picture

StatusFileSize
new775 bytes

Here is the patch for the interval implementation. It's set to resize every second so you will noticed a little lag in the resizing.

jamiecuthill’s picture

Status: Needs work » Needs review
idflood’s picture

The patch in #12 looks good and and is working well. A little problem is that I was not able to reproduce the issue, even without the patch. So either it has have been fixed somewhere else or I did something wrong.

pbuyle’s picture

The patch in #12 launch the interval, whatever the containing page is. So it would probably run the interval twice, once in thepage containing the dialog iFrame, and once in the iFrame itself. The if ($(context).parents('#media-browser-page').length) in the original patch prevent the resize from running outside the iFrame.

Also, even only in the iFrame, resizing every second is not a very good option since resizing is a costly operation. It gets the height of the body element, triggering a reflow of the document content.

Periodic resizing should be limited to the dialog iFrame content and only when it contains images (and maybe frames, iframes, objects and embeds). And even then, if the height has never changed after few resizes, it could probably be assumed that the interval can be cleared.

jarrodirwin’s picture

jarrodirwin’s picture

Status: Needs review » Needs work

The last submitted patch, resize_media_browser-1298962-8.patch, failed testing.

jarrodirwin’s picture

Status: Needs work » Needs review
StatusFileSize
new819 bytes

fixed to work with latest release (unstable5)

pbuyle’s picture

The patch does not address my comments in #15.

dddave’s picture

Status: Needs review » Needs work

per #20

dmsmidt’s picture

Status: Needs work » Needs review

I've manually applied the changes as proposed in the patch at # to unstable7-dev.
It works, but I have to agree with #15, that it is a too costly operation.
And browsing images is from an UX point of view not so smooth, since there is a one second lag.

In my patch I set the interval much lower as to get a more smooth transition while the images load.
The interval only starts at the browser tab and stops after all images are loaded.
Also, the resize is only triggered when the body height is taller than the iframe.

The caveats of load() mentioned in #9, are in my implementation imho not that relevant since if load isn't triggered resizing still works and only the interval keeps on running (checking heights).

dmsmidt’s picture

StatusFileSize
new1.1 KB

Patch against unstable7.

ParisLiakos’s picture

patch introduces tabs instead of two spaces per drupal codings standards

luksak’s picture

Status: Needs review » Needs work

This doesn't fix the issue for me. I can't see any improvement.

luksak’s picture

Issue summary: View changes

typo

devin carlson’s picture

Issue summary: View changes
Status: Needs work » Fixed
Related issues: +#1972628: Browser size doesn't fit it's content

This should be fixed in the latest -dev as part of #1972628: Browser size doesn't fit it's content.

Status: Fixed » Closed (fixed)

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