There is a problem with the fake submit handler in the media browser (views) library.

If you don't select anything it alerts you then loads the homepage in the iframe due to the click event not being cancelled. It also adds the click handler onto the fake buttons as many times as you click around in the library. So if you click through a few pages n times without selecting anything and click submit it actually executes the submit handler n+1 times.

The event handler duplication can be fixed with

  $('a.button.fake-submit', this).once().bind('click', Drupal.media.browser.submit);
  $('a.button.fake-cancel', this).once().bind('click', Drupal.media.browser.submit);

The event bubbling can be fixed with a return false .

Drupal.media.browser.submit = function () {
  // @see Drupal.media.browser.validateButtons().
  var buttons = $(parent.window.document.body).find('#mediaBrowser').parent('.ui-dialog').find('.ui-dialog-buttonpane button');
  if ($(this).hasClass('fake-cancel')) {
    buttons[1].click();
  }
  else {
    buttons[0].click();
  }
  // return false to prevert the default anchor location
  return false;
}
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

aaron’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
979 bytes

works as advertised; here's a patch.

aaron’s picture

Status: Reviewed & tested by the community » Needs work

I take it back, this patch actually breaks the browser functionality, so that it no longer allows for any selection of media to be submitted.

aaron’s picture

Status: Needs work » Reviewed & tested by the community

No, I'm sorry, false alarm. There was something else going on, I'm not sure what, but after refreshing the page (which had been open for some time), it all start working again.

amateescu’s picture

Priority: Normal » Major

There's another nasty issue that's fixed by this patch: #1319846: Cancel returns homepage in iFrame

Confirming the RTBC status :)

Dave Reid’s picture

Status: Reviewed & tested by the community » Fixed

Tested and confirmed. Committed to 7.x-2.x only with http://drupalcode.org/project/media.git/commit/635ee16. Thanks Jamie, Aaron, and Andrei!

veleiro’s picture

Thank you, works as stated

Status: Fixed » Closed (fixed)

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