Using a media browser popup once works fine. However, once it is closed, should the user try to open it again, the new popup will refuse to close when the user clicks OK or Cancel.

I see in the DOM that it also isn't cleaning up after itself, and that I need to delete the orphan div.ui-dialog to allow the next media popup to function properly.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

reubenavery’s picture

Status: Active » Needs review
FileSize
612 bytes

Here's a patch.

The mediaBrowser is calling $().dialog("close") rather than $().dialog("destroy"). Invoking destroy rather than close seems to do the trick.

Also, I added removal of the orphaned iframe..

ericduran’s picture

Status: Needs review » Needs work

Yep, this is also an issue with multiple uploads.

This doesn't look like the proper fixed since this would just revert #1947094: Closing Media Browser dialog with Escape causes orphaned HTML to hang around cause that issue to come back up.

Instead it seems media should not re-initialized the dialog if it already exist and just use the same dialog.

The current problem is that it doesn't do a proper check so it still creates a new dialog but when it goes to click on one of the links the button logic is wrong since the values aren't a simple button[1] or button[0] since those are from the previous dialog.

coming up with a patch to solve this but keep the same dialog.

ericduran’s picture

After looking into this more. It seems like the culprit is media_multiselect.

@reubidium are you also running media_multiselect?

ericduran’s picture

Status: Needs work » Needs review
FileSize
1.96 KB

Here we go, This prevents the frame from constantly being re-created which means it should solve this issue and not re-open #1947094: Closing Media Browser dialog with Escape causes orphaned HTML to hang around.

Also technically the fix for the other issue left more orphaned HTML around then it fixed.

reubenavery’s picture

@ericduran-- I did have media_multiselect enabled when I first discovered this was happening! but the problem continued to persist for me after I disabled it.

ericduran’s picture

@reubidium yep.

#4 fixes the actual media module issue.

sylus’s picture

Status: Needs review » Reviewed & tested by the community

Fixed my problems nicely :)

aaron’s picture

reubenavery’s picture

Status: Reviewed & tested by the community » Needs work

meh, it's still giving us some grief here.

when the media wysiwyg integration is on:
- select an image from the library via the wysiwyg media button. this works.
- on the same form, a media selector image field, selecting an image and clicking submit results in 'you havent selected anything'.

my solution was to execute mediaIframe.remove() rather than mediaIframe.attr('src', '') in media.popups.js:87. seems to be fine now, are there some unintended side effects i'm not forseeing?

ericduran’s picture

Yea, removing the iframe essentially goes back to the previous code. My understanding from #1947094: Closing Media Browser dialog with Escape causes orphaned HTML to hang around was that they wanted to avoid doing that. For the issues mention in the other issue.

vordude’s picture

Issue summary: View changes
FileSize
1.58 KB

Reroll for clean application.

vordude’s picture

Additional tweak along the same lines as this patch to fix the issues seen by @reubenavery which also affected me.

vordude’s picture

Status: Needs work » Needs review
msound’s picture

When upgrading to media 2.0-alpha4, and media_multiselect (including patch #12 from https://www.drupal.org/node/2216273), the media browser not cleaning up after closing is producing a strange behavior. With unlimited cardinality on a field, the first time I upload an image, I get one thumbnail (which is fine). I decide to add more images, so the second time I upload an image, I get two thumbnails of the second image. The third time I upload an image, I get three thumbnails of the third image and so on. This is happening because the mediaIframe "bind"s every time the popup opens, and does not unbind when its closed. So it fires multiple ajax calls for the same image.

Attached is a patch that fixes this (I have re-rolled patch #12 above, with a one change for unbind).

chrisgross’s picture

#12 works to prevent the dialog from getting stuck, but instead makes the close button disappear on the next dialog. The escape key does not work either, making clicking "Cancel" or "Submit" the only way to close the dialog.

Downgrading to jQuery 1.5 seems to fix this, but 1.7 and higher seem to have this problem.

cweagans’s picture

FileSize
1.91 KB

Here's one more patch - the media iFrame wasn't getting adequately cleaned up in some cases, and doing it explicitly in the same place as msound's cleanup code takes care of that issue.

chrisgross’s picture

So far so good on #16. Thanks!

Scratch that, the problem is still occurring. :-/

The 'X' button still randomly disappears after using it once.

Looking at the patch it seems that this cleanup is done after clicking an "ok" button, but this problem occurs when using the "close/X" button.

update: it looks like those changes in the patch are only being added to the mediabrowser function. Maybe they need to be added to every function where the dialog is closed? I don't know if that's relevant though because the media browser behaves this way, too.

Interestingly, though, now the ESC key works to close the dialog even when the Close is missing, whereas before it did not seem to. All we need is the make the Close button appear. Once you click into the dialog window, the ESC key no longer works.

chrisgross’s picture

Closing (and destroying) the dialog itself on hitting the close button seems to work. Shouldn't this be the default behavior? The patches above seems to only be taking action on successful operations, not on close.

In Drupal.media.popups.getDialogOptions, adding a dialog close statement seems to do this:

close: function (event, ui) {
  $(event.target).remove();
  $(this).dialog("close");
}

Perhaps this is redundant? But without it, the dialog is never destroyed.

dawnbuie’s picture

Can you confirm I'm having the same issue?

I have a field in my node that allows multiple images to be added using media browser.

When I click the 'Attach media' Browse button everything works as expected. I'm able to select an image from my library, the modal window closes and the image is added to my node with a the 'edit' and 'remove' button visible.

However when I click the Attach media' Browse button a second time my browser scrolls to the top of the page and no modal window comes up.

I have to then save the new node and image and reload in order to be able to access the Media Bowser modal again. Once I've saved the node I need to continue to reload the browser window in order to get the Attach media' Browse button to work again.

Are there patches for this? And how should I troubleshoot this?

I'm using Media 7.x-2.0-alpha4

chrisgross’s picture

As I mentioned before, this code seems like it should be redundant and so I don't know if this is the right way to do it, but it seems to work, so I'll throw up here and see what happens. I've never submitted a patch before, so forgive me if I mess it up.

chrisgross’s picture

I can't really tell which or any of these various similar patches are doing anything, and which are necessary, but if you want to dogpile the dialog destruction, here's #20 plus the previous ones.

dawnbuie’s picture

Well thanks for posting those chrisgross however neither worked for my situation. I'm also using jQuery 1.5 for my admin pages - as that's the only one that works.

Strangely I also have a media browser button on my CKeditor/WYSIWYG editor - and it works fine. I can chose an image, insert it in the body textarea then click it again and select another image etc. No need to refresh the page. I even tried removing that media button from the WYSIWYG bar, but the same problem persisted for my image field that allows multiple files to be attached and uses the media browser.

So I'm surprised no one else is reporting this.

In fact mine may be a separate issue so I've posted my problem here https://www.drupal.org/node/2406925

thanks

Dave Reid’s picture

TobiasFPetersen’s picture

Doing:

close: function (event, ui) {
$(this).dialog("destroy");
$('.media-modal-frame').remove(); //iframe removal.
}
In
Drupal.media.popups.getDialogOptions

solved all problems for me.

TobiasFPetersen’s picture

And here is a little patch. seems different approach to the other patch's.

TobiasFPetersen’s picture

Sigh...jumped the gun , got reports that the wysiwig broke , turns out there is a secondary iframe named:
#mediaStyleSelector which needs to be handled aswell.

Current sollution we are testing:
var elem = $(event.target);
var id = elem.attr('id');
if(id == 'mediaStyleSelector') //which dialog is closing right now ?
{
$(this).dialog("destroy");
$('#mediaStyleSelector').remove(); //iframe removal.
}
else
{
$(this).dialog("destroy");
$('#mediaBrowser').remove(); //iframe removal.

}

So far it seems to work. I will give it a few more days here @ work to be testet before i consider submitting another patch.

dagomar’s picture

We had the same issue, I created a patch for the last coment #26, it works for us as well.

jerry’s picture

The patch in #27 resolved this problem for me, too. I'm using jQuery 1.5 for admin pages, incidentally.

gooddesignusa’s picture

Patch from #27 worked for me as well. Using jQuery 1.7 on admin pages.

TobiasFPetersen’s picture

No reports of problems here during my vacation.
We are using jquery 1.7 aswell.

Added patch to our makefiles.

TobiasFPetersen’s picture

Status: Needs review » Reviewed & tested by the community
gooddesignusa’s picture

I had to switch to using jquery 1.8 on admin pages to fix another media issue: "You have not selected anything!" when not on page 1 (Media v2) - https://www.drupal.org/node/2111695

Patch in #27 continued to work.

Dave Reid’s picture

Status: Reviewed & tested by the community » Needs review

Waiting on confirmation that this doesn't cause a regression with the default versions of jQuery/jQuery UI in D7 core, and not for people using jQuery Update.

TobiasFPetersen’s picture

please see #28

Ron Collins’s picture

Patch #27 doesn't solve the problem for me. I tried on dev and beta1. I'm using jquery_update and tried with jquery 1.5 and 1.7.

This is just a guess (I've run out of time on this) but it seems to break after a page reload. I.e. add an image to a page (works) then reload and do the same thing again (breaks). Not sure if this is always true but might be a lead for someone. I'm thinking of the comment above regarding variables not being completely cleared.

That's all I've got.

magi.yv’s picture

Added a condition to close the window.
this patch fixed my issue.

Status: Needs review » Needs work

The last submitted patch, 36: media_browser_not_closing_properly-2093435-36.patch, failed testing.

joseph.olstad’s picture

Status: Needs work » Fixed

patch #27 applied to dev.

Thanks @dagomar and others

Status: Fixed » Closed (fixed)

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