$(selector, context).once('media-browser-launch', function () {
var configuration = settings.media.elements[selector];
// The user has JavaScript enabled, so display the browse field and hide
// the upload and attach fields which are only used as a fallback in
// case the user is unable to use the media browser.
$(selector, context).children('.browse').show();
$(selector, context).children('.upload').hide();
$(selector, context).children('.attach').hide();
$(selector, context).children('.browse').once().bind('click', {configuration: configuration}, Drupal.media.openBrowser);
});
All the $(selector, context)s are unnecessary, as we've already run the selector before applying once() to it. This is both not great from a performance point of view, but also completely invalidates the use of once(), as we don't bother using the filtered selection.
This became apparent due to #2551361: ID of media upload element gets used twice, where the containing div and the upload input have the same ID, causing the click submit handlers to be attached twice (and therefore the media browser popup to appear twice).
Comments
Comment #2
andrewbelcher commentedHere is a patch that swaps that code and uses
thisas provided by our wrappingonce()which solves both issues.Comment #3
chris matthews commentedClosing this issue as outdated. However, if you think this issue is still important, please let us know and we will gladly re-open it for review.
sincerely,
- the Drupal Media Team