1 |
85ad3d82
|
Assos Assos
|
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
|
5 |
|
|
|
6 |
|
|
|
7 |
|
|
|
8 |
|
|
|
9 |
|
|
|
10 |
|
|
(function ($) {
|
11 |
|
|
|
12 |
|
|
|
13 |
|
|
|
14 |
|
|
|
15 |
|
|
Drupal.behaviors.fileValidateAutoAttach = {
|
16 |
|
|
attach: function (context, settings) {
|
17 |
|
|
if (settings.file && settings.file.elements) {
|
18 |
|
|
$.each(settings.file.elements, function(selector) {
|
19 |
|
|
var extensions = settings.file.elements[selector];
|
20 |
|
|
$(selector, context).bind('change', {extensions: extensions}, Drupal.file.validateExtension);
|
21 |
|
|
});
|
22 |
|
|
}
|
23 |
|
|
},
|
24 |
|
|
detach: function (context, settings) {
|
25 |
|
|
if (settings.file && settings.file.elements) {
|
26 |
|
|
$.each(settings.file.elements, function(selector) {
|
27 |
|
|
$(selector, context).unbind('change', Drupal.file.validateExtension);
|
28 |
|
|
});
|
29 |
|
|
}
|
30 |
|
|
}
|
31 |
|
|
};
|
32 |
|
|
|
33 |
|
|
|
34 |
|
|
|
35 |
|
|
|
36 |
|
|
Drupal.behaviors.fileButtons = {
|
37 |
|
|
attach: function (context) {
|
38 |
|
|
$('input.form-submit', context).bind('mousedown', Drupal.file.disableFields);
|
39 |
|
|
$('div.form-managed-file input.form-submit', context).bind('mousedown', Drupal.file.progressBar);
|
40 |
|
|
},
|
41 |
|
|
detach: function (context) {
|
42 |
|
|
$('input.form-submit', context).unbind('mousedown', Drupal.file.disableFields);
|
43 |
|
|
$('div.form-managed-file input.form-submit', context).unbind('mousedown', Drupal.file.progressBar);
|
44 |
|
|
}
|
45 |
|
|
};
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
|
49 |
|
|
|
50 |
|
|
Drupal.behaviors.filePreviewLinks = {
|
51 |
|
|
attach: function (context) {
|
52 |
|
|
$('div.form-managed-file .file a, .file-widget .file a', context).bind('click',Drupal.file.openInNewWindow);
|
53 |
|
|
},
|
54 |
|
|
detach: function (context){
|
55 |
|
|
$('div.form-managed-file .file a, .file-widget .file a', context).unbind('click', Drupal.file.openInNewWindow);
|
56 |
|
|
}
|
57 |
|
|
};
|
58 |
|
|
|
59 |
|
|
|
60 |
|
|
|
61 |
|
|
|
62 |
|
|
Drupal.file = Drupal.file || {
|
63 |
|
|
|
64 |
|
|
|
65 |
|
|
|
66 |
|
|
validateExtension: function (event) {
|
67 |
|
|
|
68 |
|
|
$('.file-upload-js-error').remove();
|
69 |
|
|
|
70 |
|
|
|
71 |
|
|
var extensionPattern = event.data.extensions.replace(/,\s*/g, '|');
|
72 |
|
|
if (extensionPattern.length > 1 && this.value.length > 0) {
|
73 |
|
|
var acceptableMatch = new RegExp('\\.(' + extensionPattern + ')$', 'gi');
|
74 |
|
|
if (!acceptableMatch.test(this.value)) {
|
75 |
|
|
var error = Drupal.t("The selected file %filename cannot be uploaded. Only files with the following extensions are allowed: %extensions.", {
|
76 |
|
|
|
77 |
|
|
|
78 |
|
|
|
79 |
|
|
|
80 |
|
|
|
81 |
|
|
|
82 |
|
|
|
83 |
|
|
'%filename': this.value.replace('C:\\fakepath\\', ''),
|
84 |
|
|
'%extensions': extensionPattern.replace(/\|/g, ', ')
|
85 |
|
|
});
|
86 |
4444412d
|
Julien Enselme
|
$(this).closest('div.form-managed-file').prepend('<div class="messages error file-upload-js-error" aria-live="polite">' + error + '</div>');
|
87 |
85ad3d82
|
Assos Assos
|
this.value = '';
|
88 |
|
|
return false;
|
89 |
|
|
}
|
90 |
|
|
}
|
91 |
|
|
},
|
92 |
|
|
|
93 |
|
|
|
94 |
|
|
|
95 |
|
|
disableFields: function (event){
|
96 |
|
|
var clickedButton = this;
|
97 |
|
|
|
98 |
|
|
|
99 |
|
|
if (!$(clickedButton).hasClass('ajax-processed')) {
|
100 |
|
|
return;
|
101 |
|
|
}
|
102 |
|
|
|
103 |
|
|
|
104 |
|
|
var $enabledFields = [];
|
105 |
|
|
if ($(this).closest('div.form-managed-file').length > 0) {
|
106 |
|
|
$enabledFields = $(this).closest('div.form-managed-file').find('input.form-file');
|
107 |
|
|
}
|
108 |
|
|
|
109 |
|
|
|
110 |
|
|
|
111 |
|
|
|
112 |
|
|
|
113 |
|
|
|
114 |
|
|
|
115 |
|
|
|
116 |
|
|
|
117 |
|
|
var $fieldsToTemporarilyDisable = $('div.form-managed-file input.form-file').not($enabledFields).not(':disabled');
|
118 |
|
|
$fieldsToTemporarilyDisable.attr('disabled', 'disabled');
|
119 |
|
|
setTimeout(function (){
|
120 |
|
|
$fieldsToTemporarilyDisable.attr('disabled', false);
|
121 |
|
|
}, 1000);
|
122 |
|
|
},
|
123 |
|
|
|
124 |
|
|
|
125 |
|
|
|
126 |
|
|
progressBar: function (event) {
|
127 |
|
|
var clickedButton = this;
|
128 |
|
|
var $progressId = $(clickedButton).closest('div.form-managed-file').find('input.file-progress');
|
129 |
|
|
if ($progressId.length) {
|
130 |
|
|
var originalName = $progressId.attr('name');
|
131 |
|
|
|
132 |
|
|
|
133 |
|
|
$progressId.attr('name', originalName.match(/APC_UPLOAD_PROGRESS|UPLOAD_IDENTIFIER/)[0]);
|
134 |
|
|
|
135 |
|
|
|
136 |
|
|
setTimeout(function () {
|
137 |
|
|
$progressId.attr('name', originalName);
|
138 |
|
|
}, 1000);
|
139 |
|
|
}
|
140 |
|
|
|
141 |
|
|
setTimeout(function () {
|
142 |
|
|
$(clickedButton).closest('div.form-managed-file').find('div.ajax-progress-bar').slideDown();
|
143 |
|
|
}, 500);
|
144 |
|
|
},
|
145 |
|
|
|
146 |
|
|
|
147 |
|
|
|
148 |
|
|
openInNewWindow: function (event) {
|
149 |
|
|
$(this).attr('target', '_blank');
|
150 |
|
|
window.open(this.href, 'filePreview', 'toolbar=0,scrollbars=1,location=1,statusbar=1,menubar=0,resizable=1,width=500,height=550');
|
151 |
|
|
return false;
|
152 |
|
|
}
|
153 |
|
|
};
|
154 |
|
|
|
155 |
|
|
})(jQuery); |