Drupal.media.browser.validateButtons = function() {
// The media browser runs in an IFRAME. The Drupal.media.popups.mediaBrowser()
// function sets up the IFRAME and "OK" and "Cancel" buttons that are outside
// of the IFRAME, so that their click handlers can destroy the IFRAME while
// retaining information about what media items were selected. However,
// Drupal UI convention is to place all action buttons on the same "line"
// at the bottom of the form, so if the form within the IFRAME contains a
// "Submit" button or other action buttons, then the "OK" and "Cancel"
// buttons below the IFRAME break this convention and confuse the user.
// Therefore, we add "Submit" and "Cancel" buttons inside the IFRAME, and
// have their click action trigger the click action of the corresonding
// "OK" and "Cancel" buttons that are outside the IFRAME. media.css contains
// CSS rules that hide the outside buttons.
//
// We don't add a "Submit" button if the form already has one, since in these
// cases, another round-trip to the server is needed before the user's
// selection is finalized. For these cases, when the form's real Submit
// button is clicked, the server either returns another form for the user to
// fill out, or else a completion page that contains or sets the
// Drupal.media.browser.selectedMedia variable. If the latter, then
// Drupal.media.popups.mediaBrowser.mediaBrowserOnLoad() auto-triggers the
// "OK" button action to finalize the selection and remove the IFRAME.
//
// @todo An alternate, less hacky solution would be most welcome.
if (!($('.form-submit', this).length > 0)) {
$('<a class="button fake-ok">Submit</a>').appendTo(this).bind('click', Drupal.media.browser.submit);
if (!($('.fake-cancel', this).length > 0)) {
$('<a class="button fake-cancel">Cancel</a>').appendTo(this).bind('click', Drupal.media.browser.submit);
}
} else if (!($('.fake-cancel', this).length > 0)) {
var parent = $('.form-actions', this);
if (!parent.length) {
parent = $('form > div', this);
}
$('<a class="button fake-cancel">Cancel</a>').appendTo(parent).bind('click', Drupal.media.browser.submit);
}
};
(See also http://jsfiddle.net/S6WXc/.)
This function in the Media Modules js/media.browser.js is clashing with what I've added into the Media Select popup via Form Alter (A simple AJAX call to display thumbnails of images, that when clicked open up in a Colorbox modal window).
I've tracked the problem down to something in Media Module and Colorbox clashing, since when I click a thumb that opens the Colorbox modal popup, an event is launched that duplicates the 'fake' Submit / Cancel buttons in the Library tab, and also some of the Library thumbnails (my own thumbs are shown in the Web tab).
Not going in further detail, is there some way to override the function in the Media Module without editing the actual original .js file? I don't fancy doing edits each time I update it so to override it in my module or my own .js file would be preferable.