From 5fc858b205c24dd7582c5b311c85af0dfe36aff2 Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Tue, 3 Sep 2013 22:27:16 +0100
Subject: [PATCH] Issue #297209 by nod_, dwees, bdone: Remove 'Attach' button.

---
 core/modules/file/file.js     | 20 ++++++++++++++++++++
 core/modules/file/file.module |  1 +
 2 files changed, 21 insertions(+)

diff --git a/core/modules/file/file.js b/core/modules/file/file.js
index e1ee3230a92c..df1c3b1a5f72 100644
--- a/core/modules/file/file.js
+++ b/core/modules/file/file.js
@@ -43,6 +43,20 @@ Drupal.behaviors.fileValidateAutoAttach = {
   }
 };
 
+/**
+ * Attach behaviors to managed file element upload fields.
+ */
+Drupal.behaviors.fileAutoUpload = {
+  attach: function (context) {
+    $(context).find('input[type="file"]').once('auto-file-upload').on('change.autoFileUpload', Drupal.file.triggerUploadButton);
+  },
+  detach: function (context, setting, trigger) {
+    if (trigger === 'unload') {
+      $(context).find('input[type="file"]').removeOnce('auto-file-upload').off('.autoFileUpload');
+    }
+  }
+};
+
 /**
  * Attach behaviors to the file upload and remove buttons.
  */
@@ -104,6 +118,12 @@ Drupal.file = Drupal.file || {
       }
     }
   },
+  /**
+   * Trigger the upload_button mouse event to auto-upload as a managed file.
+   */
+  triggerUploadButton: function (event){
+    $(event.target).closest('.form-managed-file').find('.form-submit').trigger('mousedown');
+  },
   /**
    * Prevent file uploads when using buttons not intended to upload.
    */
diff --git a/core/modules/file/file.module b/core/modules/file/file.module
index 5d7797a6f39f..538d1211749c 100644
--- a/core/modules/file/file.module
+++ b/core/modules/file/file.module
@@ -1158,6 +1158,7 @@ function file_managed_file_process($element, &$form_state, $form) {
     '#name' => $parents_prefix . '_upload_button',
     '#type' => 'submit',
     '#value' => t('Upload'),
+    '#attributes' => array('class' => array('js-hide')),
     '#validate' => array(),
     '#submit' => array('file_managed_file_submit'),
     '#limit_validation_errors' => array($element['#parents']),
-- 
GitLab