123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- (function ($) {
- Drupal.behaviors.fileValidateAutoAttach = {
- attach: function (context, settings) {
- if (settings.file && settings.file.elements) {
- $.each(settings.file.elements, function(selector) {
- var extensions = settings.file.elements[selector];
- $(selector, context).bind('change', {extensions: extensions}, Drupal.file.validateExtension);
- });
- }
- },
- detach: function (context, settings) {
- if (settings.file && settings.file.elements) {
- $.each(settings.file.elements, function(selector) {
- $(selector, context).unbind('change', Drupal.file.validateExtension);
- });
- }
- }
- };
- 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);
- }
- };
- Drupal.behaviors.filePreviewLinks = {
- attach: function (context) {
- $('div.form-managed-file .file a, .file-widget .file a', context).bind('click',Drupal.file.openInNewWindow);
- },
- detach: function (context){
- $('div.form-managed-file .file a, .file-widget .file a', context).unbind('click', Drupal.file.openInNewWindow);
- }
- };
- Drupal.file = 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').prepend('<div class="messages error file-upload-js-error" aria-live="polite">' + error + '</div>');
- this.value = '';
- return false;
- }
- }
- },
-
- 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);
- },
-
- 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);
- },
-
- openInNewWindow: function (event) {
- $(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');
- return false;
- }
- };
- })(jQuery);
|