diff --git a/js/media.js b/js/media.js index 0bc3c15..a8a4175 100644 --- a/js/media.js +++ b/js/media.js @@ -18,10 +18,11 @@ Drupal.behaviors.mediaElement = { $.each(settings.media.elements, function(selector) { var configuration = settings.media.elements[selector]; // The user has JavaScript enabled, so display the browse field and hide - // the upload field which is only used as a fallback in case the user - // is unable to use the media browser. + // 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').unbind().bind('click', {configuration: configuration}, Drupal.media.openBrowser); }); } @@ -82,6 +83,10 @@ Drupal.media.openBrowser = function (event) { uploadField.val(mediaFile.fid); uploadField.trigger('change'); + // Find the attach button and automatically trigger it. + var attachButton = uploadField.siblings('.attach'); + attachButton.trigger('mousedown'); + // Display a preview of the file using the selected media file's display. previewField.html(mediaFile.preview); }, configuration);