Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#36 | media_browser_not_closing_properly-2093435-36.patch | 601 bytes | magi.yv |
#27 | media-dialog-removal-2093435-27.patch | 651 bytes | dagomar |
#25 | media-dialog_removal-2093435-24.patch | 449 bytes | TobiasFPetersen |
#21 | media-js-dialog-issues-2093435-21.patch | 2.15 KB | chrisgross |
#20 | media-js-dialog-issues-2093435-20.patch | 380 bytes | chrisgross |
Comments
Comment #1
reubenavery CreditAttribution: reubenavery commentedHere'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..
Comment #2
ericduran CreditAttribution: ericduran commentedYep, 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.
Comment #3
ericduran CreditAttribution: ericduran commentedAfter looking into this more. It seems like the culprit is media_multiselect.
@reubidium are you also running media_multiselect?
Comment #4
ericduran CreditAttribution: ericduran commentedHere 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.
Comment #5
reubenavery CreditAttribution: reubenavery commented@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.
Comment #6
ericduran CreditAttribution: ericduran commented@reubidium yep.
#4 fixes the actual media module issue.
Comment #7
sylus CreditAttribution: sylus commentedFixed my problems nicely :)
Comment #8
aaron CreditAttribution: aaron commented#4: 2093435-media-js-dialog-issues.patch queued for re-testing.
Comment #9
reubenavery CreditAttribution: reubenavery commentedmeh, 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?
Comment #10
ericduran CreditAttribution: ericduran commentedYea, 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.
Comment #11
vordude CreditAttribution: vordude commentedReroll for clean application.
Comment #12
vordude CreditAttribution: vordude commentedAdditional tweak along the same lines as this patch to fix the issues seen by @reubenavery which also affected me.
Comment #13
vordude CreditAttribution: vordude commentedComment #14
msound CreditAttribution: msound commentedWhen 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).
Comment #15
chrisgross CreditAttribution: chrisgross commented#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.
Comment #16
cweagansHere'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.
Comment #17
chrisgross CreditAttribution: chrisgross commentedSo 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.Comment #18
chrisgross CreditAttribution: chrisgross commentedClosing (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:
Perhaps this is redundant? But without it, the dialog is never destroyed.
Comment #19
dawnbuie CreditAttribution: dawnbuie commentedCan 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
Comment #20
chrisgross CreditAttribution: chrisgross commentedAs 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.
Comment #21
chrisgross CreditAttribution: chrisgross commentedI 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.
Comment #22
dawnbuie CreditAttribution: dawnbuie commentedWell 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
Comment #23
Dave ReidComment #24
TobiasFPetersen CreditAttribution: TobiasFPetersen commentedDoing:
close: function (event, ui) {
$(this).dialog("destroy");
$('.media-modal-frame').remove(); //iframe removal.
}
In
Drupal.media.popups.getDialogOptions
solved all problems for me.
Comment #25
TobiasFPetersen CreditAttribution: TobiasFPetersen commentedAnd here is a little patch. seems different approach to the other patch's.
Comment #26
TobiasFPetersen CreditAttribution: TobiasFPetersen commentedSigh...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.
Comment #27
dagomar CreditAttribution: dagomar commentedWe had the same issue, I created a patch for the last coment #26, it works for us as well.
Comment #28
jerry CreditAttribution: jerry commentedThe patch in #27 resolved this problem for me, too. I'm using jQuery 1.5 for admin pages, incidentally.
Comment #29
gooddesignusa CreditAttribution: gooddesignusa commentedPatch from #27 worked for me as well. Using jQuery 1.7 on admin pages.
Comment #30
TobiasFPetersen CreditAttribution: TobiasFPetersen commentedNo reports of problems here during my vacation.
We are using jquery 1.7 aswell.
Added patch to our makefiles.
Comment #31
TobiasFPetersen CreditAttribution: TobiasFPetersen commentedComment #32
gooddesignusa CreditAttribution: gooddesignusa commentedI 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.
Comment #33
Dave ReidWaiting 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.
Comment #34
TobiasFPetersen CreditAttribution: TobiasFPetersen commentedplease see #28
Comment #35
Ron Collins CreditAttribution: Ron Collins at Affinity Bridge commentedPatch #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.
Comment #36
magi.yv CreditAttribution: magi.yv at Zyxware Technologies commentedAdded a condition to close the window.
this patch fixed my issue.
Comment #39
joseph.olstadpatch #27 applied to dev.
Thanks @dagomar and others