|
1 | 1 | /*
|
2 |
| - * jQuery File Upload User Interface Extended Plugin 4.3 |
| 2 | + * jQuery File Upload User Interface Extended Plugin 4.3.1 |
3 | 3 | * https://github.com/blueimp/jQuery-File-Upload
|
4 | 4 | *
|
5 | 5 | * Copyright 2010, Sebastian Tschan
|
|
25 | 25 | $(this).removeClass(
|
26 | 26 | 'ui-button ui-widget ui-state-default ui-corner-all' +
|
27 | 27 | ' ui-button-icon-only ui-button-text-icon-primary'
|
28 |
| - ).html($(this).children('.ui-button-text').text()); |
| 28 | + ).html($(this).text()); |
29 | 29 | } else {
|
30 | 30 | $(this)
|
31 | 31 | .addClass('ui-button ui-widget ui-state-default ui-corner-all')
|
|
48 | 48 |
|
49 | 49 | this.uploadDir = this.thumbnailsDir = null;
|
50 | 50 | this.autoUpload = true;
|
51 |
| - this.maxChunkSize = 10000000; |
| 51 | + this.continueAbortedUploads = false; |
52 | 52 | this.dropZone = container.find('form:first');
|
53 | 53 | this.uploadTable = container.find('.files:first');
|
54 | 54 | this.downloadTable = this.uploadTable;
|
55 | 55 | this.progressAllNode = container.find('.file_upload_overall_progress div:first');
|
56 | 56 | this.uploadTemplate = this.uploadTable.find('.file_upload_template:first');
|
57 | 57 | this.downloadTemplate = this.uploadTable.find('.file_download_template:first');
|
58 |
| - this.buttons = container.find('.file_upload_buttons:first'); |
| 58 | + this.multiButtons = container.find('.file_upload_buttons:first'); |
59 | 59 |
|
60 | 60 | this.formatFileSize = function (bytes) {
|
61 | 61 | if (typeof bytes !== 'number' || bytes === null) {
|
|
90 | 90 | this.buildUploadRow = function (files, index, handler) {
|
91 | 91 | var file = files[index],
|
92 | 92 | fileName = handler.formatFileName(file.name),
|
93 |
| - encodedFileName = encodeURIComponent(fileName), |
94 | 93 | uploadRow = handler.uploadTemplate
|
95 |
| - .clone().removeAttr('id') |
96 |
| - .attr('data-file-id', encodedFileName); |
| 94 | + .clone().removeAttr('id'); |
| 95 | + uploadRow.attr('data-name', file.name); |
| 96 | + uploadRow.attr('data-size', file.size); |
| 97 | + uploadRow.attr('data-type', file.type); |
97 | 98 | uploadRow.find('.file_name')
|
98 | 99 | .text(fileName);
|
99 | 100 | uploadRow.find('.file_size')
|
|
109 | 110 | return uploadRow;
|
110 | 111 | };
|
111 | 112 |
|
| 113 | + this.getFileUrl = function (file, handler) { |
| 114 | + return handler.uploadDir + encodeURIComponent(file.name); |
| 115 | + }; |
| 116 | + |
| 117 | + this.getThumbnailUrl = function (file, handler) { |
| 118 | + return handler.thumbnailsDir + encodeURIComponent(file.name); |
| 119 | + }; |
| 120 | + |
112 | 121 | this.buildDownloadRow = function (file, handler) {
|
113 |
| - var encodedFileName = encodeURIComponent(file.name), |
114 |
| - filePath = handler.uploadDir + encodedFileName, |
115 |
| - thumbnailPath = handler.thumbnailsDir + encodedFileName, |
| 122 | + var fileName = handler.formatFileName(file.name), |
| 123 | + fileUrl = handler.getFileUrl(file, handler), |
116 | 124 | downloadRow = handler.downloadTemplate
|
117 |
| - .clone().removeAttr('id') |
118 |
| - .attr('data-file-id', encodedFileName); |
| 125 | + .clone().removeAttr('id'); |
| 126 | + $.each(file, function (name, value) { |
| 127 | + downloadRow.attr('data-' + name, value); |
| 128 | + }); |
119 | 129 | downloadRow.find('.file_name a')
|
120 |
| - .text(file.name).attr('href', filePath); |
| 130 | + .attr('href', fileUrl) |
| 131 | + .text(fileName); |
121 | 132 | downloadRow.find('.file_size')
|
122 | 133 | .text(handler.formatFileSize(file.size));
|
123 | 134 | if (file.thumbnail) {
|
124 | 135 | downloadRow.find('.file_download_preview').append(
|
125 |
| - $('<a href="' + filePath + '"><img src="' + thumbnailPath + '"/></a>') |
| 136 | + $('<a href="' + fileUrl + '"><img src="' + |
| 137 | + handler.getThumbnailUrl(file, handler) + '"/></a>') |
126 | 138 | );
|
127 | 139 | downloadRow.find('a').attr('target', '_blank');
|
128 | 140 | }
|
|
134 | 146 | };
|
135 | 147 |
|
136 | 148 | this.uploadCallBack = function (event, files, index, xhr, handler, callBack) {
|
| 149 | + if (handler.autoUpload) { |
| 150 | + callBack(); |
| 151 | + } else { |
| 152 | + handler.uploadRow.find('.file_upload_start button').click(function (e) { |
| 153 | + $(this).fadeOut(); |
| 154 | + callBack(); |
| 155 | + e.preventDefault(); |
| 156 | + }); |
| 157 | + } |
| 158 | + }; |
| 159 | + |
| 160 | + this.continueUploadCallBack = function (event, files, index, xhr, handler, callBack) { |
137 | 161 | $.getJSON(
|
138 | 162 | handler.url,
|
139 |
| - {file: handler.uploadRow.attr('data-file-id')}, |
| 163 | + {file: handler.uploadRow.attr('data-name')}, |
140 | 164 | function (file) {
|
141 | 165 | if (file && file.size !== files[index].size) {
|
142 | 166 | handler.uploadedBytes = file.size;
|
143 | 167 | }
|
144 |
| - callBack(); |
| 168 | + handler.uploadCallBack(event, files, index, xhr, handler, callBack); |
145 | 169 | }
|
146 | 170 | );
|
147 | 171 | };
|
148 | 172 |
|
149 | 173 | this.beforeSend = function (event, files, index, xhr, handler, callBack) {
|
150 |
| - if (handler.autoUpload) { |
151 |
| - handler.uploadCallBack(event, files, index, xhr, handler, callBack); |
| 174 | + if (handler.continueAbortedUploads) { |
| 175 | + handler.continueUploadCallBack(event, files, index, xhr, handler, callBack); |
152 | 176 | } else {
|
153 |
| - handler.uploadRow.find('.file_upload_start button').click(function (e) { |
154 |
| - $(this).fadeOut(); |
155 |
| - handler.uploadCallBack(event, files, index, xhr, handler, callBack); |
156 |
| - e.preventDefault(); |
157 |
| - }); |
| 177 | + handler.uploadCallBack(event, files, index, xhr, handler, callBack); |
158 | 178 | }
|
159 | 179 | };
|
160 | 180 |
|
161 |
| - this.loadFiles = function () { |
162 |
| - $.getJSON(uploadHandler.url, function (files) { |
163 |
| - $.each(files, function (index, file) { |
164 |
| - uploadHandler.buildDownloadRow(file, uploadHandler) |
165 |
| - .appendTo(uploadHandler.downloadTable).fadeIn(); |
166 |
| - }); |
167 |
| - }); |
168 |
| - }; |
169 |
| - |
170 |
| - this.initExtended = function () { |
| 181 | + this.initDeleteHandler = function () { |
171 | 182 | container.find('.file_download_delete button').live('click', function (e) {
|
172 | 183 | var row = $(this).closest('tr');
|
173 |
| - $.ajax(uploadHandler.url + '?file=' + row.attr('data-file-id'), { |
| 184 | + $.ajax({ |
| 185 | + url: uploadHandler.url + '?file=' + encodeURIComponent( |
| 186 | + row.attr('data-id') || row.attr('data-name') |
| 187 | + ), |
174 | 188 | type: 'DELETE',
|
175 | 189 | success: function () {
|
176 | 190 | row.fadeOut(function () {
|
|
180 | 194 | });
|
181 | 195 | e.preventDefault();
|
182 | 196 | });
|
183 |
| - uploadHandler.buttons.find('.file_upload_start:first') |
184 |
| - .button({icons: {primary: 'ui-icon-circle-arrow-e'}}) |
185 |
| - .click(function (e) { |
186 |
| - uploadHandler.uploadTable.find('.file_upload_start button:visible').click(); |
187 |
| - e.preventDefault(); |
188 |
| - }); |
189 |
| - uploadHandler.buttons.find('.file_upload_cancel:first') |
| 197 | + }; |
| 198 | + |
| 199 | + this.initMultiButtons = function () { |
| 200 | + if (uploadHandler.autoUpload) { |
| 201 | + uploadHandler.multiButtons.find('.file_upload_start:first').hide(); |
| 202 | + } else { |
| 203 | + uploadHandler.multiButtons.find('.file_upload_start:first') |
| 204 | + .button({icons: {primary: 'ui-icon-circle-arrow-e'}}) |
| 205 | + .click(function (e) { |
| 206 | + uploadHandler.uploadTable.find('.file_upload_start button:visible').click(); |
| 207 | + e.preventDefault(); |
| 208 | + }); |
| 209 | + } |
| 210 | + uploadHandler.multiButtons.find('.file_upload_cancel:first') |
190 | 211 | .button({icons: {primary: 'ui-icon-cancel'}})
|
191 | 212 | .click(function (e) {
|
192 | 213 | uploadHandler.uploadTable.find('.file_upload_cancel button:visible').click();
|
193 | 214 | e.preventDefault();
|
194 | 215 | });
|
195 |
| - uploadHandler.buttons.find('.file_download_delete:first') |
| 216 | + uploadHandler.multiButtons.find('.file_download_delete:first') |
196 | 217 | .button({icons: {primary: 'ui-icon-trash'}})
|
197 | 218 | .click(function (e) {
|
198 | 219 | uploadHandler.downloadTable.find('.file_download_delete button:visible').click();
|
199 | 220 | e.preventDefault();
|
200 | 221 | });
|
| 222 | + }; |
| 223 | + |
| 224 | + this.loadFiles = function () { |
| 225 | + $.getJSON(uploadHandler.url, function (files) { |
| 226 | + $.each(files, function (index, file) { |
| 227 | + uploadHandler.buildDownloadRow(file, uploadHandler) |
| 228 | + .appendTo(uploadHandler.downloadTable).fadeIn(); |
| 229 | + }); |
| 230 | + }); |
| 231 | + }; |
| 232 | + |
| 233 | + this.initExtended = function () { |
| 234 | + uploadHandler.initDeleteHandler(); |
| 235 | + uploadHandler.initMultiButtons(); |
201 | 236 | if (uploadHandler.loadFiles) {
|
202 | 237 | uploadHandler.loadFiles();
|
203 | 238 | }
|
204 | 239 | };
|
205 | 240 |
|
206 | 241 | this.destroyExtended = function () {
|
207 | 242 | container.find('.file_download_delete button').die('click');
|
208 |
| - uploadHandler.buttons.find('.file_upload_start:first').button('destroy'); |
209 |
| - uploadHandler.buttons.find('.file_upload_cancel:first').button('destroy'); |
210 |
| - uploadHandler.buttons.find('.file_download_delete:first').button('destroy'); |
| 243 | + uploadHandler.multiButtons.find('.file_upload_start:first').button('destroy').show(); |
| 244 | + uploadHandler.multiButtons.find('.file_upload_cancel:first').button('destroy'); |
| 245 | + uploadHandler.multiButtons.find('.file_download_delete:first').button('destroy'); |
211 | 246 | };
|
212 | 247 |
|
213 | 248 | $.extend(this, options);
|
|
0 commit comments