123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- (function ($) {
-
-
- Drupal.behaviors.fileButtons = {
- attach: function (context) {
- $(':input.form-submit', context).bind('mousedown', Drupal.file.disableFields);
- $('div.form-managed-file :input.form-submit', context).bind('mousedown', Drupal.file.progressBar);
- },
- detach: function (context) {
- $(':input.form-submit', context).unbind('mousedown', Drupal.file.disableFields);
- $('div.form-managed-file :input.form-submit', context).unbind('mousedown', Drupal.file.progressBar);
- }
- };
- if (Drupal.file) {
-
- Drupal.file.disableFields = function (event){
- var clickedButton = this;
-
- if (!$(clickedButton).hasClass('ajax-processed')) {
- return;
- }
-
- var $enabledFields = [];
- if ($(this).closest('div.form-managed-file').length > 0) {
- $enabledFields = $(this).closest('div.form-managed-file').find(':input.form-file');
- }
-
-
-
-
-
-
-
-
- var $fieldsToTemporarilyDisable = $('div.form-managed-file :input.form-file').not($enabledFields).not(':disabled');
- $fieldsToTemporarilyDisable.attr('disabled', 'disabled');
- setTimeout(function (){
- $fieldsToTemporarilyDisable.attr('disabled', false);
- }, 1000);
- };
-
- Drupal.file.progressBar = function (event) {
- var clickedButton = this;
- var $progressId = $(clickedButton).closest('div.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.form-managed-file').find('div.ajax-progress-bar').slideDown();
- }, 500);
- };
-
- Drupal.file.validateExtension = function (event) {
-
- $('.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.form-managed-file').parents('.form-item').first().prepend('<div class="alert alert-danger alert-dismissible messages error file-upload-js-error" aria-live="polite" role="alert">\
- <button type="button" class="close" data-dismiss="alert">\
- <span aria-hidden="true">×</span>\
- <span class="sr-only">Close</span>\
- </button>' + error + '</div>');
- this.value = '';
- return false;
- }
- }
- };
- }
- })(jQuery);
|