summaryrefslogtreecommitdiffstatshomepage
path: root/core/modules/file/file.js
diff options
context:
space:
mode:
authorAlex Pott <alex.a.pott@googlemail.com>2020-01-28 11:36:14 +0000
committerAlex Pott <alex.a.pott@googlemail.com>2020-01-28 11:36:14 +0000
commit2dadb738bfd48510db2174323528fe769731c05a (patch)
treef6319d9bfa9af8b41dc0ca7c187bef1eaf17aee4 /core/modules/file/file.js
parent09b78ffb1bc1bb62d21fb3abb85e1349a674597a (diff)
downloaddrupal-2dadb738bfd48510db2174323528fe769731c05a.tar.gz
drupal-2dadb738bfd48510db2174323528fe769731c05a.zip
Issue #3101543 by lauriii, bnjmnm, ravi.shankar: Update core JavaScript dependencies listed in package.json
Diffstat (limited to 'core/modules/file/file.js')
-rw-r--r--core/modules/file/file.js26
1 files changed, 11 insertions, 15 deletions
diff --git a/core/modules/file/file.js b/core/modules/file/file.js
index b14b7868b18c..7a7ae89f25b6 100644
--- a/core/modules/file/file.js
+++ b/core/modules/file/file.js
@@ -9,10 +9,12 @@
Drupal.behaviors.fileValidateAutoAttach = {
attach: function attach(context, settings) {
var $context = $(context);
- var elements = void 0;
+ var elements;
function initFileValidation(selector) {
- $context.find(selector).once('fileValidate').on('change.fileValidate', { extensions: elements[selector] }, Drupal.file.validateExtension);
+ $context.find(selector).once('fileValidate').on('change.fileValidate', {
+ extensions: elements[selector]
+ }, Drupal.file.validateExtension);
}
if (settings.file && settings.file.elements) {
@@ -22,7 +24,7 @@
},
detach: function detach(context, settings, trigger) {
var $context = $(context);
- var elements = void 0;
+ var elements;
function removeFileValidation(selector) {
$context.find(selector).removeOnce('fileValidate').off('change.fileValidate', Drupal.file.validateExtension);
@@ -34,7 +36,6 @@
}
}
};
-
Drupal.behaviors.fileAutoUpload = {
attach: function attach(context) {
$(context).find('input[type="file"]').once('auto-file-upload').on('change.autoFileUpload', Drupal.file.triggerUploadButton);
@@ -45,7 +46,6 @@
}
}
};
-
Drupal.behaviors.fileButtons = {
attach: function attach(context) {
var $context = $(context);
@@ -60,7 +60,6 @@
}
}
};
-
Drupal.behaviors.filePreviewLinks = {
attach: function attach(context) {
$(context).find('div.js-form-managed-file .file a').on('click', Drupal.file.openInNewWindow);
@@ -69,24 +68,22 @@
$(context).find('div.js-form-managed-file .file a').off('click', Drupal.file.openInNewWindow);
}
};
-
Drupal.file = Drupal.file || {
validateExtension: function validateExtension(event) {
event.preventDefault();
-
$('.file-upload-js-error').remove();
-
var extensionPattern = event.data.extensions.replace(/,\s*/g, '|');
+
if (extensionPattern.length > 1 && this.value.length > 0) {
- var acceptableMatch = new RegExp('\\.(' + extensionPattern + ')$', 'gi');
+ var acceptableMatch = new RegExp("\\.(".concat(extensionPattern, ")$"), 'gi');
+
if (!acceptableMatch.test(this.value)) {
var error = Drupal.t('The selected file %filename cannot be uploaded. Only files with the following extensions are allowed: %extensions.', {
'%filename': this.value.replace('C:\\fakepath\\', ''),
'%extensions': extensionPattern.replace(/\|/g, ', ')
});
- $(this).closest('div.js-form-managed-file').prepend('<div class="messages messages--error file-upload-js-error" aria-live="polite">' + error + '</div>');
+ $(this).closest('div.js-form-managed-file').prepend("<div class=\"messages messages--error file-upload-js-error\" aria-live=\"polite\">".concat(error, "</div>"));
this.value = '';
-
event.stopImmediatePropagation();
}
}
@@ -97,8 +94,8 @@
disableFields: function disableFields(event) {
var $clickedButton = $(this);
$clickedButton.trigger('formUpdated');
-
var $enabledFields = [];
+
if ($clickedButton.closest('div.js-form-managed-file').length > 0) {
$enabledFields = $clickedButton.closest('div.js-form-managed-file').find('input.js-form-file');
}
@@ -112,11 +109,10 @@
progressBar: function progressBar(event) {
var $clickedButton = $(this);
var $progressId = $clickedButton.closest('div.js-form-managed-file').find('input.file-progress');
+
if ($progressId.length) {
var originalName = $progressId.attr('name');
-
$progressId.attr('name', originalName.match(/APC_UPLOAD_PROGRESS|UPLOAD_IDENTIFIER/)[0]);
-
setTimeout(function () {
$progressId.attr('name', originalName);
}, 1000);