123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- /**
- * DO NOT EDIT THIS FILE.
- * See the following change record for more information,
- * https://www.drupal.org/node/2815083
- * @preserve
- **/
- (function ($, Drupal) {
- Drupal.behaviors.fileValidateAutoAttach = {
- attach: function attach(context, settings) {
- var $context = $(context);
- var elements = void 0;
- function initFileValidation(selector) {
- $context.find(selector).once('fileValidate').on('change.fileValidate', { extensions: elements[selector] }, Drupal.file.validateExtension);
- }
- if (settings.file && settings.file.elements) {
- elements = settings.file.elements;
- Object.keys(elements).forEach(initFileValidation);
- }
- },
- detach: function detach(context, settings, trigger) {
- var $context = $(context);
- var elements = void 0;
- function removeFileValidation(selector) {
- $context.find(selector).removeOnce('fileValidate').off('change.fileValidate', Drupal.file.validateExtension);
- }
- if (trigger === 'unload' && settings.file && settings.file.elements) {
- elements = settings.file.elements;
- Object.keys(elements).forEach(removeFileValidation);
- }
- }
- };
- Drupal.behaviors.fileAutoUpload = {
- attach: function attach(context) {
- $(context).find('input[type="file"]').once('auto-file-upload').on('change.autoFileUpload', Drupal.file.triggerUploadButton);
- },
- detach: function detach(context, settings, trigger) {
- if (trigger === 'unload') {
- $(context).find('input[type="file"]').removeOnce('auto-file-upload').off('.autoFileUpload');
- }
- }
- };
- Drupal.behaviors.fileButtons = {
- attach: function attach(context) {
- var $context = $(context);
- $context.find('.js-form-submit').on('mousedown', Drupal.file.disableFields);
- $context.find('.js-form-managed-file .js-form-submit').on('mousedown', Drupal.file.progressBar);
- },
- detach: function detach(context, settings, trigger) {
- if (trigger === 'unload') {
- var $context = $(context);
- $context.find('.js-form-submit').off('mousedown', Drupal.file.disableFields);
- $context.find('.js-form-managed-file .js-form-submit').off('mousedown', Drupal.file.progressBar);
- }
- }
- };
- Drupal.behaviors.filePreviewLinks = {
- attach: function attach(context) {
- $(context).find('div.js-form-managed-file .file a').on('click', Drupal.file.openInNewWindow);
- },
- detach: function detach(context) {
- $(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');
- 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.value = '';
- event.stopImmediatePropagation();
- }
- }
- },
- triggerUploadButton: function triggerUploadButton(event) {
- $(event.target).closest('.js-form-managed-file').find('.js-form-submit').trigger('mousedown');
- },
- 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');
- }
- var $fieldsToTemporarilyDisable = $('div.js-form-managed-file input.js-form-file').not($enabledFields).not(':disabled');
- $fieldsToTemporarilyDisable.prop('disabled', true);
- setTimeout(function () {
- $fieldsToTemporarilyDisable.prop('disabled', false);
- }, 1000);
- },
- 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);
- }
- setTimeout(function () {
- $clickedButton.closest('div.js-form-managed-file').find('div.ajax-progress-bar').slideDown();
- }, 500);
- $clickedButton.trigger('fileUpload');
- },
- openInNewWindow: function openInNewWindow(event) {
- event.preventDefault();
- $(this).attr('target', '_blank');
- window.open(this.href, 'filePreview', 'toolbar=0,scrollbars=1,location=1,statusbar=1,menubar=0,resizable=1,width=500,height=550');
- }
- };
- })(jQuery, Drupal);
|