c80_contest 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.rspec +2 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +5 -0
  7. data/CODE_OF_CONDUCT.md +74 -0
  8. data/Gemfile +4 -0
  9. data/LICENSE.txt +21 -0
  10. data/MIT-LICENSE +20 -0
  11. data/README.md +32 -0
  12. data/README.rdoc +3 -0
  13. data/Rakefile +23 -0
  14. data/app/admin/c80_contest/bids.rb +28 -0
  15. data/app/assets/images/c80_contest/.keep +0 -0
  16. data/app/assets/images/loading-sm.gif +0 -0
  17. data/app/assets/images/loading.gif +0 -0
  18. data/app/assets/javascripts/c80_contest/frontend/ajax_bid_form.js +157 -0
  19. data/app/assets/javascripts/c80_contest.js.coffee +2 -0
  20. data/app/assets/javascripts/lib/fileinput/fileinput.js +3833 -0
  21. data/app/assets/javascripts/lib/fileinput/themes/explorer/theme.js +58 -0
  22. data/app/assets/javascripts/lib/fileinput/themes/fa/theme.js +45 -0
  23. data/app/assets/javascripts/lib/fileinput/themes/gly/theme.js +45 -0
  24. data/app/assets/stylesheets/c80_contest/backend/bid_page.scss +22 -0
  25. data/app/assets/stylesheets/c80_contest/frontend/foo.scss +0 -0
  26. data/app/assets/stylesheets/c80_contest.scss +3 -0
  27. data/app/assets/stylesheets/c80_contest_active_admin.scss +2 -0
  28. data/app/assets/stylesheets/lib/fileinput/fileinput.scss +481 -0
  29. data/app/assets/stylesheets/lib/fileinput/themes/explorer/theme.scss +211 -0
  30. data/app/controllers/c80_contest/application_controller.rb +5 -0
  31. data/app/controllers/c80_contest/bid_controller.rb +26 -0
  32. data/app/controllers/c80_contest/site_controller.rb +13 -0
  33. data/app/helpers/c80_contest/application_helper.rb +26 -0
  34. data/app/models/c80_contest/bid.rb +17 -0
  35. data/app/models/c80_contest/setting.rb +53 -0
  36. data/app/uploaders/c80_contest/bid_photo_uploader.rb +32 -0
  37. data/app/views/c80_contest/bid/make_bid.js.erb +4 -0
  38. data/app/views/c80_contest/shared/_bid_form.html.erb +65 -0
  39. data/app/views/c80_contest/shared/_ok_message.html.erb +16 -0
  40. data/app/views/c80_contest/site/give_me_form.js.erb +4 -0
  41. data/app/views/layouts/c80_contest/application.html.erb +14 -0
  42. data/bin/console +14 -0
  43. data/bin/rails +12 -0
  44. data/bin/setup +8 -0
  45. data/c80_contest.gemspec +46 -0
  46. data/config/routes.rb +4 -0
  47. data/create_base.rb +25 -0
  48. data/db/migrate/20170510124400_create_c80_contest_bids.rb +12 -0
  49. data/db/migrate/20170511145501_create_c80_contest_settings.rb +19 -0
  50. data/db/seeds/c80_contest_fill_settings.rb +22 -0
  51. data/lib/c80_contest/engine.rb +20 -0
  52. data/lib/c80_contest/version.rb +3 -0
  53. data/lib/c80_contest.rb +8 -0
  54. data/lib/tasks/c80_contest_tasks.rake +4 -0
  55. metadata +335 -0
@@ -0,0 +1,3833 @@
1
+ /*!
2
+ * bootstrap-fileinput v4.4.0
3
+ * http://plugins.krajee.com/file-input
4
+ *
5
+ * Author: Kartik Visweswaran
6
+ * Copyright: 2014 - 2017, Kartik Visweswaran, Krajee.com
7
+ *
8
+ * Licensed under the BSD 3-Clause
9
+ * https://github.com/kartik-v/bootstrap-fileinput/blob/master/LICENSE.md
10
+ */
11
+ (function (factory) {
12
+ "use strict";
13
+ //noinspection JSUnresolvedVariable
14
+ if (typeof define === 'function' && define.amd) { // jshint ignore:line
15
+ // AMD. Register as an anonymous module.
16
+ define(['jquery'], factory); // jshint ignore:line
17
+ } else { // noinspection JSUnresolvedVariable
18
+ if (typeof module === 'object' && module.exports) { // jshint ignore:line
19
+ // Node/CommonJS
20
+ // noinspection JSUnresolvedVariable
21
+ module.exports = factory(require('jquery')); // jshint ignore:line
22
+ } else {
23
+ // Browser globals
24
+ factory(window.jQuery);
25
+ }
26
+ }
27
+ }(function ($) {
28
+ "use strict";
29
+
30
+ $.fn.fileinputLocales = {};
31
+ $.fn.fileinputThemes = {};
32
+
33
+ String.prototype.setTokens = function (replacePairs) {
34
+ var str = this.toString(), key, re;
35
+ for (key in replacePairs) {
36
+ if (replacePairs.hasOwnProperty(key)) {
37
+ re = new RegExp("\{" + key + "\}", "g");
38
+ str = str.replace(re, replacePairs[key]);
39
+ }
40
+ }
41
+ return str;
42
+ };
43
+
44
+ var $h, FileInput;
45
+
46
+ // fileinput helper object for all global variables and internal helper methods
47
+ //noinspection JSUnresolvedVariable
48
+ $h = {
49
+ FRAMES: '.kv-preview-thumb',
50
+ SORT_CSS: 'file-sortable',
51
+ STYLE_SETTING: 'style="width:{width};height:{height};"',
52
+ OBJECT_PARAMS: '<param name="controller" value="true" />\n' +
53
+ '<param name="allowFullScreen" value="true" />\n' +
54
+ '<param name="allowScriptAccess" value="always" />\n' +
55
+ '<param name="autoPlay" value="false" />\n' +
56
+ '<param name="autoStart" value="false" />\n' +
57
+ '<param name="quality" value="high" />\n',
58
+ DEFAULT_PREVIEW: '<div class="file-preview-other">\n' +
59
+ '<span class="{previewFileIconClass}">{previewFileIcon}</span>\n' +
60
+ '</div>',
61
+ MODAL_ID: 'kvFileinputModal',
62
+ MODAL_EVENTS: ['show', 'shown', 'hide', 'hidden', 'loaded'],
63
+ objUrl: window.URL || window.webkitURL,
64
+ compare: function (input, str, exact) {
65
+ return input !== undefined && (exact ? input === str : input.match(str));
66
+ },
67
+ isIE: function (ver) {
68
+ // check for IE versions < 11
69
+ if (navigator.appName !== 'Microsoft Internet Explorer') {
70
+ return false;
71
+ }
72
+ if (ver === 10) {
73
+ return new RegExp('msie\\s' + ver, 'i').test(navigator.userAgent);
74
+ }
75
+ var div = document.createElement("div"), status;
76
+ div.innerHTML = "<!--[if IE " + ver + "]> <i></i> <![endif]-->";
77
+ status = div.getElementsByTagName("i").length;
78
+ document.body.appendChild(div);
79
+ div.parentNode.removeChild(div);
80
+ return status;
81
+ },
82
+ initModal: function ($modal) {
83
+ var $body = $('body');
84
+ if ($body.length) {
85
+ $modal.appendTo($body);
86
+ }
87
+ },
88
+ isEmpty: function (value, trim) {
89
+ return value === undefined || value === null || value.length === 0 || (trim && $.trim(value) === '');
90
+ },
91
+ isArray: function (a) {
92
+ return Array.isArray(a) || Object.prototype.toString.call(a) === '[object Array]';
93
+ },
94
+ ifSet: function (needle, haystack, def) {
95
+ def = def || '';
96
+ return (haystack && typeof haystack === 'object' && needle in haystack) ? haystack[needle] : def;
97
+ },
98
+ cleanArray: function (arr) {
99
+ if (!(arr instanceof Array)) {
100
+ arr = [];
101
+ }
102
+ return arr.filter(function (e) {
103
+ return (e !== undefined && e !== null);
104
+ });
105
+ },
106
+ spliceArray: function (arr, index) {
107
+ var i, j = 0, out = [];
108
+ if (!(arr instanceof Array)) {
109
+ return [];
110
+ }
111
+ for (i = 0; i < arr.length; i++) {
112
+ if (i !== index) {
113
+ out[j] = arr[i];
114
+ j++;
115
+ }
116
+ }
117
+ return out;
118
+ },
119
+ getNum: function (num, def) {
120
+ def = def || 0;
121
+ if (typeof num === "number") {
122
+ return num;
123
+ }
124
+ if (typeof num === "string") {
125
+ num = parseFloat(num);
126
+ }
127
+ return isNaN(num) ? def : num;
128
+ },
129
+ hasFileAPISupport: function () {
130
+ return !!(window.File && window.FileReader);
131
+ },
132
+ hasDragDropSupport: function () {
133
+ var div = document.createElement('div');
134
+ /** @namespace div.draggable */
135
+ /** @namespace div.ondragstart */
136
+ /** @namespace div.ondrop */
137
+ return !$h.isIE(9) &&
138
+ (div.draggable !== undefined || (div.ondragstart !== undefined && div.ondrop !== undefined));
139
+ },
140
+ hasFileUploadSupport: function () {
141
+ return $h.hasFileAPISupport() && window.FormData;
142
+ },
143
+ addCss: function ($el, css) {
144
+ $el.removeClass(css).addClass(css);
145
+ },
146
+ getElement: function (options, param, value) {
147
+ return ($h.isEmpty(options) || $h.isEmpty(options[param])) ? value : $(options[param]);
148
+ },
149
+ uniqId: function () {
150
+ return Math.round(new Date().getTime() + (Math.random() * 100));
151
+ },
152
+ htmlEncode: function (str) {
153
+ return str.replace(/&/g, '&amp;')
154
+ .replace(/</g, '&lt;')
155
+ .replace(/>/g, '&gt;')
156
+ .replace(/"/g, '&quot;')
157
+ .replace(/'/g, '&apos;');
158
+ },
159
+ replaceTags: function (str, tags) {
160
+ var out = str;
161
+ if (!tags) {
162
+ return out;
163
+ }
164
+ $.each(tags, function (key, value) {
165
+ if (typeof value === "function") {
166
+ value = value();
167
+ }
168
+ out = out.split(key).join(value);
169
+ });
170
+ return out;
171
+ },
172
+ cleanMemory: function ($thumb) {
173
+ var data = $thumb.is('img') ? $thumb.attr('src') : $thumb.find('source').attr('src');
174
+ /** @namespace $h.objUrl.revokeObjectURL */
175
+ $h.objUrl.revokeObjectURL(data);
176
+ },
177
+ findFileName: function (filePath) {
178
+ var sepIndex = filePath.lastIndexOf('/');
179
+ if (sepIndex === -1) {
180
+ sepIndex = filePath.lastIndexOf('\\');
181
+ }
182
+ return filePath.split(filePath.substring(sepIndex, sepIndex + 1)).pop();
183
+ },
184
+ checkFullScreen: function () {
185
+ //noinspection JSUnresolvedVariable
186
+ return document.fullscreenElement || document.mozFullScreenElement || document.webkitFullscreenElement ||
187
+ document.msFullscreenElement;
188
+ },
189
+ toggleFullScreen: function (maximize) {
190
+ var doc = document, de = doc.documentElement;
191
+ if (de && maximize && !$h.checkFullScreen()) {
192
+ /** @namespace document.requestFullscreen */
193
+ /** @namespace document.msRequestFullscreen */
194
+ /** @namespace document.mozRequestFullScreen */
195
+ /** @namespace document.webkitRequestFullscreen */
196
+ /** @namespace Element.ALLOW_KEYBOARD_INPUT */
197
+ if (de.requestFullscreen) {
198
+ de.requestFullscreen();
199
+ } else if (de.msRequestFullscreen) {
200
+ de.msRequestFullscreen();
201
+ } else if (de.mozRequestFullScreen) {
202
+ de.mozRequestFullScreen();
203
+ } else if (de.webkitRequestFullscreen) {
204
+ de.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
205
+ }
206
+ } else {
207
+ /** @namespace document.exitFullscreen */
208
+ /** @namespace document.msExitFullscreen */
209
+ /** @namespace document.mozCancelFullScreen */
210
+ /** @namespace document.webkitExitFullscreen */
211
+ if (doc.exitFullscreen) {
212
+ doc.exitFullscreen();
213
+ } else if (doc.msExitFullscreen) {
214
+ doc.msExitFullscreen();
215
+ } else if (doc.mozCancelFullScreen) {
216
+ doc.mozCancelFullScreen();
217
+ } else if (doc.webkitExitFullscreen) {
218
+ doc.webkitExitFullscreen();
219
+ }
220
+ }
221
+ },
222
+ moveArray: function (arr, oldIndex, newIndex) {
223
+ if (newIndex >= arr.length) {
224
+ var k = newIndex - arr.length;
225
+ while ((k--) + 1) {
226
+ arr.push(undefined);
227
+ }
228
+ }
229
+ arr.splice(newIndex, 0, arr.splice(oldIndex, 1)[0]);
230
+ return arr;
231
+ },
232
+ cleanZoomCache: function ($el) {
233
+ var $cache = $el.closest('.kv-zoom-cache-theme');
234
+ if (!$cache.length) {
235
+ $cache = $el.closest('.kv-zoom-cache');
236
+ }
237
+ $cache.remove();
238
+ },
239
+ setOrientation: function (buffer, callback) {
240
+ var scanner = new DataView(buffer), idx = 0, value = 1, // Non-rotated is the default
241
+ maxBytes, uInt16, exifLength;
242
+ if (scanner.getUint16(idx) !== 0xFFD8 || buffer.length < 2) {
243
+ return; // not a proper JPEG
244
+ }
245
+ idx += 2;
246
+ maxBytes = scanner.byteLength;
247
+ while (idx < maxBytes - 2) {
248
+ uInt16 = scanner.getUint16(idx);
249
+ idx += 2;
250
+ switch (uInt16) {
251
+ case 0xFFE1: // Start of EXIF
252
+ exifLength = scanner.getUint16(idx);
253
+ maxBytes = exifLength - idx;
254
+ idx += 2;
255
+ break;
256
+ case 0x0112: // Orientation tag
257
+ value = scanner.getUint16(idx + 6, false);
258
+ maxBytes = 0; // Stop scanning
259
+ break;
260
+ }
261
+ }
262
+ if (callback) {
263
+ callback(value);
264
+ }
265
+ },
266
+ validateOrientation: function (file, callback) {
267
+ if (!window.FileReader || !window.DataView) {
268
+ return; // skip orientation if pre-requisite libraries not supported by browser
269
+ }
270
+ var reader = new FileReader(), buffer;
271
+ reader.onloadend = function () {
272
+ buffer = reader.result;
273
+ $h.setOrientation(buffer, callback);
274
+ };
275
+ reader.readAsArrayBuffer(file);
276
+ },
277
+ adjustOrientedImage: function ($img, isZoom) {
278
+ var offsetContTop, offsetTop, newTop;
279
+ if (!$img.hasClass('is-portrait-gt4')) {
280
+ return;
281
+ }
282
+ if (isZoom) {
283
+ $img.css({width: $img.parent().height()});
284
+ return;
285
+ } else {
286
+ $img.css({height: 'auto', width: $img.height()});
287
+ }
288
+ offsetContTop = $img.parent().offset().top;
289
+ offsetTop = $img.offset().top;
290
+ newTop = offsetContTop - offsetTop;
291
+ $img.css('margin-top', newTop);
292
+ }
293
+ };
294
+ FileInput = function (element, options) {
295
+ var self = this;
296
+ self.$element = $(element);
297
+ if (!self._validate()) {
298
+ return;
299
+ }
300
+ self.isPreviewable = $h.hasFileAPISupport();
301
+ self.isIE9 = $h.isIE(9);
302
+ self.isIE10 = $h.isIE(10);
303
+ if (self.isPreviewable || self.isIE9) {
304
+ self._init(options);
305
+ self._listen();
306
+ } else {
307
+ self.$element.removeClass('file-loading');
308
+ }
309
+ };
310
+ FileInput.prototype = {
311
+ constructor: FileInput,
312
+ _cleanup: function() {
313
+ var self = this;
314
+ self.reader = null;
315
+ self.formdata = {};
316
+ self.uploadCount = 0;
317
+ self.uploadStatus = {};
318
+ self.uploadLog = [];
319
+ self.uploadAsyncCount = 0;
320
+ self.loadedImages = [];
321
+ self.totalImagesCount = 0;
322
+ self.ajaxRequests = [];
323
+ self.clearStack();
324
+ self.fileInputCleared = false;
325
+ self.fileBatchCompleted = true;
326
+ if (!self.isPreviewable) {
327
+ self.showPreview = false;
328
+ }
329
+ self.isError = false;
330
+ self.ajaxAborted = false;
331
+ self.cancelling = false;
332
+ },
333
+ _init: function (options) {
334
+ var self = this, $el = self.$element, $cont, t;
335
+ self.options = options;
336
+ $.each(options, function (key, value) {
337
+ switch (key) {
338
+ case 'minFileCount':
339
+ case 'maxFileCount':
340
+ case 'minFileSize':
341
+ case 'maxFileSize':
342
+ case 'maxFilePreviewSize':
343
+ case 'resizeImageQuality':
344
+ case 'resizeIfSizeMoreThan':
345
+ case 'progressUploadThreshold':
346
+ case 'initialPreviewCount':
347
+ case 'zoomModalHeight':
348
+ case 'minImageHeight':
349
+ case 'maxImageHeight':
350
+ case 'minImageWidth':
351
+ case 'maxImageWidth':
352
+ self[key] = $h.getNum(value);
353
+ break;
354
+ default:
355
+ self[key] = value;
356
+ break;
357
+ }
358
+ });
359
+ self._cleanup();
360
+ self.$form = $el.closest('form');
361
+ self._initTemplateDefaults();
362
+ self.uploadFileAttr = !$h.isEmpty($el.attr('name')) ? $el.attr('name') : 'file_data';
363
+ t = self._getLayoutTemplate('progress');
364
+ self.progressTemplate = t.replace('{class}', self.progressClass);
365
+ self.progressCompleteTemplate = t.replace('{class}', self.progressCompleteClass);
366
+ self.progressErrorTemplate = t.replace('{class}', self.progressErrorClass);
367
+ self.dropZoneEnabled = $h.hasDragDropSupport() && self.dropZoneEnabled;
368
+ self.isDisabled = $el.attr('disabled') || $el.attr('readonly');
369
+ if (self.isDisabled) {
370
+ $el.attr('disabled', true);
371
+ }
372
+ self.isUploadable = $h.hasFileUploadSupport() && !$h.isEmpty(self.uploadUrl);
373
+ self.isClickable = self.browseOnZoneClick && self.showPreview &&
374
+ (self.isUploadable && self.dropZoneEnabled || !$h.isEmpty(self.defaultPreviewContent));
375
+ self.slug = typeof options.slugCallback === "function" ? options.slugCallback : self._slugDefault;
376
+ self.mainTemplate = self.showCaption ? self._getLayoutTemplate('main1') : self._getLayoutTemplate('main2');
377
+ self.captionTemplate = self._getLayoutTemplate('caption');
378
+ self.previewGenericTemplate = self._getPreviewTemplate('generic');
379
+ if (self.resizeImage && (self.maxImageWidth || self.maxImageHeight)) {
380
+ self.imageCanvas = document.createElement('canvas');
381
+ self.imageCanvasContext = self.imageCanvas.getContext('2d');
382
+ }
383
+ if ($h.isEmpty($el.attr('id'))) {
384
+ $el.attr('id', $h.uniqId());
385
+ }
386
+ self.namespace = '.fileinput_' + $el.attr('id').replace(/-/g, '_');
387
+ if (self.$container === undefined) {
388
+ self.$container = self._createContainer();
389
+ } else {
390
+ self._refreshContainer();
391
+ }
392
+ $cont = self.$container;
393
+ self.$dropZone = $cont.find('.file-drop-zone');
394
+ self.$progress = $cont.find('.kv-upload-progress');
395
+ self.$btnUpload = $cont.find('.fileinput-upload');
396
+ self.$captionContainer = $h.getElement(options, 'elCaptionContainer', $cont.find('.file-caption'));
397
+ self.$caption = $h.getElement(options, 'elCaptionText', $cont.find('.file-caption-name'));
398
+ self.$previewContainer = $h.getElement(options, 'elPreviewContainer', $cont.find('.file-preview'));
399
+ self.$preview = $h.getElement(options, 'elPreviewImage', $cont.find('.file-preview-thumbnails'));
400
+ self.$previewStatus = $h.getElement(options, 'elPreviewStatus', $cont.find('.file-preview-status'));
401
+ self.$errorContainer = $h.getElement(options, 'elErrorContainer',
402
+ self.$previewContainer.find('.kv-fileinput-error'));
403
+ if (!$h.isEmpty(self.msgErrorClass)) {
404
+ $h.addCss(self.$errorContainer, self.msgErrorClass);
405
+ }
406
+ self.$errorContainer.hide();
407
+ self.previewInitId = "preview-" + $h.uniqId();
408
+ self._initPreviewCache();
409
+ self._initPreview(true);
410
+ self._initPreviewActions();
411
+ self._setFileDropZoneTitle();
412
+ $el.removeClass('file-loading');
413
+ if ($el.attr('disabled')) {
414
+ self.disable();
415
+ }
416
+ self._initZoom();
417
+ },
418
+ _initTemplateDefaults: function () {
419
+ var self = this, tMain1, tMain2, tPreview, tFileIcon, tClose, tCaption, tBtnDefault, tBtnLink, tBtnBrowse,
420
+ tModalMain, tModal, tProgress, tSize, tFooter, tActions, tActionDelete, tActionUpload, tActionZoom,
421
+ tActionDrag, tIndicator, tTagBef, tTagBef1, tTagBef2, tTagAft, tGeneric, tHtml, tImage, tText, tVideo,
422
+ tAudio, tFlash, tObject, tPdf, tOther, tZoomCache, vDefaultDim;
423
+ tMain1 = '{preview}\n' +
424
+ '<div class="kv-upload-progress hide"></div>\n' +
425
+ '<div class="input-group {class}">\n' +
426
+ ' {caption}\n' +
427
+ ' <div class="input-group-btn">\n' +
428
+ ' {remove}\n' +
429
+ ' {cancel}\n' +
430
+ ' {upload}\n' +
431
+ ' {browse}\n' +
432
+ ' </div>\n' +
433
+ '</div>';
434
+ tMain2 = '{preview}\n<div class="kv-upload-progress hide"></div>\n{remove}\n{cancel}\n{upload}\n{browse}\n';
435
+ tPreview = '<div class="file-preview {class}">\n' +
436
+ ' {close}' +
437
+ ' <div class="{dropClass}">\n' +
438
+ ' <div class="file-preview-thumbnails">\n' +
439
+ ' </div>\n' +
440
+ ' <div class="clearfix"></div>' +
441
+ ' <div class="file-preview-status text-center text-success"></div>\n' +
442
+ ' <div class="kv-fileinput-error"></div>\n' +
443
+ ' </div>\n' +
444
+ '</div>';
445
+ tClose = '<div class="close fileinput-remove">&times;</div>\n';
446
+ tFileIcon = '<i class="glyphicon glyphicon-file kv-caption-icon"></i>';
447
+ tCaption = '<div tabindex="500" class="form-control file-caption {class}">\n' +
448
+ ' <div class="file-caption-name"></div>\n' +
449
+ '</div>\n';
450
+ //noinspection HtmlUnknownAttribute
451
+ tBtnDefault = '<button type="{type}" tabindex="500" title="{title}" class="{css}" ' +
452
+ '{status}>{icon} {label}</button>';
453
+ //noinspection HtmlUnknownAttribute
454
+ tBtnLink = '<a href="{href}" tabindex="500" title="{title}" class="{css}" {status}>{icon} {label}</a>';
455
+ //noinspection HtmlUnknownAttribute
456
+ tBtnBrowse = '<div tabindex="500" class="{css}" {status}>{icon} {label}</div>';
457
+ tModalMain = '<div id="' + $h.MODAL_ID + '" class="file-zoom-dialog modal fade" ' +
458
+ 'tabindex="-1" aria-labelledby="' + $h.MODAL_ID + 'Label"></div>';
459
+ tModal = '<div class="modal-dialog modal-lg" role="document">\n' +
460
+ ' <div class="modal-content">\n' +
461
+ ' <div class="modal-header">\n' +
462
+ ' <div class="kv-zoom-actions pull-right">{toggleheader}{fullscreen}{borderless}{close}</div>\n' +
463
+ ' <h3 class="modal-title">{heading} <small><span class="kv-zoom-title"></span></small></h3>\n' +
464
+ ' </div>\n' +
465
+ ' <div class="modal-body">\n' +
466
+ ' <div class="floating-buttons"></div>\n' +
467
+ ' <div class="kv-zoom-body file-zoom-content {zoomFrameClass}"></div>\n' + '{prev} {next}\n' +
468
+ ' </div>\n' +
469
+ ' </div>\n' +
470
+ '</div>\n';
471
+ tProgress = '<div class="progress">\n' +
472
+ ' <div class="{class}" role="progressbar"' +
473
+ ' aria-valuenow="{percent}" aria-valuemin="0" aria-valuemax="100" style="width:{percent}%;">\n' +
474
+ ' {status}\n' +
475
+ ' </div>\n' +
476
+ '</div>';
477
+ tSize = ' <samp>({sizeText})</samp>';
478
+ tFooter = '<div class="file-thumbnail-footer">\n' +
479
+ ' <div class="file-footer-caption" title="{caption}">{caption}<br>{size}</div>\n' +
480
+ ' {progress} {indicator} {actions}\n' +
481
+ '</div>';
482
+ tActions = '{drag}\n' +
483
+ '<div class="file-actions">\n' +
484
+ ' <div class="file-footer-buttons">\n' +
485
+ ' {upload} {delete} {zoom} {other}' +
486
+ ' </div>\n' +
487
+ ' <div class="clearfix"></div>\n' +
488
+ '</div>';
489
+ //noinspection HtmlUnknownAttribute
490
+ tActionDelete = '<button type="button" class="kv-file-remove {removeClass}" ' +
491
+ 'title="{removeTitle}" {dataUrl}{dataKey}>{removeIcon}</button>\n';
492
+ tActionUpload = '<button type="button" class="kv-file-upload {uploadClass}" title="{uploadTitle}">' +
493
+ '{uploadIcon}</button>';
494
+ tActionZoom = '<button type="button" class="kv-file-zoom {zoomClass}" ' +
495
+ 'title="{zoomTitle}">{zoomIcon}</button>';
496
+ tActionDrag = '<span class="file-drag-handle {dragClass}" title="{dragTitle}">{dragIcon}</span>';
497
+ tIndicator = '<div class="file-upload-indicator" title="{indicatorTitle}">{indicator}</div>';
498
+ tTagBef = '<div class="file-preview-frame {frameClass}" id="{previewId}" data-fileindex="{fileindex}"' +
499
+ ' data-template="{template}"';
500
+ tTagBef1 = tTagBef + '><div class="kv-file-content">\n';
501
+ tTagBef2 = tTagBef + ' title="{caption}"><div class="kv-file-content">\n';
502
+ tTagAft = '</div>{footer}\n</div>\n';
503
+ tGeneric = '{content}\n';
504
+ tHtml = '<div class="kv-preview-data file-preview-html" title="{caption}" ' + $h.STYLE_SETTING +
505
+ '>{data}</div>\n';
506
+ tImage = '<img src="{data}" class="file-preview-image kv-preview-data" title="{caption}" alt="{caption}" ' +
507
+ $h.STYLE_SETTING + '>\n';
508
+ tText = '<textarea class="kv-preview-data file-preview-text" title="{caption}" readonly ' +
509
+ $h.STYLE_SETTING + '>{data}</textarea>\n';
510
+ tVideo = '<video class="kv-preview-data file-preview-video" width="{width}" ' +
511
+ 'height="{height}" controls>\n' + '<source src="{data}" type="{type}">\n' + $h.DEFAULT_PREVIEW +
512
+ '\n</video>\n';
513
+ tAudio = '<div class="file-preview-audio"><audio class="kv-preview-data" controls>\n<source src="{data}" ' +
514
+ 'type="{type}">\n' + $h.DEFAULT_PREVIEW + '\n</audio></div>\n';
515
+ tFlash = '<object class="kv-preview-data file-object" type="application/x-shockwave-flash" ' +
516
+ 'width="{width}" height="{height}" data="{data}">\n' + $h.OBJECT_PARAMS + ' ' + $h.DEFAULT_PREVIEW +
517
+ '\n</object>\n';
518
+ tObject = '<object class="kv-preview-data file-object {typeCss}" data="{data}" type="{type}" ' +
519
+ 'width="{width}" height="{height}">\n' + '<param name="movie" value="{caption}" />\n' +
520
+ $h.OBJECT_PARAMS + ' ' + $h.DEFAULT_PREVIEW + '\n</object>\n';
521
+ tPdf = '<embed class="kv-preview-data" src="{data}" ' +
522
+ 'width="{width}" height="{height}" type="application/pdf">\n';
523
+ tOther = '<div class="kv-preview-data file-preview-other-frame">\n' + $h.DEFAULT_PREVIEW + '\n</div>\n';
524
+ tZoomCache = '<div class="kv-zoom-cache" style="display:none">{zoomContent}</div>';
525
+ vDefaultDim = {width: "100%", height: "100%", 'min-height': "480px"};
526
+ self.defaults = {
527
+ layoutTemplates: {
528
+ main1: tMain1,
529
+ main2: tMain2,
530
+ preview: tPreview,
531
+ close: tClose,
532
+ fileIcon: tFileIcon,
533
+ caption: tCaption,
534
+ modalMain: tModalMain,
535
+ modal: tModal,
536
+ progress: tProgress,
537
+ size: tSize,
538
+ footer: tFooter,
539
+ indicator: tIndicator,
540
+ actions: tActions,
541
+ actionDelete: tActionDelete,
542
+ actionUpload: tActionUpload,
543
+ actionZoom: tActionZoom,
544
+ actionDrag: tActionDrag,
545
+ btnDefault: tBtnDefault,
546
+ btnLink: tBtnLink,
547
+ btnBrowse: tBtnBrowse,
548
+ zoomCache: tZoomCache
549
+ },
550
+ previewMarkupTags: {
551
+ tagBefore1: tTagBef1,
552
+ tagBefore2: tTagBef2,
553
+ tagAfter: tTagAft
554
+ },
555
+ previewContentTemplates: {
556
+ generic: tGeneric,
557
+ html: tHtml,
558
+ image: tImage,
559
+ text: tText,
560
+ video: tVideo,
561
+ audio: tAudio,
562
+ flash: tFlash,
563
+ object: tObject,
564
+ pdf: tPdf,
565
+ other: tOther
566
+ },
567
+ allowedPreviewTypes: ['image', 'html', 'text', 'video', 'audio', 'flash', 'pdf', 'object'],
568
+ previewTemplates: {},
569
+ previewSettings: {
570
+ image: {width: "auto", height: "160px"},
571
+ html: {width: "213px", height: "160px"},
572
+ text: {width: "213px", height: "160px"},
573
+ video: {width: "auto", height: "100%", 'max-width': "100%"},
574
+ audio: {width: "100%", height: "30px"},
575
+ flash: {width: "auto", height: "100%", 'max-width': "100%"},
576
+ object: {height: "100%"},
577
+ pdf: {width: "160px", height: "160px"},
578
+ other: {width: "160px", height: "160px"}
579
+ },
580
+ previewZoomSettings: {
581
+ image: {width: "auto", height: "auto", 'max-width': "100%", 'max-height': "100%"},
582
+ html: vDefaultDim,
583
+ text: vDefaultDim,
584
+ video: {width: "auto", height: "100%", 'max-width': "100%"},
585
+ audio: {width: "100%", height: "30px"},
586
+ flash: {width: "auto", height: "480px"},
587
+ object: {width: "auto", height: "100%", 'max-width': "100%", 'min-height': "480px"},
588
+ pdf: vDefaultDim,
589
+ other: {width: "auto", height: "100%", 'min-height': "480px"}
590
+ },
591
+ fileTypeSettings: {
592
+ image: function (vType, vName) {
593
+ return $h.compare(vType, 'image.*') || $h.compare(vName, /\.(gif|png|jpe?g)$/i);
594
+ },
595
+ html: function (vType, vName) {
596
+ return $h.compare(vType, 'text/html') || $h.compare(vName, /\.(htm|html)$/i);
597
+ },
598
+ text: function (vType, vName) {
599
+ return $h.compare(vType, 'text.*') || $h.compare(vName, /\.(xml|javascript)$/i) ||
600
+ $h.compare(vName, /\.(txt|md|csv|nfo|ini|json|php|js|css)$/i);
601
+ },
602
+ video: function (vType, vName) {
603
+ return $h.compare(vType, 'video.*') && ($h.compare(vType, /(ogg|mp4|mp?g|mov|webm|3gp)$/i) ||
604
+ $h.compare(vName, /\.(og?|mp4|webm|mp?g|mov|3gp)$/i));
605
+ },
606
+ audio: function (vType, vName) {
607
+ return $h.compare(vType, 'audio.*') && ($h.compare(vName, /(ogg|mp3|mp?g|wav)$/i) ||
608
+ $h.compare(vName, /\.(og?|mp3|mp?g|wav)$/i));
609
+ },
610
+ flash: function (vType, vName) {
611
+ return $h.compare(vType, 'application/x-shockwave-flash', true) || $h.compare(vName, /\.(swf)$/i);
612
+ },
613
+ pdf: function (vType, vName) {
614
+ return $h.compare(vType, 'application/pdf', true) || $h.compare(vName, /\.(pdf)$/i);
615
+ },
616
+ object: function () {
617
+ return true;
618
+ },
619
+ other: function () {
620
+ return true;
621
+ }
622
+ },
623
+ fileActionSettings: {
624
+ showRemove: true,
625
+ showUpload: true,
626
+ showZoom: true,
627
+ showDrag: true,
628
+ removeIcon: '<i class="glyphicon glyphicon-trash text-danger"></i>',
629
+ removeClass: 'btn btn-xs btn-default',
630
+ removeTitle: 'Remove file',
631
+ uploadIcon: '<i class="glyphicon glyphicon-upload text-info"></i>',
632
+ uploadClass: 'btn btn-xs btn-default',
633
+ uploadTitle: 'Upload file',
634
+ zoomIcon: '<i class="glyphicon glyphicon-zoom-in"></i>',
635
+ zoomClass: 'btn btn-xs btn-default',
636
+ zoomTitle: 'View Details',
637
+ dragIcon: '<i class="glyphicon glyphicon-menu-hamburger"></i>',
638
+ dragClass: 'text-info',
639
+ dragTitle: 'Move / Rearrange',
640
+ dragSettings: {},
641
+ indicatorNew: '<i class="glyphicon glyphicon-hand-down text-warning"></i>',
642
+ indicatorSuccess: '<i class="glyphicon glyphicon-ok-sign text-success"></i>',
643
+ indicatorError: '<i class="glyphicon glyphicon-exclamation-sign text-danger"></i>',
644
+ indicatorLoading: '<i class="glyphicon glyphicon-hand-up text-muted"></i>',
645
+ indicatorNewTitle: 'Not uploaded yet',
646
+ indicatorSuccessTitle: 'Uploaded',
647
+ indicatorErrorTitle: 'Upload Error',
648
+ indicatorLoadingTitle: 'Uploading ...'
649
+ }
650
+ };
651
+ $.each(self.defaults, function (key, setting) {
652
+ if (key === 'allowedPreviewTypes') {
653
+ if (self.allowedPreviewTypes === undefined) {
654
+ self.allowedPreviewTypes = setting;
655
+ }
656
+ return;
657
+ }
658
+ self[key] = $.extend(true, {}, setting, self[key]);
659
+ });
660
+ self._initPreviewTemplates();
661
+ },
662
+ _initPreviewTemplates: function () {
663
+ var self = this, cfg = self.defaults, tags = self.previewMarkupTags, tagBef, tagAft = tags.tagAfter;
664
+ $.each(cfg.previewContentTemplates, function (key, value) {
665
+ if ($h.isEmpty(self.previewTemplates[key])) {
666
+ tagBef = tags.tagBefore2;
667
+ if (key === 'generic' || key === 'image' || key === 'html' || key === 'text') {
668
+ tagBef = tags.tagBefore1;
669
+ }
670
+ self.previewTemplates[key] = tagBef + value + tagAft;
671
+ }
672
+ });
673
+ },
674
+ _initPreviewCache: function () {
675
+ var self = this;
676
+ self.previewCache = {
677
+ data: {},
678
+ init: function () {
679
+ var content = self.initialPreview;
680
+ if (content.length > 0 && !$h.isArray(content)) {
681
+ content = content.split(self.initialPreviewDelimiter);
682
+ }
683
+ self.previewCache.data = {
684
+ content: content,
685
+ config: self.initialPreviewConfig,
686
+ tags: self.initialPreviewThumbTags
687
+ };
688
+ },
689
+ fetch: function () {
690
+ return self.previewCache.data.content.filter(function (n) {
691
+ return n !== null;
692
+ });
693
+ },
694
+ count: function (all) {
695
+ return !!self.previewCache.data && !!self.previewCache.data.content ?
696
+ (all ? self.previewCache.data.content.length : self.previewCache.fetch().length) : 0;
697
+ },
698
+ get: function (i, isDisabled) {
699
+ var ind = 'init_' + i, data = self.previewCache.data, config = data.config[i],
700
+ content = data.content[i], previewId = self.previewInitId + '-' + ind, out, $tmp, cat, ftr,
701
+ fname, ftype, frameClass, asData = $h.ifSet('previewAsData', config, self.initialPreviewAsData),
702
+ parseTemplate = function (cat, dat, fn, ft, id, ftr, ind, fc, t) {
703
+ fc = ' file-preview-initial ' + $h.SORT_CSS + (fc ? ' ' + fc : '');
704
+ return self._generatePreviewTemplate(cat, dat, fn, ft, id, false, null, fc, ftr, ind, t);
705
+ };
706
+ if (!content) {
707
+ return '';
708
+ }
709
+ isDisabled = isDisabled === undefined ? true : isDisabled;
710
+ cat = $h.ifSet('type', config, self.initialPreviewFileType || 'generic');
711
+ fname = $h.ifSet('filename', config, $h.ifSet('caption', config));
712
+ ftype = $h.ifSet('filetype', config, cat);
713
+ ftr = self.previewCache.footer(i, isDisabled, (config && config.size || null));
714
+ frameClass = $h.ifSet('frameClass', config);
715
+ if (asData) {
716
+ out = parseTemplate(cat, content, fname, ftype, previewId, ftr, ind, frameClass);
717
+ } else {
718
+ out = parseTemplate('generic', content, fname, ftype, previewId, ftr, ind, frameClass, cat)
719
+ .setTokens({'content': data.content[i]});
720
+ }
721
+ if (data.tags.length && data.tags[i]) {
722
+ out = $h.replaceTags(out, data.tags[i]);
723
+ }
724
+ /** @namespace config.frameAttr */
725
+ if (!$h.isEmpty(config) && !$h.isEmpty(config.frameAttr)) {
726
+ $tmp = $(document.createElement('div')).html(out);
727
+ $tmp.find('.file-preview-initial').attr(config.frameAttr);
728
+ out = $tmp.html();
729
+ $tmp.remove();
730
+ }
731
+ return out;
732
+ },
733
+ add: function (content, config, tags, append) {
734
+ var data = self.previewCache.data, index;
735
+ if (!$h.isArray(content)) {
736
+ content = content.split(self.initialPreviewDelimiter);
737
+ }
738
+ if (append) {
739
+ index = data.content.push(content) - 1;
740
+ data.config[index] = config;
741
+ data.tags[index] = tags;
742
+ } else {
743
+ index = content.length - 1;
744
+ data.content = content;
745
+ data.config = config;
746
+ data.tags = tags;
747
+ }
748
+ self.previewCache.data = data;
749
+ return index;
750
+ },
751
+ set: function (content, config, tags, append) {
752
+ var data = self.previewCache.data, i, chk;
753
+ if (!content || !content.length) {
754
+ return;
755
+ }
756
+ if (!$h.isArray(content)) {
757
+ content = content.split(self.initialPreviewDelimiter);
758
+ }
759
+ chk = content.filter(function (n) {
760
+ return n !== null;
761
+ });
762
+ if (!chk.length) {
763
+ return;
764
+ }
765
+ if (data.content === undefined) {
766
+ data.content = [];
767
+ }
768
+ if (data.config === undefined) {
769
+ data.config = [];
770
+ }
771
+ if (data.tags === undefined) {
772
+ data.tags = [];
773
+ }
774
+ if (append) {
775
+ for (i = 0; i < content.length; i++) {
776
+ if (content[i]) {
777
+ data.content.push(content[i]);
778
+ }
779
+ }
780
+ for (i = 0; i < config.length; i++) {
781
+ if (config[i]) {
782
+ data.config.push(config[i]);
783
+ }
784
+ }
785
+ for (i = 0; i < tags.length; i++) {
786
+ if (tags[i]) {
787
+ data.tags.push(tags[i]);
788
+ }
789
+ }
790
+ } else {
791
+ data.content = content;
792
+ data.config = config;
793
+ data.tags = tags;
794
+ }
795
+ self.previewCache.data = data;
796
+ },
797
+ unset: function (index) {
798
+ var chk = self.previewCache.count();
799
+ if (!chk) {
800
+ return;
801
+ }
802
+ if (chk === 1) {
803
+ self.previewCache.data.content = [];
804
+ self.previewCache.data.config = [];
805
+ self.previewCache.data.tags = [];
806
+ self.initialPreview = [];
807
+ self.initialPreviewConfig = [];
808
+ self.initialPreviewThumbTags = [];
809
+ return;
810
+ }
811
+ self.previewCache.data.content[index] = null;
812
+ self.previewCache.data.config[index] = null;
813
+ self.previewCache.data.tags[index] = null;
814
+ },
815
+ out: function () {
816
+ var html = '', caption, len = self.previewCache.count(true), i;
817
+ if (len === 0) {
818
+ return {content: '', caption: ''};
819
+ }
820
+ for (i = 0; i < len; i++) {
821
+ html += self.previewCache.get(i);
822
+ }
823
+ caption = self._getMsgSelected(self.previewCache.count());
824
+ return {content: html, caption: caption};
825
+ },
826
+ footer: function (i, isDisabled, size) {
827
+ var data = self.previewCache.data;
828
+ if (!data || !data.config || data.config.length === 0 || $h.isEmpty(data.config[i])) {
829
+ return '';
830
+ }
831
+ isDisabled = isDisabled === undefined ? true : isDisabled;
832
+ var config = data.config[i], caption = $h.ifSet('caption', config), actions,
833
+ width = $h.ifSet('width', config, 'auto'), url = $h.ifSet('url', config, false),
834
+ key = $h.ifSet('key', config, null), fs = self.fileActionSettings,
835
+ initPreviewShowDel = self.initialPreviewShowDelete || false,
836
+ showDel = $h.ifSet('showDelete', config, $h.ifSet('showDelete', fs, initPreviewShowDel)),
837
+ showZoom = $h.ifSet('showZoom', config, $h.ifSet('showZoom', fs, true)),
838
+ showDrag = $h.ifSet('showDrag', config, $h.ifSet('showDrag', fs, true)),
839
+ disabled = (url === false) && isDisabled;
840
+ actions = self._renderFileActions(false, showDel, showZoom, showDrag, disabled, url, key, true);
841
+ return self._getLayoutTemplate('footer').setTokens({
842
+ 'progress': self._renderThumbProgress(),
843
+ 'actions': actions,
844
+ 'caption': caption,
845
+ 'size': self._getSize(size),
846
+ 'width': width,
847
+ 'indicator': ''
848
+ });
849
+ }
850
+ };
851
+ self.previewCache.init();
852
+ },
853
+ _handler: function ($el, event, callback) {
854
+ var self = this, ns = self.namespace, ev = event.split(' ').join(ns + ' ') + ns;
855
+ if (!$el || !$el.length) {
856
+ return;
857
+ }
858
+ $el.off(ev).on(ev, callback);
859
+ },
860
+ _log: function (msg) {
861
+ var self = this, id = self.$element.attr('id');
862
+ if (id) {
863
+ msg = '"' + id + '": ' + msg;
864
+ }
865
+ if (typeof window.console.log !== "undefined") {
866
+ window.console.log(msg);
867
+ } else {
868
+ window.alert(msg);
869
+ }
870
+ },
871
+ _validate: function () {
872
+ var self = this, status = self.$element.attr('type') === 'file';
873
+ if (!status) {
874
+ self._log('The input "type" must be set to "file" for initializing the "bootstrap-fileinput" plugin.');
875
+ }
876
+ return status;
877
+ },
878
+ _errorsExist: function () {
879
+ var self = this, $err;
880
+ if (self.$errorContainer.find('li').length) {
881
+ return true;
882
+ }
883
+ $err = $(document.createElement('div')).html(self.$errorContainer.html());
884
+ $err.find('span.kv-error-close').remove();
885
+ $err.find('ul').remove();
886
+ return $.trim($err.text()).length ? true : false;
887
+ },
888
+ _errorHandler: function (evt, caption) {
889
+ var self = this, err = evt.target.error, showError = function (msg) {
890
+ self._showError(msg.replace('{name}', caption));
891
+ };
892
+ /** @namespace err.NOT_FOUND_ERR */
893
+ /** @namespace err.SECURITY_ERR */
894
+ /** @namespace err.NOT_READABLE_ERR */
895
+ if (err.code === err.NOT_FOUND_ERR) {
896
+ showError(self.msgFileNotFound);
897
+ } else if (err.code === err.SECURITY_ERR) {
898
+ showError(self.msgFileSecured);
899
+ } else if (err.code === err.NOT_READABLE_ERR) {
900
+ showError(self.msgFileNotReadable);
901
+ } else if (err.code === err.ABORT_ERR) {
902
+ showError(self.msgFilePreviewAborted);
903
+ } else {
904
+ showError(self.msgFilePreviewError);
905
+ }
906
+ },
907
+ _addError: function (msg) {
908
+ var self = this, $error = self.$errorContainer;
909
+ if (msg && $error.length) {
910
+ $error.html(self.errorCloseButton + msg);
911
+ self._handler($error.find('.kv-error-close'), 'click', function () {
912
+ $error.fadeOut('slow');
913
+ });
914
+ }
915
+ },
916
+ _resetErrors: function (fade) {
917
+ var self = this, $error = self.$errorContainer;
918
+ self.isError = false;
919
+ self.$container.removeClass('has-error');
920
+ $error.html('');
921
+ if (fade) {
922
+ $error.fadeOut('slow');
923
+ } else {
924
+ $error.hide();
925
+ }
926
+ },
927
+ _showFolderError: function (folders) {
928
+ var self = this, $error = self.$errorContainer, msg;
929
+ if (!folders) {
930
+ return;
931
+ }
932
+ msg = self.msgFoldersNotAllowed.replace('{n}', folders);
933
+ self._addError(msg);
934
+ $h.addCss(self.$container, 'has-error');
935
+ $error.fadeIn(800);
936
+ self._raise('filefoldererror', [folders, msg]);
937
+ },
938
+ _showUploadError: function (msg, params, event) {
939
+ var self = this, $error = self.$errorContainer, ev = event || 'fileuploaderror', e = params && params.id ?
940
+ '<li data-file-id="' + params.id + '">' + msg + '</li>' : '<li>' + msg + '</li>';
941
+ if ($error.find('ul').length === 0) {
942
+ self._addError('<ul>' + e + '</ul>');
943
+ } else {
944
+ $error.find('ul').append(e);
945
+ }
946
+ $error.fadeIn(800);
947
+ self._raise(ev, [params, msg]);
948
+ self.$container.removeClass('file-input-new');
949
+ $h.addCss(self.$container, 'has-error');
950
+ return true;
951
+ },
952
+ _showError: function (msg, params, event) {
953
+ var self = this, $error = self.$errorContainer, ev = event || 'fileerror';
954
+ params = params || {};
955
+ params.reader = self.reader;
956
+ self._addError(msg);
957
+ $error.fadeIn(800);
958
+ self._raise(ev, [params, msg]);
959
+ if (!self.isUploadable) {
960
+ self._clearFileInput();
961
+ }
962
+ self.$container.removeClass('file-input-new');
963
+ $h.addCss(self.$container, 'has-error');
964
+ self.$btnUpload.attr('disabled', true);
965
+ return true;
966
+ },
967
+ _noFilesError: function (params) {
968
+ var self = this, label = self.minFileCount > 1 ? self.filePlural : self.fileSingle,
969
+ msg = self.msgFilesTooLess.replace('{n}', self.minFileCount).replace('{files}', label),
970
+ $error = self.$errorContainer;
971
+ self._addError(msg);
972
+ self.isError = true;
973
+ self._updateFileDetails(0);
974
+ $error.fadeIn(800);
975
+ self._raise('fileerror', [params, msg]);
976
+ self._clearFileInput();
977
+ $h.addCss(self.$container, 'has-error');
978
+ },
979
+ _parseError: function (operation, jqXHR, errorThrown, fileName) {
980
+ /** @namespace jqXHR.responseJSON */
981
+ var self = this, errMsg = $.trim(errorThrown + ''), dot = errMsg.slice(-1) === '.' ? '' : '.',
982
+ text = jqXHR.responseJSON !== undefined && jqXHR.responseJSON.error !== undefined ?
983
+ jqXHR.responseJSON.error : jqXHR.responseText;
984
+ if (self.cancelling && self.msgUploadAborted) {
985
+ errMsg = self.msgUploadAborted;
986
+ }
987
+ if (self.showAjaxErrorDetails && text) {
988
+ text = $.trim(text.replace(/\n\s*\n/g, '\n'));
989
+ text = text.length > 0 ? '<pre>' + text + '</pre>' : '';
990
+ errMsg += dot + text;
991
+ } else {
992
+ errMsg += dot;
993
+ }
994
+ if (errMsg === dot) {
995
+ errMsg = self.msgAjaxError.replace('{operation}', operation);
996
+ }
997
+ self.cancelling = false;
998
+ return fileName ? '<b>' + fileName + ': </b>' + errMsg : errMsg;
999
+ },
1000
+ _parseFileType: function (file) {
1001
+ var self = this, isValid, vType, cat, i, types = self.allowedPreviewTypes || [];
1002
+ for (i = 0; i < types.length; i++) {
1003
+ cat = types[i];
1004
+ isValid = self.fileTypeSettings[cat];
1005
+ vType = isValid(file.type, file.name) ? cat : '';
1006
+ if (!$h.isEmpty(vType)) {
1007
+ return vType;
1008
+ }
1009
+ }
1010
+ return 'other';
1011
+ },
1012
+ _getPreviewIcon: function (fname) {
1013
+ var self = this, ext, out = null;
1014
+ if (fname && fname.indexOf('.') > -1) {
1015
+ ext = fname.split('.').pop();
1016
+ if (self.previewFileIconSettings) {
1017
+ out = self.previewFileIconSettings[ext] || self.previewFileIconSettings[ext.toLowerCase()] || null;
1018
+ }
1019
+ if (self.previewFileExtSettings) {
1020
+ $.each(self.previewFileExtSettings, function (key, func) {
1021
+ if (self.previewFileIconSettings[key] && func(ext)) {
1022
+ out = self.previewFileIconSettings[key];
1023
+ //noinspection UnnecessaryReturnStatementJS
1024
+ return;
1025
+ }
1026
+ });
1027
+ }
1028
+ }
1029
+ return out;
1030
+ },
1031
+ _parseFilePreviewIcon: function (content, fname) {
1032
+ var self = this, icn = self._getPreviewIcon(fname) || self.previewFileIcon, out = content;
1033
+ if (out.indexOf('{previewFileIcon}') > -1) {
1034
+ out = out.setTokens({'previewFileIconClass': self.previewFileIconClass, 'previewFileIcon': icn});
1035
+ }
1036
+ return out;
1037
+ },
1038
+ _raise: function (event, params) {
1039
+ var self = this, e = $.Event(event);
1040
+ if (params !== undefined) {
1041
+ self.$element.trigger(e, params);
1042
+ } else {
1043
+ self.$element.trigger(e);
1044
+ }
1045
+ if (e.isDefaultPrevented() || e.result === false) {
1046
+ return false;
1047
+ }
1048
+ switch (event) {
1049
+ // ignore these events
1050
+ case 'filebatchuploadcomplete':
1051
+ case 'filebatchuploadsuccess':
1052
+ case 'fileuploaded':
1053
+ case 'fileclear':
1054
+ case 'filecleared':
1055
+ case 'filereset':
1056
+ case 'fileerror':
1057
+ case 'filefoldererror':
1058
+ case 'fileuploaderror':
1059
+ case 'filebatchuploaderror':
1060
+ case 'filedeleteerror':
1061
+ case 'filecustomerror':
1062
+ case 'filesuccessremove':
1063
+ break;
1064
+ // receive data response via `filecustomerror` event`
1065
+ default:
1066
+ if (!self.ajaxAborted) {
1067
+ self.ajaxAborted = e.result;
1068
+ }
1069
+ break;
1070
+ }
1071
+ return true;
1072
+ },
1073
+ _listenFullScreen: function (isFullScreen) {
1074
+ var self = this, $modal = self.$modal, $btnFull, $btnBord;
1075
+ if (!$modal || !$modal.length) {
1076
+ return;
1077
+ }
1078
+ $btnFull = $modal && $modal.find('.btn-fullscreen');
1079
+ $btnBord = $modal && $modal.find('.btn-borderless');
1080
+ if (!$btnFull.length || !$btnBord.length) {
1081
+ return;
1082
+ }
1083
+ $btnFull.removeClass('active').attr('aria-pressed', 'false');
1084
+ $btnBord.removeClass('active').attr('aria-pressed', 'false');
1085
+ if (isFullScreen) {
1086
+ $btnFull.addClass('active').attr('aria-pressed', 'true');
1087
+ } else {
1088
+ $btnBord.addClass('active').attr('aria-pressed', 'true');
1089
+ }
1090
+ if ($modal.hasClass('file-zoom-fullscreen')) {
1091
+ self._maximizeZoomDialog();
1092
+ } else {
1093
+ if (isFullScreen) {
1094
+ self._maximizeZoomDialog();
1095
+ } else {
1096
+ $btnBord.removeClass('active').attr('aria-pressed', 'false');
1097
+ }
1098
+ }
1099
+ },
1100
+ _listen: function () {
1101
+ var self = this, $el = self.$element, $form = self.$form, $cont = self.$container, fullScreenEvents;
1102
+ self._handler($el, 'change', $.proxy(self._change, self));
1103
+ if (self.showBrowse) {
1104
+ self._handler(self.$btnFile, 'click', $.proxy(self._browse, self));
1105
+ }
1106
+ self._handler($cont.find('.fileinput-remove:not([disabled])'), 'click', $.proxy(self.clear, self));
1107
+ self._handler($cont.find('.fileinput-cancel'), 'click', $.proxy(self.cancel, self));
1108
+ self._initDragDrop();
1109
+ self._handler($form, 'reset', $.proxy(self.reset, self));
1110
+ if (!self.isUploadable) {
1111
+ self._handler($form, 'submit', $.proxy(self._submitForm, self));
1112
+ }
1113
+ self._handler(self.$container.find('.fileinput-upload'), 'click', $.proxy(self._uploadClick, self));
1114
+ self._handler($(window), 'resize', function () {
1115
+ self._listenFullScreen(screen.width === window.innerWidth && screen.height === window.innerHeight);
1116
+ });
1117
+ fullScreenEvents = 'webkitfullscreenchange mozfullscreenchange fullscreenchange MSFullscreenChange';
1118
+ self._handler($(document), fullScreenEvents, function () {
1119
+ self._listenFullScreen($h.checkFullScreen());
1120
+ });
1121
+ self._initClickable();
1122
+ },
1123
+ _initClickable: function () {
1124
+ var self = this, $zone;
1125
+ if (!self.isClickable) {
1126
+ return;
1127
+ }
1128
+ $zone = self.isUploadable ? self.$dropZone : self.$preview.find('.file-default-preview');
1129
+ $h.addCss($zone, 'clickable');
1130
+ $zone.attr('tabindex', -1);
1131
+ self._handler($zone, 'click', function (e) {
1132
+ var $tar = $(e.target);
1133
+ if (!$tar.parents('.file-preview-thumbnails').length || $tar.parents('.file-default-preview').length) {
1134
+ self.$element.trigger('click');
1135
+ $zone.blur();
1136
+ }
1137
+ });
1138
+ },
1139
+ _initDragDrop: function () {
1140
+ var self = this, $zone = self.$dropZone;
1141
+ if (self.isUploadable && self.dropZoneEnabled && self.showPreview) {
1142
+ self._handler($zone, 'dragenter dragover', $.proxy(self._zoneDragEnter, self));
1143
+ self._handler($zone, 'dragleave', $.proxy(self._zoneDragLeave, self));
1144
+ self._handler($zone, 'drop', $.proxy(self._zoneDrop, self));
1145
+ self._handler($(document), 'dragenter dragover drop', self._zoneDragDropInit);
1146
+ }
1147
+ },
1148
+ _zoneDragDropInit: function (e) {
1149
+ e.stopPropagation();
1150
+ e.preventDefault();
1151
+ },
1152
+ _zoneDragEnter: function (e) {
1153
+ var self = this, hasFiles = $.inArray('Files', e.originalEvent.dataTransfer.types) > -1;
1154
+ self._zoneDragDropInit(e);
1155
+ if (self.isDisabled || !hasFiles) {
1156
+ e.originalEvent.dataTransfer.effectAllowed = 'none';
1157
+ e.originalEvent.dataTransfer.dropEffect = 'none';
1158
+ return;
1159
+ }
1160
+ $h.addCss(self.$dropZone, 'file-highlighted');
1161
+ },
1162
+ _zoneDragLeave: function (e) {
1163
+ var self = this;
1164
+ self._zoneDragDropInit(e);
1165
+ if (self.isDisabled) {
1166
+ return;
1167
+ }
1168
+ self.$dropZone.removeClass('file-highlighted');
1169
+ },
1170
+ _zoneDrop: function (e) {
1171
+ var self = this;
1172
+ e.preventDefault();
1173
+ /** @namespace e.originalEvent.dataTransfer */
1174
+ if (self.isDisabled || $h.isEmpty(e.originalEvent.dataTransfer.files)) {
1175
+ return;
1176
+ }
1177
+ self._change(e, 'dragdrop');
1178
+ self.$dropZone.removeClass('file-highlighted');
1179
+ },
1180
+ _uploadClick: function (e) {
1181
+ var self = this, $btn = self.$container.find('.fileinput-upload'), $form,
1182
+ isEnabled = !$btn.hasClass('disabled') && $h.isEmpty($btn.attr('disabled'));
1183
+ if (e && e.isDefaultPrevented()) {
1184
+ return;
1185
+ }
1186
+ if (!self.isUploadable) {
1187
+ if (isEnabled && $btn.attr('type') !== 'submit') {
1188
+ $form = $btn.closest('form');
1189
+ // downgrade to normal form submit if possible
1190
+ if ($form.length) {
1191
+ $form.trigger('submit');
1192
+ }
1193
+ e.preventDefault();
1194
+ }
1195
+ return;
1196
+ }
1197
+ e.preventDefault();
1198
+ if (isEnabled) {
1199
+ self.upload();
1200
+ }
1201
+ },
1202
+ _submitForm: function () {
1203
+ var self = this, $el = self.$element, files = $el.get(0).files;
1204
+ if (files && self.minFileCount > 0 && self._getFileCount(files.length) < self.minFileCount) {
1205
+ self._noFilesError({});
1206
+ return false;
1207
+ }
1208
+ return !self._abort({});
1209
+ },
1210
+ _clearPreview: function () {
1211
+ var self = this, $p = self.$preview,
1212
+ $thumbs = self.showUploadedThumbs ? $p.find($h.FRAMES + ':not(.file-preview-success)') : $p.find($h.FRAMES);
1213
+ $thumbs.each(function () {
1214
+ var $thumb = $(this);
1215
+ $thumb.remove();
1216
+ $h.cleanZoomCache($p.find('#zoom-' + $thumb.attr('id')));
1217
+ });
1218
+ if (!self.$preview.find($h.FRAMES).length || !self.showPreview) {
1219
+ self._resetUpload();
1220
+ }
1221
+ self._validateDefaultPreview();
1222
+ },
1223
+ _initSortable: function () {
1224
+ var self = this, $el = self.$preview, settings, selector = '.' + $h.SORT_CSS;
1225
+ if (!window.KvSortable || $el.find(selector).length === 0) {
1226
+ return;
1227
+ }
1228
+ //noinspection JSUnusedGlobalSymbols
1229
+ settings = {
1230
+ handle: '.drag-handle-init',
1231
+ dataIdAttr: 'data-preview-id',
1232
+ scroll: false,
1233
+ draggable: selector,
1234
+ onSort: function (e) {
1235
+ var oldIndex = e.oldIndex, newIndex = e.newIndex, key, $frame;
1236
+ self.initialPreview = $h.moveArray(self.initialPreview, oldIndex, newIndex);
1237
+ self.initialPreviewConfig = $h.moveArray(self.initialPreviewConfig, oldIndex, newIndex);
1238
+ self.previewCache.init();
1239
+ for (var i = 0; i < self.initialPreviewConfig.length; i++) {
1240
+ if (self.initialPreviewConfig[i] !== null) {
1241
+ key = self.initialPreviewConfig[i].key;
1242
+ $frame = $(".kv-file-remove[data-key='" + key + "']").closest($h.FRAMES);
1243
+ $frame.attr('data-fileindex', 'init_' + i).attr('data-fileindex', 'init_' + i);
1244
+ }
1245
+ }
1246
+ self._raise('filesorted', {
1247
+ previewId: $(e.item).attr('id'),
1248
+ 'oldIndex': oldIndex,
1249
+ 'newIndex': newIndex,
1250
+ stack: self.initialPreviewConfig
1251
+ });
1252
+ }
1253
+ };
1254
+ if ($el.data('kvsortable')) {
1255
+ $el.kvsortable('destroy');
1256
+ }
1257
+ $.extend(true, settings, self.fileActionSettings.dragSettings);
1258
+ $el.kvsortable(settings);
1259
+ },
1260
+ _initPreview: function (isInit) {
1261
+ var self = this, cap = self.initialCaption || '', out;
1262
+ if (!self.previewCache.count()) {
1263
+ self._clearPreview();
1264
+ if (isInit) {
1265
+ self._setCaption(cap);
1266
+ } else {
1267
+ self._initCaption();
1268
+ }
1269
+ return;
1270
+ }
1271
+ out = self.previewCache.out();
1272
+ cap = isInit && self.initialCaption ? self.initialCaption : out.caption;
1273
+ self.$preview.html(out.content);
1274
+ self._setInitThumbAttr();
1275
+ self._setCaption(cap);
1276
+ self._initSortable();
1277
+ if (!$h.isEmpty(out.content)) {
1278
+ self.$container.removeClass('file-input-new');
1279
+ }
1280
+ },
1281
+ _getZoomButton: function (type) {
1282
+ var self = this, label = self.previewZoomButtonIcons[type], css = self.previewZoomButtonClasses[type],
1283
+ title = ' title="' + (self.previewZoomButtonTitles[type] || '') + '" ',
1284
+ params = title + (type === 'close' ? ' data-dismiss="modal" aria-hidden="true"' : '');
1285
+ if (type === 'fullscreen' || type === 'borderless' || type === 'toggleheader') {
1286
+ params += ' data-toggle="button" aria-pressed="false" autocomplete="off"';
1287
+ }
1288
+ return '<button type="button" class="' + css + ' btn-' + type + '"' + params + '>' + label + '</button>';
1289
+ },
1290
+ _getModalContent: function () {
1291
+ var self = this;
1292
+ return self._getLayoutTemplate('modal').setTokens({
1293
+ 'zoomFrameClass': self.frameClass,
1294
+ 'heading': self.msgZoomModalHeading,
1295
+ 'prev': self._getZoomButton('prev'),
1296
+ 'next': self._getZoomButton('next'),
1297
+ 'toggleheader': self._getZoomButton('toggleheader'),
1298
+ 'fullscreen': self._getZoomButton('fullscreen'),
1299
+ 'borderless': self._getZoomButton('borderless'),
1300
+ 'close': self._getZoomButton('close')
1301
+ });
1302
+ },
1303
+ _listenModalEvent: function (event) {
1304
+ var self = this, $modal = self.$modal, getParams = function (e) {
1305
+ return {
1306
+ sourceEvent: e,
1307
+ previewId: $modal.data('previewId'),
1308
+ modal: $modal
1309
+ };
1310
+ };
1311
+ $modal.on(event + '.bs.modal', function (e) {
1312
+ var $btnFull = $modal.find('.btn-fullscreen'), $btnBord = $modal.find('.btn-borderless');
1313
+ self._raise('filezoom' + event, getParams(e));
1314
+ if (event === 'shown') {
1315
+ $btnBord.removeClass('active').attr('aria-pressed', 'false');
1316
+ $btnFull.removeClass('active').attr('aria-pressed', 'false');
1317
+ if ($modal.hasClass('file-zoom-fullscreen')) {
1318
+ self._maximizeZoomDialog();
1319
+ if ($h.checkFullScreen()) {
1320
+ $btnFull.addClass('active').attr('aria-pressed', 'true');
1321
+ } else {
1322
+ $btnBord.addClass('active').attr('aria-pressed', 'true');
1323
+ }
1324
+ }
1325
+ }
1326
+ });
1327
+ },
1328
+ _initZoom: function () {
1329
+ var self = this, $dialog, modalMain = self._getLayoutTemplate('modalMain'), modalId = '#' + $h.MODAL_ID;
1330
+ if (!self.showPreview) {
1331
+ return;
1332
+ }
1333
+ self.$modal = $(modalId);
1334
+ if (!self.$modal || !self.$modal.length) {
1335
+ $dialog = $(document.createElement('div')).html(modalMain).insertAfter(self.$container);
1336
+ self.$modal = $(modalId).insertBefore($dialog);
1337
+ $dialog.remove();
1338
+ }
1339
+ $h.initModal(self.$modal);
1340
+ self.$modal.html(self._getModalContent());
1341
+ $.each($h.MODAL_EVENTS, function (key, event) {
1342
+ self._listenModalEvent(event);
1343
+ });
1344
+ },
1345
+ _initZoomButtons: function () {
1346
+ var self = this, previewId = self.$modal.data('previewId') || '', $first, $last, $preview = self.$preview,
1347
+ thumbs = $preview.find($h.FRAMES).toArray(), len = thumbs.length,
1348
+ $prev = self.$modal.find('.btn-prev'), $next = self.$modal.find('.btn-next');
1349
+ if (thumbs.length < 2) {
1350
+ $prev.hide();
1351
+ $next.hide();
1352
+ return;
1353
+ } else {
1354
+ $prev.show();
1355
+ $next.show();
1356
+ }
1357
+ if (!len) {
1358
+ return;
1359
+ }
1360
+ $first = $(thumbs[0]);
1361
+ $last = $(thumbs[len - 1]);
1362
+ $prev.removeAttr('disabled');
1363
+ $next.removeAttr('disabled');
1364
+ if ($first.length && $first.attr('id') === previewId) {
1365
+ $prev.attr('disabled', true);
1366
+ }
1367
+ if ($last.length && $last.attr('id') === previewId) {
1368
+ $next.attr('disabled', true);
1369
+ }
1370
+ },
1371
+ _maximizeZoomDialog: function () {
1372
+ var self = this, $modal = self.$modal, $head = $modal.find('.modal-header:visible'),
1373
+ $foot = $modal.find('.modal-footer:visible'), $body = $modal.find('.modal-body'),
1374
+ h = $(window).height(), diff = 0;
1375
+ $modal.addClass('file-zoom-fullscreen');
1376
+ if ($head && $head.length) {
1377
+ h -= $head.outerHeight(true);
1378
+ }
1379
+ if ($foot && $foot.length) {
1380
+ h -= $foot.outerHeight(true);
1381
+ }
1382
+ if ($body && $body.length) {
1383
+ diff = $body.outerHeight(true) - $body.height();
1384
+ h -= diff;
1385
+ }
1386
+ $modal.find('.kv-zoom-body').height(h);
1387
+ },
1388
+ _resizeZoomDialog: function (fullScreen) {
1389
+ var self = this, $modal = self.$modal, $btnFull = $modal.find('.btn-fullscreen'),
1390
+ $btnBord = $modal.find('.btn-borderless');
1391
+ if ($modal.hasClass('file-zoom-fullscreen')) {
1392
+ $h.toggleFullScreen(false);
1393
+ if (!fullScreen) {
1394
+ if (!$btnFull.hasClass('active')) {
1395
+ $modal.removeClass('file-zoom-fullscreen');
1396
+ self.$modal.find('.kv-zoom-body').css('height', self.zoomModalHeight);
1397
+ } else {
1398
+ $btnFull.removeClass('active').attr('aria-pressed', 'false');
1399
+ }
1400
+ } else {
1401
+ if (!$btnFull.hasClass('active')) {
1402
+ $modal.removeClass('file-zoom-fullscreen');
1403
+ self._resizeZoomDialog(true);
1404
+ if ($btnBord.hasClass('active')) {
1405
+ $btnBord.removeClass('active').attr('aria-pressed', 'false');
1406
+ }
1407
+ }
1408
+ }
1409
+ } else {
1410
+ if (!fullScreen) {
1411
+ self._maximizeZoomDialog();
1412
+ return;
1413
+ }
1414
+ $h.toggleFullScreen(true);
1415
+ }
1416
+ $modal.focus();
1417
+ },
1418
+ _setZoomContent: function ($frame, animate) {
1419
+ var self = this, $content, tmplt, body, title, $body, $dataEl, config, pid = $frame.attr('id'),
1420
+ $modal = self.$modal, $prev = $modal.find('.btn-prev'), $next = $modal.find('.btn-next'), $tmp,
1421
+ $btnFull = $modal.find('.btn-fullscreen'), $btnBord = $modal.find('.btn-borderless'), cap, size,
1422
+ $btnTogh = $modal.find('.btn-toggleheader'), $zoomPreview = self.$preview.find('#zoom-' + pid);
1423
+ tmplt = $zoomPreview.attr('data-template') || 'generic';
1424
+ $content = $zoomPreview.find('.kv-file-content');
1425
+ body = $content.length ? $content.html() : '';
1426
+ cap = $frame.data('caption') || '';
1427
+ size = $frame.data('size') || '';
1428
+ title = cap + ' ' + size;
1429
+ $modal.find('.kv-zoom-title').html(title);
1430
+ $body = $modal.find('.kv-zoom-body');
1431
+ $modal.removeClass('kv-single-content');
1432
+ if (animate) {
1433
+ $tmp = $body.addClass('file-thumb-loading').clone().insertAfter($body);
1434
+ $body.html(body).hide();
1435
+ $tmp.fadeOut('fast', function () {
1436
+ $body.fadeIn('fast', function () {
1437
+ $body.removeClass('file-thumb-loading');
1438
+ });
1439
+ $tmp.remove();
1440
+ });
1441
+ } else {
1442
+ $body.html(body);
1443
+ }
1444
+ config = self.previewZoomSettings[tmplt];
1445
+ if (config) {
1446
+ $dataEl = $body.find('.kv-preview-data');
1447
+ $h.addCss($dataEl, 'file-zoom-detail');
1448
+ $.each(config, function (key, value) {
1449
+ $dataEl.css(key, value);
1450
+ if (($dataEl.attr('width') && key === 'width') || ($dataEl.attr('height') && key === 'height')) {
1451
+ $dataEl.removeAttr(key);
1452
+ }
1453
+ });
1454
+ }
1455
+ $modal.data('previewId', pid);
1456
+ var $img = $body.find('img');
1457
+ if ($img.length) {
1458
+ $h.adjustOrientedImage($img, true);
1459
+ }
1460
+ self._handler($prev, 'click', function () {
1461
+ self._zoomSlideShow('prev', pid);
1462
+ });
1463
+ self._handler($next, 'click', function () {
1464
+ self._zoomSlideShow('next', pid);
1465
+ });
1466
+ self._handler($btnFull, 'click', function () {
1467
+ self._resizeZoomDialog(true);
1468
+ });
1469
+ self._handler($btnBord, 'click', function () {
1470
+ self._resizeZoomDialog(false);
1471
+ });
1472
+ self._handler($btnTogh, 'click', function () {
1473
+ var $header = $modal.find('.modal-header'), $floatBar = $modal.find('.modal-body .floating-buttons'),
1474
+ ht, $actions = $header.find('.kv-zoom-actions'), resize = function (height) {
1475
+ var $body = self.$modal.find('.kv-zoom-body'), h = self.zoomModalHeight;
1476
+ if ($modal.hasClass('file-zoom-fullscreen')) {
1477
+ h = $body.outerHeight(true);
1478
+ if (!height) {
1479
+ h = h - $header.outerHeight(true);
1480
+ }
1481
+ }
1482
+ $body.css('height', height ? h + height : h);
1483
+ };
1484
+ if ($header.is(':visible')) {
1485
+ ht = $header.outerHeight(true);
1486
+ $header.slideUp('slow', function () {
1487
+ $actions.find('.btn').appendTo($floatBar);
1488
+ resize(ht);
1489
+ });
1490
+ } else {
1491
+ $floatBar.find('.btn').appendTo($actions);
1492
+ $header.slideDown('slow', function () {
1493
+ resize();
1494
+ });
1495
+ }
1496
+ $modal.focus();
1497
+ });
1498
+ self._handler($modal, 'keydown', function (e) {
1499
+ var key = e.which || e.keyCode;
1500
+ if (key === 37 && !$prev.attr('disabled')) {
1501
+ self._zoomSlideShow('prev', pid);
1502
+ }
1503
+ if (key === 39 && !$next.attr('disabled')) {
1504
+ self._zoomSlideShow('next', pid);
1505
+ }
1506
+ });
1507
+ },
1508
+ _zoomPreview: function ($btn) {
1509
+ var self = this, $frame, $modal = self.$modal;
1510
+ if (!$btn.length) {
1511
+ throw 'Cannot zoom to detailed preview!';
1512
+ }
1513
+ $h.initModal($modal);
1514
+ $modal.html(self._getModalContent());
1515
+ $frame = $btn.closest($h.FRAMES);
1516
+ self._setZoomContent($frame);
1517
+ $modal.modal('show');
1518
+ self._initZoomButtons();
1519
+ },
1520
+ _zoomSlideShow: function (dir, previewId) {
1521
+ var self = this, $btn = self.$modal.find('.kv-zoom-actions .btn-' + dir), $targFrame, i,
1522
+ thumbs = self.$preview.find($h.FRAMES).toArray(), len = thumbs.length, out;
1523
+ if ($btn.attr('disabled')) {
1524
+ return;
1525
+ }
1526
+ for (i = 0; i < len; i++) {
1527
+ if ($(thumbs[i]).attr('id') === previewId) {
1528
+ out = dir === 'prev' ? i - 1 : i + 1;
1529
+ break;
1530
+ }
1531
+ }
1532
+ if (out < 0 || out >= len || !thumbs[out]) {
1533
+ return;
1534
+ }
1535
+ $targFrame = $(thumbs[out]);
1536
+ if ($targFrame.length) {
1537
+ self._setZoomContent($targFrame, true);
1538
+ }
1539
+ self._initZoomButtons();
1540
+ self._raise('filezoom' + dir, {'previewId': previewId, modal: self.$modal});
1541
+ },
1542
+ _initZoomButton: function () {
1543
+ var self = this;
1544
+ self.$preview.find('.kv-file-zoom').each(function () {
1545
+ var $el = $(this);
1546
+ self._handler($el, 'click', function () {
1547
+ self._zoomPreview($el);
1548
+ });
1549
+ });
1550
+ },
1551
+ _clearObjects: function ($el) {
1552
+ $el.find('video audio').each(function () {
1553
+ this.pause();
1554
+ $(this).remove();
1555
+ });
1556
+ $el.find('img object div').each(function () {
1557
+ $(this).remove();
1558
+ });
1559
+ },
1560
+ _clearFileInput: function () {
1561
+ var self = this, $el = self.$element, $srcFrm, $tmpFrm, $tmpEl;
1562
+ self.fileInputCleared = true;
1563
+ if ($h.isEmpty($el.val())) {
1564
+ return;
1565
+ }
1566
+ // Fix for IE ver < 11, that does not clear file inputs. Requires a sequence of steps to prevent IE
1567
+ // crashing but still allow clearing of the file input.
1568
+ if (self.isIE9 || self.isIE10) {
1569
+ $srcFrm = $el.closest('form');
1570
+ $tmpFrm = $(document.createElement('form'));
1571
+ $tmpEl = $(document.createElement('div'));
1572
+ $el.before($tmpEl);
1573
+ if ($srcFrm.length) {
1574
+ $srcFrm.after($tmpFrm);
1575
+ } else {
1576
+ $tmpEl.after($tmpFrm);
1577
+ }
1578
+ $tmpFrm.append($el).trigger('reset');
1579
+ $tmpEl.before($el).remove();
1580
+ $tmpFrm.remove();
1581
+ } else { // normal input clear behavior for other sane browsers
1582
+ $el.val('');
1583
+ }
1584
+ },
1585
+ _resetUpload: function () {
1586
+ var self = this;
1587
+ self.uploadCache = {content: [], config: [], tags: [], append: true};
1588
+ self.uploadCount = 0;
1589
+ self.uploadStatus = {};
1590
+ self.uploadLog = [];
1591
+ self.uploadAsyncCount = 0;
1592
+ self.loadedImages = [];
1593
+ self.totalImagesCount = 0;
1594
+ self.$btnUpload.removeAttr('disabled');
1595
+ self._setProgress(0);
1596
+ $h.addCss(self.$progress, 'hide');
1597
+ self._resetErrors(false);
1598
+ self.ajaxAborted = false;
1599
+ self.ajaxRequests = [];
1600
+ self._resetCanvas();
1601
+ self.cacheInitialPreview = {};
1602
+ if (self.overwriteInitial) {
1603
+ self.initialPreview = [];
1604
+ self.initialPreviewConfig = [];
1605
+ self.initialPreviewThumbTags = [];
1606
+ self.previewCache.data = {
1607
+ content: [],
1608
+ config: [],
1609
+ tags: []
1610
+ };
1611
+ }
1612
+ },
1613
+ _resetCanvas: function () {
1614
+ var self = this;
1615
+ if (self.canvas && self.imageCanvasContext) {
1616
+ self.imageCanvasContext.clearRect(0, 0, self.canvas.width, self.canvas.height);
1617
+ }
1618
+ },
1619
+ _hasInitialPreview: function () {
1620
+ var self = this;
1621
+ return !self.overwriteInitial && self.previewCache.count();
1622
+ },
1623
+ _resetPreview: function () {
1624
+ var self = this, out, cap;
1625
+ if (self.previewCache.count()) {
1626
+ out = self.previewCache.out();
1627
+ self.$preview.html(out.content);
1628
+ self._setInitThumbAttr();
1629
+ cap = self.initialCaption ? self.initialCaption : out.caption;
1630
+ self._setCaption(cap);
1631
+ } else {
1632
+ self._clearPreview();
1633
+ self._initCaption();
1634
+ }
1635
+ if (self.showPreview) {
1636
+ self._initZoom();
1637
+ self._initSortable();
1638
+ }
1639
+ },
1640
+ _clearDefaultPreview: function () {
1641
+ var self = this;
1642
+ self.$preview.find('.file-default-preview').remove();
1643
+ },
1644
+ _validateDefaultPreview: function () {
1645
+ var self = this;
1646
+ if (!self.showPreview || $h.isEmpty(self.defaultPreviewContent)) {
1647
+ return;
1648
+ }
1649
+ self.$preview.html('<div class="file-default-preview">' + self.defaultPreviewContent + '</div>');
1650
+ self.$container.removeClass('file-input-new');
1651
+ self._initClickable();
1652
+ },
1653
+ _resetPreviewThumbs: function (isAjax) {
1654
+ var self = this, out;
1655
+ if (isAjax) {
1656
+ self._clearPreview();
1657
+ self.clearStack();
1658
+ return;
1659
+ }
1660
+ if (self._hasInitialPreview()) {
1661
+ out = self.previewCache.out();
1662
+ self.$preview.html(out.content);
1663
+ self._setInitThumbAttr();
1664
+ self._setCaption(out.caption);
1665
+ self._initPreviewActions();
1666
+ } else {
1667
+ self._clearPreview();
1668
+ }
1669
+ },
1670
+ _getLayoutTemplate: function (t) {
1671
+ var self = this, template = self.layoutTemplates[t];
1672
+ if ($h.isEmpty(self.customLayoutTags)) {
1673
+ return template;
1674
+ }
1675
+ return $h.replaceTags(template, self.customLayoutTags);
1676
+ },
1677
+ _getPreviewTemplate: function (t) {
1678
+ var self = this, template = self.previewTemplates[t];
1679
+ if ($h.isEmpty(self.customPreviewTags)) {
1680
+ return template;
1681
+ }
1682
+ return $h.replaceTags(template, self.customPreviewTags);
1683
+ },
1684
+ _getOutData: function (jqXHR, responseData, filesData) {
1685
+ var self = this;
1686
+ jqXHR = jqXHR || {};
1687
+ responseData = responseData || {};
1688
+ filesData = filesData || self.filestack.slice(0) || {};
1689
+ return {
1690
+ form: self.formdata,
1691
+ files: filesData,
1692
+ filenames: self.filenames,
1693
+ filescount: self.getFilesCount(),
1694
+ extra: self._getExtraData(),
1695
+ response: responseData,
1696
+ reader: self.reader,
1697
+ jqXHR: jqXHR
1698
+ };
1699
+ },
1700
+ _getMsgSelected: function (n) {
1701
+ var self = this, strFiles = n === 1 ? self.fileSingle : self.filePlural;
1702
+ return n > 0 ? self.msgSelected.replace('{n}', n).replace('{files}', strFiles) : self.msgNoFilesSelected;
1703
+ },
1704
+ _getThumbs: function (css) {
1705
+ css = css || '';
1706
+ return this.$preview.find($h.FRAMES + ':not(.file-preview-initial)' + css);
1707
+ },
1708
+ _getExtraData: function (previewId, index) {
1709
+ var self = this, data = self.uploadExtraData;
1710
+ if (typeof self.uploadExtraData === "function") {
1711
+ data = self.uploadExtraData(previewId, index);
1712
+ }
1713
+ return data;
1714
+ },
1715
+ _initXhr: function (xhrobj, previewId, fileCount) {
1716
+ var self = this;
1717
+ if (xhrobj.upload) {
1718
+ xhrobj.upload.addEventListener('progress', function (event) {
1719
+ var pct = 0, total = event.total, position = event.loaded || event.position;
1720
+ /** @namespace event.lengthComputable */
1721
+ if (event.lengthComputable) {
1722
+ pct = Math.floor(position / total * 100);
1723
+ }
1724
+ if (previewId) {
1725
+ self._setAsyncUploadStatus(previewId, pct, fileCount);
1726
+ } else {
1727
+ self._setProgress(pct);
1728
+ }
1729
+ }, false);
1730
+ }
1731
+ return xhrobj;
1732
+ },
1733
+ _ajaxSubmit: function (fnBefore, fnSuccess, fnComplete, fnError, previewId, index) {
1734
+ var self = this, settings;
1735
+ if (!self._raise('filepreajax', [previewId, index])) {
1736
+ return;
1737
+ }
1738
+ self._uploadExtra(previewId, index);
1739
+ settings = $.extend(true, {}, {
1740
+ xhr: function () {
1741
+ var xhrobj = $.ajaxSettings.xhr();
1742
+ return self._initXhr(xhrobj, previewId, self.getFileStack().length);
1743
+ },
1744
+ url: self.uploadUrl,
1745
+ type: 'POST',
1746
+ dataType: 'json',
1747
+ data: self.formdata,
1748
+ cache: false,
1749
+ processData: false,
1750
+ contentType: false,
1751
+ beforeSend: fnBefore,
1752
+ success: fnSuccess,
1753
+ complete: fnComplete,
1754
+ error: fnError
1755
+ }, self.ajaxSettings);
1756
+ self.ajaxRequests.push($.ajax(settings));
1757
+ },
1758
+ _mergeArray: function (prop, content) {
1759
+ var self = this, arr1 = $h.cleanArray(self[prop]), arr2 = $h.cleanArray(content);
1760
+ self[prop] = arr1.concat(arr2);
1761
+ },
1762
+ _initUploadSuccess: function (out, $thumb, allFiles) {
1763
+ var self = this, append, data, index, $div, $newCache, content, config, tags, i;
1764
+ if (!self.showPreview || typeof out !== 'object' || $.isEmptyObject(out)) {
1765
+ return;
1766
+ }
1767
+ if (out.initialPreview !== undefined && out.initialPreview.length > 0) {
1768
+ self.hasInitData = true;
1769
+ content = out.initialPreview || [];
1770
+ config = out.initialPreviewConfig || [];
1771
+ tags = out.initialPreviewThumbTags || [];
1772
+ append = out.append === undefined || out.append ? true : false;
1773
+ if (content.length > 0 && !$h.isArray(content)) {
1774
+ content = content.split(self.initialPreviewDelimiter);
1775
+ }
1776
+ self._mergeArray('initialPreview', content);
1777
+ self._mergeArray('initialPreviewConfig', config);
1778
+ self._mergeArray('initialPreviewThumbTags', tags);
1779
+ if ($thumb !== undefined) {
1780
+ if (!allFiles) {
1781
+ index = self.previewCache.add(content, config[0], tags[0], append);
1782
+ data = self.previewCache.get(index, false);
1783
+ $div = $(document.createElement('div')).html(data).hide().insertAfter($thumb);
1784
+ $newCache = $div.find('.kv-zoom-cache');
1785
+ if ($newCache && $newCache.length) {
1786
+ $newCache.insertAfter($thumb);
1787
+ }
1788
+ $thumb.fadeOut('slow', function () {
1789
+ var $newThumb = $div.find('.file-preview-frame');
1790
+ if ($newThumb && $newThumb.length) {
1791
+ $newThumb.insertBefore($thumb).fadeIn('slow').css('display:inline-block');
1792
+ }
1793
+ self._initPreviewActions();
1794
+ self._clearFileInput();
1795
+ $h.cleanZoomCache(self.$preview.find('#zoom-' + $thumb.attr('id')));
1796
+ $thumb.remove();
1797
+ $div.remove();
1798
+ self._initSortable();
1799
+ });
1800
+ } else {
1801
+ i = $thumb.attr('data-fileindex');
1802
+ self.uploadCache.content[i] = content[0];
1803
+ self.uploadCache.config[i] = config[0] || [];
1804
+ self.uploadCache.tags[i] = tags[0] || [];
1805
+ self.uploadCache.append = append;
1806
+ }
1807
+ } else {
1808
+ self.previewCache.set(content, config, tags, append);
1809
+ self._initPreview();
1810
+ self._initPreviewActions();
1811
+ }
1812
+ }
1813
+ },
1814
+ _initSuccessThumbs: function () {
1815
+ var self = this;
1816
+ if (!self.showPreview) {
1817
+ return;
1818
+ }
1819
+ self._getThumbs($h.FRAMES + '.file-preview-success').each(function () {
1820
+ var $thumb = $(this), $preview = self.$preview, $remove = $thumb.find('.kv-file-remove');
1821
+ $remove.removeAttr('disabled');
1822
+ self._handler($remove, 'click', function () {
1823
+ var id = $thumb.attr('id'),
1824
+ out = self._raise('filesuccessremove', [id, $thumb.attr('data-fileindex')]);
1825
+ $h.cleanMemory($thumb);
1826
+ if (out === false) {
1827
+ return;
1828
+ }
1829
+ $thumb.fadeOut('slow', function () {
1830
+ $h.cleanZoomCache($preview.find('#zoom-' + id));
1831
+ $thumb.remove();
1832
+ if (!$preview.find($h.FRAMES).length) {
1833
+ self.reset();
1834
+ }
1835
+ });
1836
+ });
1837
+ });
1838
+ },
1839
+ _checkAsyncComplete: function () {
1840
+ var self = this, previewId, i;
1841
+ for (i = 0; i < self.filestack.length; i++) {
1842
+ if (self.filestack[i]) {
1843
+ previewId = self.previewInitId + "-" + i;
1844
+ if ($.inArray(previewId, self.uploadLog) === -1) {
1845
+ return false;
1846
+ }
1847
+ }
1848
+ }
1849
+ return (self.uploadAsyncCount === self.uploadLog.length);
1850
+ },
1851
+ _uploadExtra: function (previewId, index) {
1852
+ var self = this, data = self._getExtraData(previewId, index);
1853
+ if (data.length === 0) {
1854
+ return;
1855
+ }
1856
+ $.each(data, function (key, value) {
1857
+ self.formdata.append(key, value);
1858
+ });
1859
+ },
1860
+ _uploadSingle: function (i, files, allFiles) {
1861
+ var self = this, total = self.getFileStack().length, formdata = new FormData(), outData,
1862
+ previewId = self.previewInitId + "-" + i, $thumb, chkComplete, $btnUpload, $btnDelete,
1863
+ hasPostData = self.filestack.length > 0 || !$.isEmptyObject(self.uploadExtraData),
1864
+ $prog = $('#' + previewId).find('.file-thumb-progress'),
1865
+ fnBefore, fnSuccess, fnComplete, fnError, updateUploadLog, params = {id: previewId, index: i};
1866
+ self.formdata = formdata;
1867
+ if (self.showPreview) {
1868
+ $thumb = $('#' + previewId + ':not(.file-preview-initial)');
1869
+ $btnUpload = $thumb.find('.kv-file-upload');
1870
+ $btnDelete = $thumb.find('.kv-file-remove');
1871
+ $prog.removeClass('hide');
1872
+ }
1873
+ if (total === 0 || !hasPostData || ($btnUpload && $btnUpload.hasClass('disabled')) || self._abort(params)) {
1874
+ return;
1875
+ }
1876
+ updateUploadLog = function (i, previewId) {
1877
+ self.updateStack(i, undefined);
1878
+ self.uploadLog.push(previewId);
1879
+ if (self._checkAsyncComplete()) {
1880
+ self.fileBatchCompleted = true;
1881
+ }
1882
+ };
1883
+ chkComplete = function () {
1884
+ var u = self.uploadCache, $initThumbs, i, j, len = 0, data = self.cacheInitialPreview;
1885
+ if (!self.fileBatchCompleted) {
1886
+ return;
1887
+ }
1888
+ if (data && data.content) {
1889
+ len = data.content.length;
1890
+ }
1891
+ setTimeout(function () {
1892
+ if (self.showPreview) {
1893
+ self.previewCache.set(u.content, u.config, u.tags, u.append);
1894
+ if (len) {
1895
+ for (i = 0; i < u.content.length; i++) {
1896
+ j = i + len;
1897
+ data.content[j] = u.content[i];
1898
+ if (data.config.length) {
1899
+ data.config[j] = u.config[i];
1900
+ }
1901
+ if (data.tags.length) {
1902
+ data.tags[j] = u.tags[i];
1903
+ }
1904
+ }
1905
+ self.initialPreview = $h.cleanArray(data.content);
1906
+ self.initialPreviewConfig = $h.cleanArray(data.config);
1907
+ self.initialPreviewThumbTags = $h.cleanArray(data.tags);
1908
+ } else {
1909
+ self.initialPreview = u.content;
1910
+ self.initialPreviewConfig = u.config;
1911
+ self.initialPreviewThumbTags = u.tags;
1912
+ }
1913
+ self.cacheInitialPreview = {};
1914
+ if (self.hasInitData) {
1915
+ self._initPreview();
1916
+ self._initPreviewActions();
1917
+ }
1918
+ }
1919
+ self.unlock();
1920
+ self._clearFileInput();
1921
+ $initThumbs = self.$preview.find('.file-preview-initial');
1922
+ if (self.uploadAsync && $initThumbs.length) {
1923
+ $h.addCss($initThumbs, $h.SORT_CSS);
1924
+ self._initSortable();
1925
+ }
1926
+ self._raise('filebatchuploadcomplete', [self.filestack, self._getExtraData()]);
1927
+ self.uploadCount = 0;
1928
+ self.uploadStatus = {};
1929
+ self.uploadLog = [];
1930
+ self._setProgress(101);
1931
+ }, 100);
1932
+ };
1933
+ fnBefore = function (jqXHR) {
1934
+ outData = self._getOutData(jqXHR);
1935
+ self.fileBatchCompleted = false;
1936
+ if (self.showPreview) {
1937
+ if (!$thumb.hasClass('file-preview-success')) {
1938
+ self._setThumbStatus($thumb, 'Loading');
1939
+ $h.addCss($thumb, 'file-uploading');
1940
+ }
1941
+ $btnUpload.attr('disabled', true);
1942
+ $btnDelete.attr('disabled', true);
1943
+ }
1944
+ if (!allFiles) {
1945
+ self.lock();
1946
+ }
1947
+ self._raise('filepreupload', [outData, previewId, i]);
1948
+ $.extend(true, params, outData);
1949
+ if (self._abort(params)) {
1950
+ jqXHR.abort();
1951
+ self._setProgressCancelled();
1952
+ }
1953
+ };
1954
+ fnSuccess = function (data, textStatus, jqXHR) {
1955
+ var pid = self.showPreview && $thumb.attr('id') ? $thumb.attr('id') : previewId;
1956
+ outData = self._getOutData(jqXHR, data);
1957
+ $.extend(true, params, outData);
1958
+ setTimeout(function () {
1959
+ if ($h.isEmpty(data) || $h.isEmpty(data.error)) {
1960
+ if (self.showPreview) {
1961
+ self._setThumbStatus($thumb, 'Success');
1962
+ $btnUpload.hide();
1963
+ self._initUploadSuccess(data, $thumb, allFiles);
1964
+ self._setProgress(101, $prog);
1965
+ }
1966
+ self._raise('fileuploaded', [outData, pid, i]);
1967
+ if (!allFiles) {
1968
+ self.updateStack(i, undefined);
1969
+ } else {
1970
+ updateUploadLog(i, pid);
1971
+ }
1972
+ } else {
1973
+ self._showUploadError(data.error, params);
1974
+ self._setPreviewError($thumb, i);
1975
+ if (allFiles) {
1976
+ updateUploadLog(i, pid);
1977
+ }
1978
+ }
1979
+ }, 100);
1980
+ };
1981
+ fnComplete = function () {
1982
+ setTimeout(function () {
1983
+ if (self.showPreview) {
1984
+ $btnUpload.removeAttr('disabled');
1985
+ $btnDelete.removeAttr('disabled');
1986
+ $thumb.removeClass('file-uploading');
1987
+ }
1988
+ if (!allFiles) {
1989
+ self.unlock(false);
1990
+ self._clearFileInput();
1991
+ } else {
1992
+ chkComplete();
1993
+ }
1994
+ self._initSuccessThumbs();
1995
+ }, 100);
1996
+ };
1997
+ fnError = function (jqXHR, textStatus, errorThrown) {
1998
+ var op = self.ajaxOperations.uploadThumb,
1999
+ errMsg = self._parseError(op, jqXHR, errorThrown, (allFiles ? files[i].name : null));
2000
+ setTimeout(function () {
2001
+ if (allFiles) {
2002
+ updateUploadLog(i, previewId);
2003
+ }
2004
+ self.uploadStatus[previewId] = 100;
2005
+ self._setPreviewError($thumb, i);
2006
+ $.extend(true, params, self._getOutData(jqXHR));
2007
+ self._setProgress(101, $prog, self.msgAjaxProgressError.replace('{operation}', op));
2008
+ self._showUploadError(errMsg, params);
2009
+ }, 100);
2010
+ };
2011
+ formdata.append(self.uploadFileAttr, files[i], self.filenames[i]);
2012
+ formdata.append('file_id', i);
2013
+ self._ajaxSubmit(fnBefore, fnSuccess, fnComplete, fnError, previewId, i);
2014
+ },
2015
+ _uploadBatch: function () {
2016
+ var self = this, files = self.filestack, total = files.length, params = {}, fnBefore, fnSuccess, fnError,
2017
+ fnComplete, hasPostData = self.filestack.length > 0 || !$.isEmptyObject(self.uploadExtraData),
2018
+ setAllUploaded;
2019
+ self.formdata = new FormData();
2020
+ if (total === 0 || !hasPostData || self._abort(params)) {
2021
+ return;
2022
+ }
2023
+ setAllUploaded = function () {
2024
+ $.each(files, function (key) {
2025
+ self.updateStack(key, undefined);
2026
+ });
2027
+ self._clearFileInput();
2028
+ };
2029
+ fnBefore = function (jqXHR) {
2030
+ self.lock();
2031
+ var outData = self._getOutData(jqXHR);
2032
+ if (self.showPreview) {
2033
+ self._getThumbs().each(function () {
2034
+ var $thumb = $(this), $btnUpload = $thumb.find('.kv-file-upload'),
2035
+ $btnDelete = $thumb.find('.kv-file-remove');
2036
+ if (!$thumb.hasClass('file-preview-success')) {
2037
+ self._setThumbStatus($thumb, 'Loading');
2038
+ $h.addCss($thumb, 'file-uploading');
2039
+ }
2040
+ $btnUpload.attr('disabled', true);
2041
+ $btnDelete.attr('disabled', true);
2042
+ });
2043
+ }
2044
+ self._raise('filebatchpreupload', [outData]);
2045
+ if (self._abort(outData)) {
2046
+ jqXHR.abort();
2047
+ self._setProgressCancelled();
2048
+ }
2049
+ };
2050
+ fnSuccess = function (data, textStatus, jqXHR) {
2051
+ /** @namespace data.errorkeys */
2052
+ var outData = self._getOutData(jqXHR, data), $thumbs = self._getThumbs(':not(.file-preview-error)'),
2053
+ key = 0,
2054
+ keys = $h.isEmpty(data) || $h.isEmpty(data.errorkeys) ? [] : data.errorkeys;
2055
+ if ($h.isEmpty(data) || $h.isEmpty(data.error)) {
2056
+ self._raise('filebatchuploadsuccess', [outData]);
2057
+ setAllUploaded();
2058
+ if (self.showPreview) {
2059
+ $thumbs.each(function () {
2060
+ var $thumb = $(this), $btnUpload = $thumb.find('.kv-file-upload');
2061
+ $thumb.find('.kv-file-upload').hide();
2062
+ self._setThumbStatus($thumb, 'Success');
2063
+ $thumb.removeClass('file-uploading');
2064
+ $btnUpload.removeAttr('disabled');
2065
+ });
2066
+ self._initUploadSuccess(data);
2067
+ } else {
2068
+ self.reset();
2069
+ }
2070
+ self._setProgress(101);
2071
+ } else {
2072
+ if (self.showPreview) {
2073
+ $thumbs.each(function () {
2074
+ var $thumb = $(this), $btnDelete = $thumb.find('.kv-file-remove'),
2075
+ $btnUpload = $thumb.find('.kv-file-upload');
2076
+ $thumb.removeClass('file-uploading');
2077
+ $btnUpload.removeAttr('disabled');
2078
+ $btnDelete.removeAttr('disabled');
2079
+ if (keys.length === 0) {
2080
+ self._setPreviewError($thumb);
2081
+ return;
2082
+ }
2083
+ if ($.inArray(key, keys) !== -1) {
2084
+ self._setPreviewError($thumb);
2085
+ } else {
2086
+ $thumb.find('.kv-file-upload').hide();
2087
+ self._setThumbStatus($thumb, 'Success');
2088
+ self.updateStack(key, undefined);
2089
+ }
2090
+ key++;
2091
+ });
2092
+ self._initUploadSuccess(data);
2093
+ }
2094
+ self._showUploadError(data.error, outData, 'filebatchuploaderror');
2095
+ }
2096
+ };
2097
+ fnComplete = function () {
2098
+ self.unlock();
2099
+ self._initSuccessThumbs();
2100
+ self._clearFileInput();
2101
+ self._raise('filebatchuploadcomplete', [self.filestack, self._getExtraData()]);
2102
+ };
2103
+ fnError = function (jqXHR, textStatus, errorThrown) {
2104
+ var outData = self._getOutData(jqXHR), op = self.ajaxOperations.uploadBatch,
2105
+ errMsg = self._parseError(op, jqXHR, errorThrown);
2106
+ self._showUploadError(errMsg, outData, 'filebatchuploaderror');
2107
+ self.uploadFileCount = total - 1;
2108
+ if (!self.showPreview) {
2109
+ return;
2110
+ }
2111
+ self._getThumbs().each(function () {
2112
+ var $thumb = $(this), key = $thumb.attr('data-fileindex');
2113
+ $thumb.removeClass('file-uploading');
2114
+ if (self.filestack[key] !== undefined) {
2115
+ self._setPreviewError($thumb);
2116
+ }
2117
+ });
2118
+ self._getThumbs().removeClass('file-uploading');
2119
+ self._getThumbs(' .kv-file-upload').removeAttr('disabled');
2120
+ self._getThumbs(' .kv-file-delete').removeAttr('disabled');
2121
+ self._setProgress(101, self.$progress, self.msgAjaxProgressError.replace('{operation}', op));
2122
+ };
2123
+ $.each(files, function (key, data) {
2124
+ if (!$h.isEmpty(files[key])) {
2125
+ self.formdata.append(self.uploadFileAttr, data, self.filenames[key]);
2126
+ }
2127
+ });
2128
+ self._ajaxSubmit(fnBefore, fnSuccess, fnComplete, fnError);
2129
+ },
2130
+ _uploadExtraOnly: function () {
2131
+ var self = this, params = {}, fnBefore, fnSuccess, fnComplete, fnError;
2132
+ self.formdata = new FormData();
2133
+ if (self._abort(params)) {
2134
+ return;
2135
+ }
2136
+ fnBefore = function (jqXHR) {
2137
+ self.lock();
2138
+ var outData = self._getOutData(jqXHR);
2139
+ self._raise('filebatchpreupload', [outData]);
2140
+ self._setProgress(50);
2141
+ params.data = outData;
2142
+ params.xhr = jqXHR;
2143
+ if (self._abort(params)) {
2144
+ jqXHR.abort();
2145
+ self._setProgressCancelled();
2146
+ }
2147
+ };
2148
+ fnSuccess = function (data, textStatus, jqXHR) {
2149
+ var outData = self._getOutData(jqXHR, data);
2150
+ if ($h.isEmpty(data) || $h.isEmpty(data.error)) {
2151
+ self._raise('filebatchuploadsuccess', [outData]);
2152
+ self._clearFileInput();
2153
+ self._initUploadSuccess(data);
2154
+ self._setProgress(101);
2155
+ } else {
2156
+ self._showUploadError(data.error, outData, 'filebatchuploaderror');
2157
+ }
2158
+ };
2159
+ fnComplete = function () {
2160
+ self.unlock();
2161
+ self._clearFileInput();
2162
+ self._raise('filebatchuploadcomplete', [self.filestack, self._getExtraData()]);
2163
+ };
2164
+ fnError = function (jqXHR, textStatus, errorThrown) {
2165
+ var outData = self._getOutData(jqXHR), op = self.ajaxOperations.uploadExtra,
2166
+ errMsg = self._parseError(op, jqXHR, errorThrown);
2167
+ params.data = outData;
2168
+ self._showUploadError(errMsg, outData, 'filebatchuploaderror');
2169
+ self._setProgress(101, self.$progress, self.msgAjaxProgressError.replace('{operation}', op));
2170
+ };
2171
+ self._ajaxSubmit(fnBefore, fnSuccess, fnComplete, fnError);
2172
+ },
2173
+ _deleteFileIndex: function ($frame) {
2174
+ var self = this, ind = $frame.attr('data-fileindex');
2175
+ if (ind.substring(0, 5) === 'init_') {
2176
+ ind = parseInt(ind.replace('init_', ''));
2177
+ self.initialPreview = $h.spliceArray(self.initialPreview, ind);
2178
+ self.initialPreviewConfig = $h.spliceArray(self.initialPreviewConfig, ind);
2179
+ self.initialPreviewThumbTags = $h.spliceArray(self.initialPreviewThumbTags, ind);
2180
+ self.$preview.find($h.FRAMES).each(function () {
2181
+ var $nFrame = $(this), nInd = $nFrame.attr('data-fileindex');
2182
+ if (nInd.substring(0, 5) === 'init_') {
2183
+ nInd = parseInt(nInd.replace('init_', ''));
2184
+ if (nInd > ind) {
2185
+ nInd--;
2186
+ $nFrame.attr('data-fileindex', 'init_' + nInd);
2187
+ }
2188
+ }
2189
+ });
2190
+ if (self.uploadAsync) {
2191
+ self.cacheInitialPreview = self.getPreview();
2192
+ }
2193
+ }
2194
+ },
2195
+ _initFileActions: function () {
2196
+ var self = this, $preview = self.$preview;
2197
+ if (!self.showPreview) {
2198
+ return;
2199
+ }
2200
+ self._initZoomButton();
2201
+ $preview.find($h.FRAMES + ' .kv-file-remove').each(function () {
2202
+ var $el = $(this), $frame = $el.closest($h.FRAMES), hasError, id = $frame.attr('id'),
2203
+ ind = $frame.attr('data-fileindex'), n, cap, status;
2204
+ self._handler($el, 'click', function () {
2205
+ status = self._raise('filepreremove', [id, ind]);
2206
+ if (status === false || !self._validateMinCount()) {
2207
+ return false;
2208
+ }
2209
+ hasError = $frame.hasClass('file-preview-error');
2210
+ $h.cleanMemory($frame);
2211
+ $frame.fadeOut('slow', function () {
2212
+ $h.cleanZoomCache($preview.find('#zoom-' + id));
2213
+ self.updateStack(ind, undefined);
2214
+ self._clearObjects($frame);
2215
+ $frame.remove();
2216
+ if (id && hasError) {
2217
+ self.$errorContainer.find('li[data-file-id="' + id + '"]').fadeOut('fast', function () {
2218
+ $(this).remove();
2219
+ if (!self._errorsExist()) {
2220
+ self._resetErrors();
2221
+ }
2222
+ });
2223
+ }
2224
+ self._clearFileInput();
2225
+ var filestack = self.getFileStack(true), chk = self.previewCache.count(),
2226
+ len = filestack.length,
2227
+ hasThumb = self.showPreview && $preview.find($h.FRAMES).length;
2228
+ if (len === 0 && chk === 0 && !hasThumb) {
2229
+ self.reset();
2230
+ } else {
2231
+ n = chk + len;
2232
+ cap = n > 1 ? self._getMsgSelected(n) : (filestack[0] ? self._getFileNames()[0] : '');
2233
+ self._setCaption(cap);
2234
+ }
2235
+ self._raise('fileremoved', [id, ind]);
2236
+ });
2237
+ });
2238
+ });
2239
+ self.$preview.find($h.FRAMES + ' .kv-file-upload').each(function () {
2240
+ var $el = $(this);
2241
+ self._handler($el, 'click', function () {
2242
+ var $frame = $el.closest($h.FRAMES), ind = $frame.attr('data-fileindex');
2243
+ if (!$frame.hasClass('file-preview-error')) {
2244
+ self._uploadSingle(ind, self.filestack, false);
2245
+ }
2246
+ });
2247
+ });
2248
+ },
2249
+ _initPreviewActions: function () {
2250
+ var self = this, $preview = self.$preview, deleteExtraData = self.deleteExtraData || {},
2251
+ btnRemove = $h.FRAMES + ' .kv-file-remove',
2252
+ resetProgress = function () {
2253
+ var hasFiles = self.isUploadable ? self.previewCache.count() : self.$element.get(0).files.length;
2254
+ if ($preview.find(btnRemove).length === 0 && !hasFiles) {
2255
+ self.reset();
2256
+ self.initialCaption = '';
2257
+ }
2258
+ };
2259
+ self._initZoomButton();
2260
+ $preview.find(btnRemove).each(function () {
2261
+ var $el = $(this), vUrl = $el.data('url') || self.deleteUrl, vKey = $el.data('key');
2262
+ if ($h.isEmpty(vUrl) || vKey === undefined) {
2263
+ return;
2264
+ }
2265
+ var $frame = $el.closest($h.FRAMES), cache = self.previewCache.data,
2266
+ settings, params, index = $frame.attr('data-fileindex'), config, extraData;
2267
+ index = parseInt(index.replace('init_', ''));
2268
+ config = $h.isEmpty(cache.config) && $h.isEmpty(cache.config[index]) ? null : cache.config[index];
2269
+ extraData = $h.isEmpty(config) || $h.isEmpty(config.extra) ? deleteExtraData : config.extra;
2270
+ if (typeof extraData === "function") {
2271
+ extraData = extraData();
2272
+ }
2273
+ params = {id: $el.attr('id'), key: vKey, extra: extraData};
2274
+ settings = $.extend(true, {}, {
2275
+ url: vUrl,
2276
+ type: 'POST',
2277
+ dataType: 'json',
2278
+ data: $.extend(true, {}, {key: vKey}, extraData),
2279
+ beforeSend: function (jqXHR) {
2280
+ self.ajaxAborted = false;
2281
+ self._raise('filepredelete', [vKey, jqXHR, extraData]);
2282
+ if (self.ajaxAborted) {
2283
+ jqXHR.abort();
2284
+ } else {
2285
+ $h.addCss($frame, 'file-uploading');
2286
+ $h.addCss($el, 'disabled');
2287
+ }
2288
+ },
2289
+ success: function (data, textStatus, jqXHR) {
2290
+ var n, cap;
2291
+ if ($h.isEmpty(data) || $h.isEmpty(data.error)) {
2292
+ index = parseInt(($frame.attr('data-fileindex')).replace('init_', ''));
2293
+ self.previewCache.unset(index);
2294
+ n = self.previewCache.count();
2295
+ cap = n > 0 ? self._getMsgSelected(n) : '';
2296
+ self._deleteFileIndex($frame);
2297
+ self._setCaption(cap);
2298
+ self._raise('filedeleted', [vKey, jqXHR, extraData]);
2299
+ } else {
2300
+ params.jqXHR = jqXHR;
2301
+ params.response = data;
2302
+ self._showError(data.error, params, 'filedeleteerror');
2303
+ $frame.removeClass('file-uploading');
2304
+ $el.removeClass('disabled');
2305
+ resetProgress();
2306
+ return;
2307
+ }
2308
+ $frame.removeClass('file-uploading').addClass('file-deleted');
2309
+ $frame.fadeOut('slow', function () {
2310
+ $h.cleanZoomCache($preview.find('#zoom-' + $frame.attr('id')));
2311
+ self._clearObjects($frame);
2312
+ $frame.remove();
2313
+ resetProgress();
2314
+ if (!n && self.getFileStack().length === 0) {
2315
+ self._setCaption('');
2316
+ self.reset();
2317
+ }
2318
+ });
2319
+ },
2320
+ error: function (jqXHR, textStatus, errorThrown) {
2321
+ var op = self.ajaxOperations.deleteThumb, errMsg = self._parseError(op, jqXHR, errorThrown);
2322
+ params.jqXHR = jqXHR;
2323
+ params.response = {};
2324
+ self._showError(errMsg, params, 'filedeleteerror');
2325
+ $frame.removeClass('file-uploading');
2326
+ resetProgress();
2327
+ }
2328
+ }, self.ajaxDeleteSettings);
2329
+ self._handler($el, 'click', function () {
2330
+ if (!self._validateMinCount()) {
2331
+ return false;
2332
+ }
2333
+ $.ajax(settings);
2334
+ });
2335
+ });
2336
+ },
2337
+ _hideFileIcon: function () {
2338
+ if (this.overwriteInitial) {
2339
+ this.$captionContainer.find('.kv-caption-icon').hide();
2340
+ }
2341
+ },
2342
+ _showFileIcon: function () {
2343
+ this.$captionContainer.find('.kv-caption-icon').show();
2344
+ },
2345
+ _getSize: function (bytes) {
2346
+ var self = this, size = parseFloat(bytes), i, func = self.fileSizeGetter, sizes, out;
2347
+ if (!$.isNumeric(bytes) || !$.isNumeric(size)) {
2348
+ return '';
2349
+ }
2350
+ if (typeof func === 'function') {
2351
+ out = func(size);
2352
+ } else {
2353
+ if (size === 0) {
2354
+ out = '0.00 B';
2355
+ } else {
2356
+ i = Math.floor(Math.log(size) / Math.log(1024));
2357
+ sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
2358
+ out = (size / Math.pow(1024, i)).toFixed(2) * 1 + ' ' + sizes[i];
2359
+ }
2360
+ }
2361
+ return self._getLayoutTemplate('size').replace('{sizeText}', out);
2362
+ },
2363
+ _generatePreviewTemplate: function (cat, data, fname, ftype, previewId, isError, size, frameClass, foot, ind, templ) {
2364
+ var self = this, caption = self.slug(fname), prevContent, zoomContent = '',
2365
+ config = self.previewSettings[cat] || self.defaults.previewSettings[cat],
2366
+ w = config && config.width ? config.width : '', h = config && config.height ? config.height : '',
2367
+ footer = foot || self._renderFileFooter(caption, size, ($h.isEmpty(w) ? 'auto' : w), isError),
2368
+ hasIconSetting = self._getPreviewIcon(fname), typeCss = 'type-default',
2369
+ forcePrevIcon = hasIconSetting && self.preferIconicPreview,
2370
+ forceZoomIcon = hasIconSetting && self.preferIconicZoomPreview,
2371
+ getContent = function (c, d, zoom, frameCss) {
2372
+ var id = zoom ? 'zoom-' + previewId : previewId, tmplt = self._getPreviewTemplate(c),
2373
+ css = (frameClass || '') + ' ' + frameCss;
2374
+ if (self.frameClass) {
2375
+ css = self.frameClass + ' ' + css;
2376
+ }
2377
+ if (zoom) {
2378
+ css = css.replace(' ' + $h.SORT_CSS, '');
2379
+ }
2380
+ tmplt = self._parseFilePreviewIcon(tmplt, fname);
2381
+ if (c === 'text') {
2382
+ d = $h.htmlEncode(d);
2383
+ }
2384
+ if (cat === 'object' && !ftype) {
2385
+ $.each(self.defaults.fileTypeSettings, function (key, func) {
2386
+ if (key === 'object' || key === 'other') {
2387
+ return;
2388
+ }
2389
+ if (func(fname, ftype)) {
2390
+ typeCss = 'type-' + key;
2391
+ }
2392
+ });
2393
+ }
2394
+ return tmplt.setTokens({
2395
+ 'previewId': id,
2396
+ 'caption': caption,
2397
+ 'frameClass': css,
2398
+ 'type': ftype,
2399
+ 'fileindex': ind,
2400
+ 'width': w,
2401
+ 'height': h,
2402
+ 'typeCss': typeCss,
2403
+ 'footer': footer,
2404
+ 'data': d,
2405
+ 'template': templ || cat
2406
+ });
2407
+ };
2408
+ ind = ind || previewId.slice(previewId.lastIndexOf('-') + 1);
2409
+ if (self.fileActionSettings.showZoom) {
2410
+ zoomContent = getContent((forceZoomIcon ? 'other' : cat), data, true, 'kv-zoom-thumb');
2411
+ }
2412
+ zoomContent = '\n' + self._getLayoutTemplate('zoomCache').replace('{zoomContent}', zoomContent);
2413
+ prevContent = getContent((forcePrevIcon ? 'other' : cat), data, false, 'kv-preview-thumb');
2414
+ return prevContent + zoomContent;
2415
+ },
2416
+ _previewDefault: function (file, previewId, isDisabled) {
2417
+ var self = this, $preview = self.$preview;
2418
+ if (!self.showPreview) {
2419
+ return;
2420
+ }
2421
+ var fname = file ? file.name : '', ftype = file ? file.type : '', content, size = file.size || 0,
2422
+ caption = self.slug(fname), isError = isDisabled === true && !self.isUploadable,
2423
+ data = $h.objUrl.createObjectURL(file);
2424
+ self._clearDefaultPreview();
2425
+ content = self._generatePreviewTemplate('other', data, fname, ftype, previewId, isError, size);
2426
+ $preview.append("\n" + content);
2427
+ self._setThumbAttr(previewId, caption, size);
2428
+ if (isDisabled === true && self.isUploadable) {
2429
+ self._setThumbStatus($('#' + previewId), 'Error');
2430
+ }
2431
+ },
2432
+ _previewFile: function (i, file, theFile, previewId, data) {
2433
+ if (!this.showPreview) {
2434
+ return;
2435
+ }
2436
+ var self = this, cat = self._parseFileType(file), fname = file ? file.name : '', caption = self.slug(fname),
2437
+ types = self.allowedPreviewTypes, mimes = self.allowedPreviewMimeTypes, $preview = self.$preview,
2438
+ chkTypes = types && types.indexOf(cat) >= 0, fsize = file.size || 0, ftype = file.type,
2439
+ iData = (cat === 'text' || cat === 'html' || cat === 'image') ? theFile.target.result : data, content,
2440
+ chkMimes = mimes && mimes.indexOf(ftype) !== -1;
2441
+ /** @namespace window.DOMPurify */
2442
+ if (cat === 'html' && self.purifyHtml && window.DOMPurify) {
2443
+ iData = window.DOMPurify.sanitize(iData);
2444
+ }
2445
+ if (chkTypes || chkMimes) {
2446
+ content = self._generatePreviewTemplate(cat, iData, fname, ftype, previewId, false, fsize);
2447
+ self._clearDefaultPreview();
2448
+ $preview.append("\n" + content);
2449
+ var $img = $preview.find('#' + previewId + ' img');
2450
+ if ($img.length && self.autoOrientImage) {
2451
+ $h.validateOrientation(file, function (value) {
2452
+ if (value) {
2453
+ var $zoomImg = $preview.find('#zoom-' + previewId + ' img'), css = 'rotate-' + value;
2454
+ if (value > 4) {
2455
+ css += ($img.width() > $img.height() ? ' is-portrait-gt4' : ' is-landscape-gt4');
2456
+ }
2457
+ $h.addCss($img, css);
2458
+ $h.addCss($zoomImg, css);
2459
+ self._raise('fileimageoriented', {'$img': $img, 'file': file});
2460
+ }
2461
+ self._validateImage(previewId, caption, ftype, fsize);
2462
+ $h.adjustOrientedImage($img);
2463
+ });
2464
+ } else {
2465
+ self._validateImage(previewId, caption, ftype, fsize);
2466
+ }
2467
+ } else {
2468
+ self._previewDefault(file, previewId);
2469
+ }
2470
+ self._setThumbAttr(previewId, caption, fsize);
2471
+ self._initSortable();
2472
+ },
2473
+ _setThumbAttr: function (id, caption, size) {
2474
+ var self = this, $frame = $('#' + id);
2475
+ if ($frame.length) {
2476
+ size = size && size > 0 ? self._getSize(size) : '';
2477
+ $frame.data({'caption': caption, 'size': size});
2478
+ }
2479
+ },
2480
+ _setInitThumbAttr: function () {
2481
+ var self = this, data = self.previewCache.data, len = self.previewCache.count(true), config,
2482
+ caption, size, previewId;
2483
+ if (len === 0) {
2484
+ return;
2485
+ }
2486
+ for (var i = 0; i < len; i++) {
2487
+ config = data.config[i];
2488
+ previewId = self.previewInitId + '-' + 'init_' + i;
2489
+ caption = $h.ifSet('caption', config, $h.ifSet('filename', config));
2490
+ size = $h.ifSet('size', config);
2491
+ self._setThumbAttr(previewId, caption, size);
2492
+ }
2493
+ },
2494
+ _slugDefault: function (text) {
2495
+ return $h.isEmpty(text) ? '' : String(text).replace(/[\-\[\]\/\{}:;#%=\(\)\*\+\?\\\^\$\|<>&"']/g, '_');
2496
+ },
2497
+ _readFiles: function (files) {
2498
+ this.reader = new FileReader();
2499
+ var self = this, $el = self.$element, $preview = self.$preview, reader = self.reader,
2500
+ $container = self.$previewContainer, $status = self.$previewStatus, msgLoading = self.msgLoading,
2501
+ msgProgress = self.msgProgress, previewInitId = self.previewInitId, numFiles = files.length,
2502
+ settings = self.fileTypeSettings, ctr = self.filestack.length, readFile,
2503
+ fileTypes = self.allowedFileTypes, typLen = fileTypes ? fileTypes.length : 0,
2504
+ fileExt = self.allowedFileExtensions, strExt = $h.isEmpty(fileExt) ? '' : fileExt.join(', '),
2505
+ maxPreviewSize = self.maxFilePreviewSize && parseFloat(self.maxFilePreviewSize),
2506
+ canPreview = $preview.length && (!maxPreviewSize || isNaN(maxPreviewSize)),
2507
+ throwError = function (msg, file, previewId, index) {
2508
+ var p1 = $.extend(true, {}, self._getOutData({}, {}, files), {id: previewId, index: index}),
2509
+ p2 = {id: previewId, index: index, file: file, files: files};
2510
+ self._previewDefault(file, previewId, true);
2511
+ if (self.isUploadable) {
2512
+ self.addToStack(undefined);
2513
+ setTimeout(function () {
2514
+ readFile(index + 1);
2515
+ }, 100);
2516
+ }
2517
+ self._initFileActions();
2518
+ if (self.removeFromPreviewOnError) {
2519
+ $('#' + previewId).remove();
2520
+ }
2521
+ return self.isUploadable ? self._showUploadError(msg, p1) : self._showError(msg, p2);
2522
+ };
2523
+
2524
+ self.loadedImages = [];
2525
+ self.totalImagesCount = 0;
2526
+
2527
+ $.each(files, function (key, file) {
2528
+ var func = self.fileTypeSettings.image;
2529
+ if (func && func(file.type)) {
2530
+ self.totalImagesCount++;
2531
+ }
2532
+ });
2533
+ readFile = function (i) {
2534
+ if ($h.isEmpty($el.attr('multiple'))) {
2535
+ numFiles = 1;
2536
+ }
2537
+ if (i >= numFiles) {
2538
+ if (self.isUploadable && self.filestack.length > 0) {
2539
+ self._raise('filebatchselected', [self.getFileStack()]);
2540
+ } else {
2541
+ self._raise('filebatchselected', [files]);
2542
+ }
2543
+ $container.removeClass('file-thumb-loading');
2544
+ $status.html('');
2545
+ return;
2546
+ }
2547
+ var node = ctr + i, previewId = previewInitId + "-" + node, isText, isImage, file = files[i], fSizeKB,
2548
+ caption = file.name ? self.slug(file.name) : '', fileSize = (file.size || 0) / 1000, j, msg,
2549
+ fileExtExpr = '', previewData = $h.objUrl.createObjectURL(file), typ, chk, typ1, typ2,
2550
+ fileCount = 0, strTypes = '', func;
2551
+ if (typLen > 0) {
2552
+ for (j = 0; j < typLen; j++) {
2553
+ typ1 = fileTypes[j];
2554
+ typ2 = self.msgFileTypes[typ1] || typ1;
2555
+ strTypes += j === 0 ? typ2 : ', ' + typ2;
2556
+ }
2557
+ }
2558
+ if (caption === false) {
2559
+ readFile(i + 1);
2560
+ return;
2561
+ }
2562
+ if (caption.length === 0) {
2563
+ msg = self.msgInvalidFileName.replace('{name}', $h.htmlEncode(file.name));
2564
+ self.isError = throwError(msg, file, previewId, i);
2565
+ return;
2566
+ }
2567
+ if (!$h.isEmpty(fileExt)) {
2568
+ fileExtExpr = new RegExp('\\.(' + fileExt.join('|') + ')$', 'i');
2569
+ }
2570
+ fSizeKB = fileSize.toFixed(2);
2571
+ if (self.maxFileSize > 0 && fileSize > self.maxFileSize) {
2572
+ msg = self.msgSizeTooLarge.setTokens({
2573
+ 'name': caption,
2574
+ 'size': fSizeKB,
2575
+ 'maxSize': self.maxFileSize
2576
+ });
2577
+ self.isError = throwError(msg, file, previewId, i);
2578
+ return;
2579
+ }
2580
+ if (self.minFileSize !== null && fileSize <= $h.getNum(self.minFileSize)) {
2581
+ msg = self.msgSizeTooSmall.setTokens({
2582
+ 'name': caption,
2583
+ 'size': fSizeKB,
2584
+ 'minSize': self.minFileSize
2585
+ });
2586
+ self.isError = throwError(msg, file, previewId, i);
2587
+ return;
2588
+ }
2589
+ if (!$h.isEmpty(fileTypes) && $h.isArray(fileTypes)) {
2590
+ for (j = 0; j < fileTypes.length; j += 1) {
2591
+ typ = fileTypes[j];
2592
+ func = settings[typ];
2593
+ fileCount += !func || (typeof func !== 'function') ? 0 : (func(file.type, file.name) ? 1 : 0);
2594
+ }
2595
+ if (fileCount === 0) {
2596
+ msg = self.msgInvalidFileType.setTokens({'name': caption, 'types': strTypes});
2597
+ self.isError = throwError(msg, file, previewId, i);
2598
+ return;
2599
+ }
2600
+ }
2601
+ if (fileCount === 0 && !$h.isEmpty(fileExt) && $h.isArray(fileExt) && !$h.isEmpty(fileExtExpr)) {
2602
+ chk = $h.compare(caption, fileExtExpr);
2603
+ fileCount += $h.isEmpty(chk) ? 0 : chk.length;
2604
+ if (fileCount === 0) {
2605
+ msg = self.msgInvalidFileExtension.setTokens({'name': caption, 'extensions': strExt});
2606
+ self.isError = throwError(msg, file, previewId, i);
2607
+ return;
2608
+ }
2609
+ }
2610
+ if (!self.showPreview) {
2611
+ self.addToStack(file);
2612
+ setTimeout(function () {
2613
+ readFile(i + 1);
2614
+ }, 100);
2615
+ self._raise('fileloaded', [file, previewId, i, reader]);
2616
+ return;
2617
+ }
2618
+ if (!canPreview && fileSize > maxPreviewSize) {
2619
+ self.addToStack(file);
2620
+ $container.addClass('file-thumb-loading');
2621
+ self._previewDefault(file, previewId);
2622
+ self._initFileActions();
2623
+ self._updateFileDetails(numFiles);
2624
+ readFile(i + 1);
2625
+ return;
2626
+ }
2627
+ if ($preview.length && FileReader !== undefined) {
2628
+ $status.html(msgLoading.replace('{index}', i + 1).replace('{files}', numFiles));
2629
+ $container.addClass('file-thumb-loading');
2630
+ reader.onerror = function (evt) {
2631
+ self._errorHandler(evt, caption);
2632
+ };
2633
+ reader.onload = function (theFile) {
2634
+ self._previewFile(i, file, theFile, previewId, previewData);
2635
+ self._initFileActions();
2636
+ };
2637
+ reader.onloadend = function () {
2638
+ msg = msgProgress.setTokens({
2639
+ 'index': i + 1,
2640
+ 'files': numFiles,
2641
+ 'percent': 50,
2642
+ 'name': caption
2643
+ });
2644
+ setTimeout(function () {
2645
+ $status.html(msg);
2646
+ self._updateFileDetails(numFiles);
2647
+ readFile(i + 1);
2648
+ }, 100);
2649
+ self._raise('fileloaded', [file, previewId, i, reader]);
2650
+ };
2651
+ reader.onprogress = function (data) {
2652
+ if (data.lengthComputable) {
2653
+ var fact = (data.loaded / data.total) * 100, progress = Math.ceil(fact);
2654
+ msg = msgProgress.setTokens({
2655
+ 'index': i + 1,
2656
+ 'files': numFiles,
2657
+ 'percent': progress,
2658
+ 'name': caption
2659
+ });
2660
+ setTimeout(function () {
2661
+ $status.html(msg);
2662
+ }, 100);
2663
+ }
2664
+ };
2665
+ isText = settings.text;
2666
+ isImage = settings.image;
2667
+
2668
+ if (isText(file.type, caption)) {
2669
+ reader.readAsText(file, self.textEncoding);
2670
+ } else {
2671
+ if (isImage(file.type, caption)) {
2672
+ reader.readAsDataURL(file);
2673
+ } else {
2674
+ reader.readAsArrayBuffer(file);
2675
+ }
2676
+ }
2677
+ } else {
2678
+ self._previewDefault(file, previewId);
2679
+ setTimeout(function () {
2680
+ readFile(i + 1);
2681
+ self._updateFileDetails(numFiles);
2682
+ }, 100);
2683
+ self._raise('fileloaded', [file, previewId, i, reader]);
2684
+ }
2685
+ self.addToStack(file);
2686
+ };
2687
+
2688
+ readFile(0);
2689
+ self._updateFileDetails(numFiles, false);
2690
+ },
2691
+ _updateFileDetails: function (numFiles) {
2692
+ var self = this, $el = self.$element, fileStack = self.getFileStack(),
2693
+ name = ($h.isIE(9) && $h.findFileName($el.val())) ||
2694
+ ($el[0].files[0] && $el[0].files[0].name) || (fileStack.length && fileStack[0].name) || '',
2695
+ label = self.slug(name), n = self.isUploadable ? fileStack.length : numFiles,
2696
+ nFiles = self.previewCache.count() + n, log = n > 1 ? self._getMsgSelected(nFiles) : label;
2697
+ if (self.isError) {
2698
+ self.$previewContainer.removeClass('file-thumb-loading');
2699
+ self.$previewStatus.html('');
2700
+ self.$captionContainer.find('.kv-caption-icon').hide();
2701
+ } else {
2702
+ self._showFileIcon();
2703
+ }
2704
+ self._setCaption(log, self.isError);
2705
+ self.$container.removeClass('file-input-new file-input-ajax-new');
2706
+ if (arguments.length === 1) {
2707
+ self._raise('fileselect', [numFiles, label]);
2708
+ }
2709
+ if (self.previewCache.count()) {
2710
+ self._initPreviewActions();
2711
+ }
2712
+ },
2713
+ _setThumbStatus: function ($thumb, status) {
2714
+ var self = this;
2715
+ if (!self.showPreview) {
2716
+ return;
2717
+ }
2718
+ var icon = 'indicator' + status, msg = icon + 'Title',
2719
+ css = 'file-preview-' + status.toLowerCase(),
2720
+ $indicator = $thumb.find('.file-upload-indicator'),
2721
+ config = self.fileActionSettings;
2722
+ $thumb.removeClass('file-preview-success file-preview-error file-preview-loading');
2723
+ if (status === 'Error') {
2724
+ $thumb.find('.kv-file-upload').attr('disabled', true);
2725
+ }
2726
+ if (status === 'Success') {
2727
+ $thumb.find('.file-drag-handle').remove();
2728
+ $indicator.css('margin-left', 0);
2729
+ }
2730
+ $indicator.html(config[icon]);
2731
+ $indicator.attr('title', config[msg]);
2732
+ $thumb.addClass(css);
2733
+ },
2734
+ _setProgressCancelled: function () {
2735
+ var self = this;
2736
+ self._setProgress(101, self.$progress, self.msgCancelled);
2737
+ },
2738
+ _setProgress: function (p, $el, error) {
2739
+ var self = this, pct = Math.min(p, 100), out, pctLimit = self.progressUploadThreshold,
2740
+ t = p <= 100 ? self.progressTemplate : self.progressCompleteTemplate,
2741
+ template = pct < 100 ? self.progressTemplate : (error ? self.progressErrorTemplate : t);
2742
+ $el = $el || self.$progress;
2743
+ if (!$h.isEmpty(template)) {
2744
+ if (pctLimit && pct > pctLimit && p <= 100) {
2745
+ out = template.setTokens({'percent': pctLimit, 'status': self.msgUploadThreshold});
2746
+ } else {
2747
+ out = template.setTokens({'percent': pct, 'status': (p > 100 ? self.msgUploadEnd : pct + '%')});
2748
+ }
2749
+ $el.html(out);
2750
+ if (error) {
2751
+ $el.find('[role="progressbar"]').html(error);
2752
+ }
2753
+ }
2754
+ },
2755
+ _setFileDropZoneTitle: function () {
2756
+ var self = this, $zone = self.$container.find('.file-drop-zone'), title = self.dropZoneTitle, strFiles;
2757
+ if (self.isClickable) {
2758
+ strFiles = $h.isEmpty(self.$element.attr('multiple')) ? self.fileSingle : self.filePlural;
2759
+ title += self.dropZoneClickTitle.replace('{files}', strFiles);
2760
+ }
2761
+ $zone.find('.' + self.dropZoneTitleClass).remove();
2762
+ if (!self.isUploadable || !self.showPreview || $zone.length === 0 || self.getFileStack().length > 0 || !self.dropZoneEnabled) {
2763
+ return;
2764
+ }
2765
+ if ($zone.find($h.FRAMES).length === 0 && $h.isEmpty(self.defaultPreviewContent)) {
2766
+ $zone.prepend('<div class="' + self.dropZoneTitleClass + '">' + title + '</div>');
2767
+ }
2768
+ self.$container.removeClass('file-input-new');
2769
+ $h.addCss(self.$container, 'file-input-ajax-new');
2770
+ },
2771
+ _setAsyncUploadStatus: function (previewId, pct, total) {
2772
+ var self = this, sum = 0;
2773
+ self._setProgress(pct, $('#' + previewId).find('.file-thumb-progress'));
2774
+ self.uploadStatus[previewId] = pct;
2775
+ $.each(self.uploadStatus, function (key, value) {
2776
+ sum += value;
2777
+ });
2778
+ self._setProgress(Math.floor(sum / total));
2779
+
2780
+ },
2781
+ _validateMinCount: function () {
2782
+ var self = this, len = self.isUploadable ? self.getFileStack().length : self.$element.get(0).files.length;
2783
+ if (self.validateInitialCount && self.minFileCount > 0 && self._getFileCount(len - 1) < self.minFileCount) {
2784
+ self._noFilesError({});
2785
+ return false;
2786
+ }
2787
+ return true;
2788
+ },
2789
+ _getFileCount: function (fileCount) {
2790
+ var self = this, addCount = 0;
2791
+ if (self.validateInitialCount && !self.overwriteInitial) {
2792
+ addCount = self.previewCache.count();
2793
+ fileCount += addCount;
2794
+ }
2795
+ return fileCount;
2796
+ },
2797
+ _getFileId: function (file) {
2798
+ var self = this, custom = self.generateFileId, relativePath;
2799
+ if (typeof custom === 'function') {
2800
+ return custom(file, event);
2801
+ }
2802
+ if (!file) {
2803
+ return null;
2804
+ }
2805
+ /** @namespace file.webkitRelativePath */
2806
+ relativePath = file.webkitRelativePath || file.fileName || file.name || null;
2807
+ if (!relativePath) {
2808
+ return null;
2809
+ }
2810
+ return (file.size + '-' + relativePath.replace(/[^0-9a-zA-Z_-]/img, ''));
2811
+ },
2812
+ _getFileName: function (file) {
2813
+ return file && file.name ? this.slug(file.name) : undefined;
2814
+ },
2815
+ _getFileIds: function (skipNull) {
2816
+ var self = this;
2817
+ return self.fileids.filter(function (n) {
2818
+ return (skipNull ? n !== undefined : n !== undefined && n !== null);
2819
+ });
2820
+ },
2821
+ _getFileNames: function (skipNull) {
2822
+ var self = this;
2823
+ return self.filenames.filter(function (n) {
2824
+ return (skipNull ? n !== undefined : n !== undefined && n !== null);
2825
+ });
2826
+ },
2827
+ _setPreviewError: function ($thumb, i, val) {
2828
+ var self = this;
2829
+ if (i !== undefined) {
2830
+ self.updateStack(i, val);
2831
+ }
2832
+ if (self.removeFromPreviewOnError) {
2833
+ $thumb.remove();
2834
+ } else {
2835
+ self._setThumbStatus($thumb, 'Error');
2836
+ }
2837
+ },
2838
+ _checkDimensions: function (i, chk, $img, $thumb, fname, type, params) {
2839
+ var self = this, msg, dim, tag = chk === 'Small' ? 'min' : 'max', limit = self[tag + 'Image' + type],
2840
+ $imgEl, isValid;
2841
+ if ($h.isEmpty(limit) || !$img.length) {
2842
+ return;
2843
+ }
2844
+ $imgEl = $img[0];
2845
+ dim = (type === 'Width') ? $imgEl.naturalWidth || $imgEl.width : $imgEl.naturalHeight || $imgEl.height;
2846
+ isValid = chk === 'Small' ? dim >= limit : dim <= limit;
2847
+ if (isValid) {
2848
+ return;
2849
+ }
2850
+ msg = self['msgImage' + type + chk].setTokens({'name': fname, 'size': limit});
2851
+ self._showUploadError(msg, params);
2852
+ self._setPreviewError($thumb, i, null);
2853
+ },
2854
+ _validateImage: function (previewId, fname, ftype, fsize) {
2855
+ var self = this, $preview = self.$preview, params, w1, w2, $thumb = $preview.find("#" + previewId),
2856
+ i = $thumb.attr('data-fileindex'), $img = $thumb.find('img');
2857
+ fname = fname || 'Untitled';
2858
+ if (!$img.length) {
2859
+ return;
2860
+ }
2861
+ self._handler($img, 'load', function () {
2862
+ w1 = $thumb.width();
2863
+ w2 = $preview.width();
2864
+ if (w1 > w2) {
2865
+ $img.css('width', '100%');
2866
+ $thumb.css('width', '97%');
2867
+ }
2868
+ params = {ind: i, id: previewId};
2869
+ self._checkDimensions(i, 'Small', $img, $thumb, fname, 'Width', params);
2870
+ self._checkDimensions(i, 'Small', $img, $thumb, fname, 'Height', params);
2871
+ if (!self.resizeImage) {
2872
+ self._checkDimensions(i, 'Large', $img, $thumb, fname, 'Width', params);
2873
+ self._checkDimensions(i, 'Large', $img, $thumb, fname, 'Height', params);
2874
+ }
2875
+ self._raise('fileimageloaded', [previewId]);
2876
+ self.loadedImages.push({
2877
+ ind: i,
2878
+ img: $img,
2879
+ thumb: $thumb,
2880
+ pid: previewId,
2881
+ typ: ftype,
2882
+ siz: fsize,
2883
+ validated: false
2884
+ });
2885
+ self._validateAllImages();
2886
+ });
2887
+ },
2888
+ _validateAllImages: function () {
2889
+ var self = this, i, counter = {val: 0}, numImgs = self.loadedImages.length, config,
2890
+ fsize, minSize = self.resizeIfSizeMoreThan;
2891
+ if (numImgs !== self.totalImagesCount) {
2892
+ return;
2893
+ }
2894
+ self._raise('fileimagesloaded');
2895
+ if (!self.resizeImage) {
2896
+ return;
2897
+ }
2898
+ for (i = 0; i < self.loadedImages.length; i++) {
2899
+ config = self.loadedImages[i];
2900
+ if (config.validated) {
2901
+ continue;
2902
+ }
2903
+ fsize = config.siz;
2904
+ if (fsize && fsize > minSize * 1000) {
2905
+ self._getResizedImage(config, counter, numImgs);
2906
+ }
2907
+ self.loadedImages[i].validated = true;
2908
+ }
2909
+ },
2910
+ _getResizedImage: function (config, counter, numImgs) {
2911
+ var self = this, img = $(config.img)[0], width = img.naturalWidth, height = img.naturalHeight,
2912
+ ratio = 1, maxWidth = self.maxImageWidth || width, maxHeight = self.maxImageHeight || height,
2913
+ isValidImage = !!(width && height), chkWidth, chkHeight, canvas = self.imageCanvas,
2914
+ context = self.imageCanvasContext, type = config.typ, pid = config.pid, ind = config.ind,
2915
+ $thumb = config.thumb, throwError, msg;
2916
+ throwError = function (msg, params, ev) {
2917
+ if (self.isUploadable) {
2918
+ self._showUploadError(msg, params, ev);
2919
+ } else {
2920
+ self._showError(msg, params, ev);
2921
+ }
2922
+ self._setPreviewError($thumb, ind);
2923
+ };
2924
+ if (!self.filestack[ind] || !isValidImage || (width <= maxWidth && height <= maxHeight)) {
2925
+ if (isValidImage && self.filestack[ind]) {
2926
+ self._raise('fileimageresized', [pid, ind]);
2927
+ }
2928
+ counter.val++;
2929
+ if (counter.val === numImgs) {
2930
+ self._raise('fileimagesresized');
2931
+ }
2932
+ if (!isValidImage) {
2933
+ throwError(self.msgImageResizeError, {id: pid, 'index': ind}, 'fileimageresizeerror');
2934
+ return;
2935
+ }
2936
+ }
2937
+ type = type || self.resizeDefaultImageType;
2938
+ chkWidth = width > maxWidth;
2939
+ chkHeight = height > maxHeight;
2940
+ if (self.resizePreference === 'width') {
2941
+ ratio = chkWidth ? maxWidth / width : (chkHeight ? maxHeight / height : 1);
2942
+ } else {
2943
+ ratio = chkHeight ? maxHeight / height : (chkWidth ? maxWidth / width : 1);
2944
+ }
2945
+ self._resetCanvas();
2946
+ width *= ratio;
2947
+ height *= ratio;
2948
+ canvas.width = width;
2949
+ canvas.height = height;
2950
+ try {
2951
+ context.drawImage(img, 0, 0, width, height);
2952
+ canvas.toBlob(function (blob) {
2953
+ self.filestack[ind] = blob;
2954
+ self._raise('fileimageresized', [pid, ind]);
2955
+ counter.val++;
2956
+ if (counter.val === numImgs) {
2957
+ self._raise('fileimagesresized', [undefined, undefined]);
2958
+ }
2959
+ if (!(blob instanceof Blob)) {
2960
+ throwError(self.msgImageResizeError, {id: pid, 'index': ind}, 'fileimageresizeerror');
2961
+ }
2962
+ }, type, self.resizeQuality);
2963
+ }
2964
+ catch (err) {
2965
+ counter.val++;
2966
+ if (counter.val === numImgs) {
2967
+ self._raise('fileimagesresized', [undefined, undefined]);
2968
+ }
2969
+ msg = self.msgImageResizeException.replace('{errors}', err.message);
2970
+ throwError(msg, {id: pid, 'index': ind}, 'fileimageresizeexception');
2971
+ }
2972
+ },
2973
+ _initBrowse: function ($container) {
2974
+ var self = this;
2975
+ if (self.showBrowse) {
2976
+ self.$btnFile = $container.find('.btn-file');
2977
+ self.$btnFile.append(self.$element);
2978
+ } else {
2979
+ self.$element.hide();
2980
+ }
2981
+ },
2982
+ _initCaption: function () {
2983
+ var self = this, cap = self.initialCaption || '';
2984
+ if (self.overwriteInitial || $h.isEmpty(cap)) {
2985
+ self.$caption.html('');
2986
+ return false;
2987
+ }
2988
+ self._setCaption(cap);
2989
+ return true;
2990
+ },
2991
+ _setCaption: function (content, isError) {
2992
+ var self = this, title, out, n, cap, stack = self.getFileStack();
2993
+ if (!self.$caption.length) {
2994
+ return;
2995
+ }
2996
+ if (isError) {
2997
+ title = $('<div>' + self.msgValidationError + '</div>').text();
2998
+ n = stack.length;
2999
+ if (n) {
3000
+ cap = n === 1 && stack[0] ? self._getFileNames()[0] : self._getMsgSelected(n);
3001
+ } else {
3002
+ cap = self._getMsgSelected(self.msgNo);
3003
+ }
3004
+ out = '<span class="' + self.msgValidationErrorClass + '">' + self.msgValidationErrorIcon +
3005
+ ($h.isEmpty(content) ? cap : content) + '</span>';
3006
+ } else {
3007
+ if ($h.isEmpty(content)) {
3008
+ return;
3009
+ }
3010
+ title = $('<div>' + content + '</div>').text();
3011
+ out = self._getLayoutTemplate('fileIcon') + title;
3012
+ }
3013
+ self.$caption.html(out);
3014
+ self.$caption.attr('title', title);
3015
+ self.$captionContainer.find('.file-caption-ellipsis').attr('title', title);
3016
+ },
3017
+ _createContainer: function () {
3018
+ var self = this, $container = $(document.createElement("div"))
3019
+ .attr({"class": 'file-input file-input-new'})
3020
+ .html(self._renderMain());
3021
+ self.$element.before($container);
3022
+ self._initBrowse($container);
3023
+ if (self.theme) {
3024
+ $container.addClass('theme-' + self.theme);
3025
+ }
3026
+ return $container;
3027
+ },
3028
+ _refreshContainer: function () {
3029
+ var self = this, $container = self.$container;
3030
+ $container.before(self.$element);
3031
+ $container.html(self._renderMain());
3032
+ self._initBrowse($container);
3033
+ },
3034
+ _renderMain: function () {
3035
+ var self = this,
3036
+ dropCss = (self.isUploadable && self.dropZoneEnabled) ? ' file-drop-zone clearfix' : 'file-drop-disabled clearfix',
3037
+ close = !self.showClose ? '' : self._getLayoutTemplate('close'),
3038
+ preview = !self.showPreview ? '' : self._getLayoutTemplate('preview')
3039
+ .setTokens({'class': self.previewClass, 'dropClass': dropCss}),
3040
+ css = self.isDisabled ? self.captionClass + ' file-caption-disabled' : self.captionClass,
3041
+ caption = self.captionTemplate.setTokens({'class': css + ' kv-fileinput-caption'});
3042
+ return self.mainTemplate.setTokens({
3043
+ 'class': self.mainClass + (!self.showBrowse && self.showCaption ? ' no-browse' : ''),
3044
+ 'preview': preview,
3045
+ 'close': close,
3046
+ 'caption': caption,
3047
+ 'upload': self._renderButton('upload'),
3048
+ 'remove': self._renderButton('remove'),
3049
+ 'cancel': self._renderButton('cancel'),
3050
+ 'browse': self._renderButton('browse')
3051
+ });
3052
+
3053
+ },
3054
+ _renderButton: function (type) {
3055
+ var self = this, tmplt = self._getLayoutTemplate('btnDefault'), css = self[type + 'Class'],
3056
+ title = self[type + 'Title'], icon = self[type + 'Icon'], label = self[type + 'Label'],
3057
+ status = self.isDisabled ? ' disabled' : '', btnType = 'button';
3058
+ switch (type) {
3059
+ case 'remove':
3060
+ if (!self.showRemove) {
3061
+ return '';
3062
+ }
3063
+ break;
3064
+ case 'cancel':
3065
+ if (!self.showCancel) {
3066
+ return '';
3067
+ }
3068
+ css += ' hide';
3069
+ break;
3070
+ case 'upload':
3071
+ if (!self.showUpload) {
3072
+ return '';
3073
+ }
3074
+ if (self.isUploadable && !self.isDisabled) {
3075
+ tmplt = self._getLayoutTemplate('btnLink').replace('{href}', self.uploadUrl);
3076
+ } else {
3077
+ btnType = 'submit';
3078
+ }
3079
+ break;
3080
+ case 'browse':
3081
+ if (!self.showBrowse) {
3082
+ return '';
3083
+ }
3084
+ tmplt = self._getLayoutTemplate('btnBrowse');
3085
+ break;
3086
+ default:
3087
+ return '';
3088
+ }
3089
+
3090
+ css += type === 'browse' ? ' btn-file' : ' fileinput-' + type + ' fileinput-' + type + '-button';
3091
+ if (!$h.isEmpty(label)) {
3092
+ label = ' <span class="' + self.buttonLabelClass + '">' + label + '</span>';
3093
+ }
3094
+ return tmplt.setTokens({
3095
+ 'type': btnType, 'css': css, 'title': title, 'status': status, 'icon': icon, 'label': label
3096
+ });
3097
+ },
3098
+ _renderThumbProgress: function () {
3099
+ var self = this;
3100
+ return '<div class="file-thumb-progress hide">' +
3101
+ self.progressTemplate.setTokens({'percent': '0', 'status': self.msgUploadBegin}) +
3102
+ '</div>';
3103
+ },
3104
+ _renderFileFooter: function (caption, size, width, isError) {
3105
+ var self = this, config = self.fileActionSettings, rem = config.showRemove, drg = config.showDrag,
3106
+ upl = config.showUpload, zoom = config.showZoom, out, template = self._getLayoutTemplate('footer'),
3107
+ ind = isError ? config.indicatorError : config.indicatorNew,
3108
+ tInd = self._getLayoutTemplate('indicator'),
3109
+ title = isError ? config.indicatorErrorTitle : config.indicatorNewTitle,
3110
+ indicator = tInd.setTokens({'indicator': ind, 'indicatorTitle': title});
3111
+ size = self._getSize(size);
3112
+ if (self.isUploadable) {
3113
+ out = template.setTokens({
3114
+ 'actions': self._renderFileActions(upl, rem, zoom, drg, false, false, false),
3115
+ 'caption': caption,
3116
+ 'size': size,
3117
+ 'width': width,
3118
+ 'progress': self._renderThumbProgress(),
3119
+ 'indicator': indicator
3120
+ });
3121
+ } else {
3122
+ out = template.setTokens({
3123
+ 'actions': self._renderFileActions(false, false, zoom, drg, false, false, false),
3124
+ 'caption': caption,
3125
+ 'size': size,
3126
+ 'width': width,
3127
+ 'progress': '',
3128
+ 'indicator': indicator
3129
+ });
3130
+ }
3131
+ out = $h.replaceTags(out, self.previewThumbTags);
3132
+ return out;
3133
+ },
3134
+ _renderFileActions: function (showUpload, showDelete, showZoom, showDrag, disabled, url, key, isInit) {
3135
+ if (!showUpload && !showDelete && !showZoom && !showDrag) {
3136
+ return '';
3137
+ }
3138
+ var self = this, vUrl = url === false ? '' : ' data-url="' + url + '"',
3139
+ vKey = key === false ? '' : ' data-key="' + key + '"',
3140
+ btnDelete = '', btnUpload = '', btnZoom = '', btnDrag = '', css,
3141
+ template = self._getLayoutTemplate('actions'), config = self.fileActionSettings,
3142
+ otherButtons = self.otherActionButtons.setTokens({'dataKey': vKey}),
3143
+ removeClass = disabled ? config.removeClass + ' disabled' : config.removeClass;
3144
+ if (showDelete) {
3145
+ btnDelete = self._getLayoutTemplate('actionDelete').setTokens({
3146
+ 'removeClass': removeClass,
3147
+ 'removeIcon': config.removeIcon,
3148
+ 'removeTitle': config.removeTitle,
3149
+ 'dataUrl': vUrl,
3150
+ 'dataKey': vKey
3151
+ });
3152
+ }
3153
+ if (showUpload) {
3154
+ btnUpload = self._getLayoutTemplate('actionUpload').setTokens({
3155
+ 'uploadClass': config.uploadClass,
3156
+ 'uploadIcon': config.uploadIcon,
3157
+ 'uploadTitle': config.uploadTitle
3158
+ });
3159
+ }
3160
+ if (showZoom) {
3161
+ btnZoom = self._getLayoutTemplate('actionZoom').setTokens({
3162
+ 'zoomClass': config.zoomClass,
3163
+ 'zoomIcon': config.zoomIcon,
3164
+ 'zoomTitle': config.zoomTitle
3165
+ });
3166
+ }
3167
+ if (showDrag && isInit) {
3168
+ css = 'drag-handle-init ' + config.dragClass;
3169
+ btnDrag = self._getLayoutTemplate('actionDrag').setTokens({
3170
+ 'dragClass': css,
3171
+ 'dragTitle': config.dragTitle,
3172
+ 'dragIcon': config.dragIcon
3173
+ });
3174
+ }
3175
+ return template.setTokens({
3176
+ 'delete': btnDelete,
3177
+ 'upload': btnUpload,
3178
+ 'zoom': btnZoom,
3179
+ 'drag': btnDrag,
3180
+ 'other': otherButtons
3181
+ });
3182
+ },
3183
+ _browse: function (e) {
3184
+ var self = this;
3185
+ self._raise('filebrowse');
3186
+ if (e && e.isDefaultPrevented()) {
3187
+ return;
3188
+ }
3189
+ if (self.isError && !self.isUploadable) {
3190
+ self.clear();
3191
+ }
3192
+ self.$captionContainer.focus();
3193
+ },
3194
+ _filterDuplicate: function (file, files, fileIds) {
3195
+ var self = this, fileId = self._getFileId(file);
3196
+ if (fileId && fileIds && fileIds.indexOf(fileId) > -1) {
3197
+ return;
3198
+ }
3199
+ if (!fileIds) {
3200
+ fileIds = [];
3201
+ }
3202
+ files.push(file);
3203
+ fileIds.push(fileId);
3204
+ },
3205
+ _change: function (e) {
3206
+ var self = this, $el = self.$element;
3207
+ if (!self.isUploadable && $h.isEmpty($el.val()) && self.fileInputCleared) { // IE 11 fix
3208
+ self.fileInputCleared = false;
3209
+ return;
3210
+ }
3211
+ self.fileInputCleared = false;
3212
+ var tfiles = [], msg, total, isDragDrop = arguments.length > 1, isAjaxUpload = self.isUploadable, n, len,
3213
+ files = isDragDrop ? e.originalEvent.dataTransfer.files : $el.get(0).files, ctr = self.filestack.length,
3214
+ isSingleUpload = $h.isEmpty($el.attr('multiple')), flagSingle = (isSingleUpload && ctr > 0),
3215
+ folders = 0, fileIds = self._getFileIds(), throwError = function (mesg, file, previewId, index) {
3216
+ var p1 = $.extend(true, {}, self._getOutData({}, {}, files), {id: previewId, index: index}),
3217
+ p2 = {id: previewId, index: index, file: file, files: files};
3218
+ return self.isUploadable ? self._showUploadError(mesg, p1) : self._showError(mesg, p2);
3219
+ };
3220
+ self.reader = null;
3221
+ self._resetUpload();
3222
+ self._hideFileIcon();
3223
+ if (self.isUploadable) {
3224
+ self.$container.find('.file-drop-zone .' + self.dropZoneTitleClass).remove();
3225
+ }
3226
+ if (isDragDrop) {
3227
+ $.each(files, function (i, f) {
3228
+ if (f && !f.type && f.size !== undefined && f.size % 4096 === 0) {
3229
+ folders++;
3230
+ } else {
3231
+ self._filterDuplicate(f, tfiles, fileIds);
3232
+ }
3233
+ });
3234
+ } else {
3235
+ if (e.target && e.target.files === undefined) {
3236
+ files = e.target.value ? [{name: e.target.value.replace(/^.+\\/, '')}] : [];
3237
+ } else {
3238
+ files = e.target.files || {};
3239
+ }
3240
+ if (isAjaxUpload) {
3241
+ $.each(files, function (i, f) {
3242
+ self._filterDuplicate(f, tfiles, fileIds);
3243
+ });
3244
+ } else {
3245
+ tfiles = files;
3246
+ }
3247
+ }
3248
+ if ($h.isEmpty(tfiles) || tfiles.length === 0) {
3249
+ if (!isAjaxUpload) {
3250
+ self.clear();
3251
+ }
3252
+ self._showFolderError(folders);
3253
+ self._raise('fileselectnone');
3254
+ return;
3255
+ }
3256
+ self._resetErrors();
3257
+ len = tfiles.length;
3258
+ total = self._getFileCount(self.isUploadable ? (self.getFileStack().length + len) : len);
3259
+ if (self.maxFileCount > 0 && total > self.maxFileCount) {
3260
+ if (!self.autoReplace || len > self.maxFileCount) {
3261
+ n = (self.autoReplace && len > self.maxFileCount) ? len : total;
3262
+ msg = self.msgFilesTooMany.replace('{m}', self.maxFileCount).replace('{n}', n);
3263
+ self.isError = throwError(msg, null, null, null);
3264
+ self.$captionContainer.find('.kv-caption-icon').hide();
3265
+ self._setCaption('', true);
3266
+ self.$container.removeClass('file-input-new file-input-ajax-new');
3267
+ return;
3268
+ }
3269
+ if (total > self.maxFileCount) {
3270
+ self._resetPreviewThumbs(isAjaxUpload);
3271
+ }
3272
+ } else {
3273
+ if (!isAjaxUpload || flagSingle) {
3274
+ self._resetPreviewThumbs(false);
3275
+ if (flagSingle) {
3276
+ self.clearStack();
3277
+ }
3278
+ } else {
3279
+ if (isAjaxUpload && ctr === 0 && (!self.previewCache.count() || self.overwriteInitial)) {
3280
+ self._resetPreviewThumbs(true);
3281
+ }
3282
+ }
3283
+ }
3284
+ if (self.isPreviewable) {
3285
+ self._readFiles(tfiles);
3286
+ } else {
3287
+ self._updateFileDetails(1);
3288
+ }
3289
+ self._showFolderError(folders);
3290
+ },
3291
+ _abort: function (params) {
3292
+ var self = this, data;
3293
+ if (self.ajaxAborted && typeof self.ajaxAborted === "object" && self.ajaxAborted.message !== undefined) {
3294
+ data = $.extend(true, {}, self._getOutData(), params);
3295
+ data.abortData = self.ajaxAborted.data || {};
3296
+ data.abortMessage = self.ajaxAborted.message;
3297
+ self._setProgress(101, self.$progress, self.msgCancelled);
3298
+ self._showUploadError(self.ajaxAborted.message, data, 'filecustomerror');
3299
+ self.cancel();
3300
+ return true;
3301
+ }
3302
+ return false;
3303
+ },
3304
+ _resetFileStack: function () {
3305
+ var self = this, i = 0, newstack = [], newnames = [], newids = [];
3306
+ self._getThumbs().each(function () {
3307
+ var $thumb = $(this), ind = $thumb.attr('data-fileindex'), file = self.filestack[ind],
3308
+ pid = $thumb.attr('id'), newId;
3309
+ if (ind === '-1' || ind === -1) {
3310
+ return;
3311
+ }
3312
+ if (file !== undefined) {
3313
+ newstack[i] = file;
3314
+ newnames[i] = self._getFileName(file);
3315
+ newids[i] = self._getFileId(file);
3316
+ $thumb.attr({'id': self.previewInitId + '-' + i, 'data-fileindex': i});
3317
+ i++;
3318
+ } else {
3319
+ newId = 'uploaded-' + $h.uniqId();
3320
+ $thumb.attr({'id': newId, 'data-fileindex': '-1'});
3321
+ self.$preview.find('#zoom-' + pid).attr('id', 'zoom-' + newId);
3322
+ }
3323
+ });
3324
+ self.filestack = newstack;
3325
+ self.filenames = newnames;
3326
+ self.fileids = newids;
3327
+ },
3328
+ clearStack: function () {
3329
+ var self = this;
3330
+ self.filestack = [];
3331
+ self.filenames = [];
3332
+ self.fileids = [];
3333
+ return self.$element;
3334
+ },
3335
+ updateStack: function (i, file) {
3336
+ var self = this;
3337
+ self.filestack[i] = file;
3338
+ self.filenames[i] = self._getFileName(file);
3339
+ self.fileids[i] = file && self._getFileId(file) || null;
3340
+ return self.$element;
3341
+ },
3342
+ addToStack: function (file) {
3343
+ var self = this;
3344
+ self.filestack.push(file);
3345
+ self.filenames.push(self._getFileName(file));
3346
+ self.fileids.push(self._getFileId(file));
3347
+ return self.$element;
3348
+ },
3349
+ getFileStack: function (skipNull) {
3350
+ var self = this;
3351
+ return self.filestack.filter(function (n) {
3352
+ return (skipNull ? n !== undefined : n !== undefined && n !== null);
3353
+ });
3354
+ },
3355
+ getFilesCount: function () {
3356
+ var self = this, len = self.isUploadable ? self.getFileStack().length : self.$element.get(0).files.length;
3357
+ return self._getFileCount(len);
3358
+ },
3359
+ lock: function () {
3360
+ var self = this;
3361
+ self._resetErrors();
3362
+ self.disable();
3363
+ if (self.showRemove) {
3364
+ $h.addCss(self.$container.find('.fileinput-remove'), 'hide');
3365
+ }
3366
+ if (self.showCancel) {
3367
+ self.$container.find('.fileinput-cancel').removeClass('hide');
3368
+ }
3369
+ self._raise('filelock', [self.filestack, self._getExtraData()]);
3370
+ return self.$element;
3371
+ },
3372
+ unlock: function (reset) {
3373
+ var self = this;
3374
+ if (reset === undefined) {
3375
+ reset = true;
3376
+ }
3377
+ self.enable();
3378
+ if (self.showCancel) {
3379
+ $h.addCss(self.$container.find('.fileinput-cancel'), 'hide');
3380
+ }
3381
+ if (self.showRemove) {
3382
+ self.$container.find('.fileinput-remove').removeClass('hide');
3383
+ }
3384
+ if (reset) {
3385
+ self._resetFileStack();
3386
+ }
3387
+ self._raise('fileunlock', [self.filestack, self._getExtraData()]);
3388
+ return self.$element;
3389
+ },
3390
+ cancel: function () {
3391
+ var self = this, xhr = self.ajaxRequests, len = xhr.length, i;
3392
+ if (len > 0) {
3393
+ for (i = 0; i < len; i += 1) {
3394
+ self.cancelling = true;
3395
+ xhr[i].abort();
3396
+ }
3397
+ }
3398
+ self._setProgressCancelled();
3399
+ self._getThumbs().each(function () {
3400
+ var $thumb = $(this), ind = $thumb.attr('data-fileindex');
3401
+ $thumb.removeClass('file-uploading');
3402
+ if (self.filestack[ind] !== undefined) {
3403
+ $thumb.find('.kv-file-upload').removeClass('disabled').removeAttr('disabled');
3404
+ $thumb.find('.kv-file-remove').removeClass('disabled').removeAttr('disabled');
3405
+ }
3406
+ self.unlock();
3407
+ });
3408
+ return self.$element;
3409
+ },
3410
+ clear: function () {
3411
+ var self = this, cap;
3412
+ if (!self._raise('fileclear')) {
3413
+ return;
3414
+ }
3415
+ self.$btnUpload.removeAttr('disabled');
3416
+ self._getThumbs().find('video,audio,img').each(function () {
3417
+ $h.cleanMemory($(this));
3418
+ });
3419
+ self._resetUpload();
3420
+ self.clearStack();
3421
+ self._clearFileInput();
3422
+ self._resetErrors(true);
3423
+ if (self._hasInitialPreview()) {
3424
+ self._showFileIcon();
3425
+ self._resetPreview();
3426
+ self._initPreviewActions();
3427
+ self.$container.removeClass('file-input-new');
3428
+ } else {
3429
+ self._getThumbs().each(function () {
3430
+ self._clearObjects($(this));
3431
+ });
3432
+ if (self.isUploadable) {
3433
+ self.previewCache.data = {};
3434
+ }
3435
+ self.$preview.html('');
3436
+ cap = (!self.overwriteInitial && self.initialCaption.length > 0) ? self.initialCaption : '';
3437
+ self.$caption.html(cap);
3438
+ self.$caption.attr('title', '');
3439
+ $h.addCss(self.$container, 'file-input-new');
3440
+ self._validateDefaultPreview();
3441
+ }
3442
+ if (self.$container.find($h.FRAMES).length === 0) {
3443
+ if (!self._initCaption()) {
3444
+ self.$captionContainer.find('.kv-caption-icon').hide();
3445
+ }
3446
+ }
3447
+ self._hideFileIcon();
3448
+ self._raise('filecleared');
3449
+ self.$captionContainer.focus();
3450
+ self._setFileDropZoneTitle();
3451
+ return self.$element;
3452
+ },
3453
+ reset: function () {
3454
+ var self = this;
3455
+ if (!self._raise('filereset')) {
3456
+ return;
3457
+ }
3458
+ self._resetPreview();
3459
+ self.$container.find('.fileinput-filename').text('');
3460
+ $h.addCss(self.$container, 'file-input-new');
3461
+ if (self.$preview.find($h.FRAMES).length || self.isUploadable && self.dropZoneEnabled) {
3462
+ self.$container.removeClass('file-input-new');
3463
+ }
3464
+ self._setFileDropZoneTitle();
3465
+ self.clearStack();
3466
+ self.formdata = {};
3467
+ return self.$element;
3468
+ },
3469
+ disable: function () {
3470
+ var self = this;
3471
+ self.isDisabled = true;
3472
+ self._raise('filedisabled');
3473
+ self.$element.attr('disabled', 'disabled');
3474
+ self.$container.find(".kv-fileinput-caption").addClass("file-caption-disabled");
3475
+ self.$container.find(".btn-file, .fileinput-remove, .fileinput-upload, .file-preview-frame button").attr(
3476
+ "disabled",
3477
+ true);
3478
+ self._initDragDrop();
3479
+ return self.$element;
3480
+ },
3481
+ enable: function () {
3482
+ var self = this;
3483
+ self.isDisabled = false;
3484
+ self._raise('fileenabled');
3485
+ self.$element.removeAttr('disabled');
3486
+ self.$container.find(".kv-fileinput-caption").removeClass("file-caption-disabled");
3487
+ self.$container.find(
3488
+ ".btn-file, .fileinput-remove, .fileinput-upload, .file-preview-frame button").removeAttr("disabled");
3489
+ self._initDragDrop();
3490
+ return self.$element;
3491
+ },
3492
+ upload: function () {
3493
+ var self = this, totLen = self.getFileStack().length, params = {}, i, outData, len,
3494
+ hasExtraData = !$.isEmptyObject(self._getExtraData());
3495
+ if (!self.isUploadable || self.isDisabled) {
3496
+ return;
3497
+ }
3498
+ if (self.minFileCount > 0 && self._getFileCount(totLen) < self.minFileCount) {
3499
+ self._noFilesError(params);
3500
+ return;
3501
+ }
3502
+ self._resetUpload();
3503
+ if (totLen === 0 && !hasExtraData) {
3504
+ self._showUploadError(self.msgUploadEmpty);
3505
+ return;
3506
+ }
3507
+ self.$progress.removeClass('hide');
3508
+ self.uploadCount = 0;
3509
+ self.uploadStatus = {};
3510
+ self.uploadLog = [];
3511
+ self.lock();
3512
+ self._setProgress(2);
3513
+ if (totLen === 0 && hasExtraData) {
3514
+ self._uploadExtraOnly();
3515
+ return;
3516
+ }
3517
+ len = self.filestack.length;
3518
+ self.hasInitData = false;
3519
+ if (self.uploadAsync) {
3520
+ outData = self._getOutData();
3521
+ self._raise('filebatchpreupload', [outData]);
3522
+ self.fileBatchCompleted = false;
3523
+ self.uploadCache = {content: [], config: [], tags: [], append: true};
3524
+ self.uploadAsyncCount = self.getFileStack().length;
3525
+ for (i = 0; i < len; i++) {
3526
+ self.uploadCache.content[i] = null;
3527
+ self.uploadCache.config[i] = null;
3528
+ self.uploadCache.tags[i] = null;
3529
+ }
3530
+ self.$preview.find('.file-preview-initial').removeClass($h.SORT_CSS);
3531
+ self._initSortable();
3532
+ self.cacheInitialPreview = self.getPreview();
3533
+
3534
+ for (i = 0; i < len; i++) {
3535
+ if (self.filestack[i] !== undefined) {
3536
+ self._uploadSingle(i, self.filestack, true);
3537
+ }
3538
+ }
3539
+ return;
3540
+ }
3541
+ self._uploadBatch();
3542
+ return self.$element;
3543
+ },
3544
+ destroy: function () {
3545
+ var self = this, $form = self.$form, $cont = self.$container, $el = self.$element, ns = self.namespace;
3546
+ $(document).off(ns);
3547
+ $(window).off(ns);
3548
+ if ($form && $form.length) {
3549
+ $form.off(ns);
3550
+ }
3551
+ if (self.isUploadable) {
3552
+ self._clearFileInput();
3553
+ }
3554
+ self._cleanup();
3555
+ self._initPreviewCache();
3556
+ $el.insertBefore($cont).off(ns).removeData();
3557
+ $cont.off().remove();
3558
+ return $el;
3559
+ },
3560
+ refresh: function (options) {
3561
+ var self = this, $el = self.$element;
3562
+ options = options ? $.extend(true, {}, self.options, options) : self.options;
3563
+ self.destroy();
3564
+ $el.fileinput(options);
3565
+ self = $el.data('fileinput');
3566
+ if (self.isUploadable) {
3567
+ self._clearFileInput();
3568
+ }
3569
+ if ($el.val()) {
3570
+ $el.trigger('change.fileinput');
3571
+ }
3572
+ return $el;
3573
+ },
3574
+ zoom: function (frameId) {
3575
+ var self = this, $frame = $('#' + frameId), $modal = self.$modal;
3576
+ if (!$frame.length) {
3577
+ self._log('Cannot zoom to detailed preview! Invalid frame with id: "' + frameId + '".');
3578
+ return;
3579
+ }
3580
+ $h.initModal($modal);
3581
+ $modal.html(self._getModalContent());
3582
+ self._setZoomContent($frame);
3583
+ $modal.modal('show');
3584
+ self._initZoomButtons();
3585
+ },
3586
+ getPreview: function () {
3587
+ var self = this;
3588
+ return {
3589
+ content: self.initialPreview,
3590
+ config: self.initialPreviewConfig,
3591
+ tags: self.initialPreviewThumbTags
3592
+ };
3593
+ }
3594
+ };
3595
+
3596
+ $.fn.fileinput = function (option) {
3597
+ if (!$h.hasFileAPISupport() && !$h.isIE(9)) {
3598
+ return;
3599
+ }
3600
+ var args = Array.apply(null, arguments), retvals = [];
3601
+ args.shift();
3602
+ this.each(function () {
3603
+ var self = $(this), data = self.data('fileinput'), options = typeof option === 'object' && option,
3604
+ theme = options.theme || self.data('theme'), l = {}, t = {},
3605
+ lang = options.language || self.data('language') || $.fn.fileinput.defaults.language || 'en', opt;
3606
+ if (!data) {
3607
+ if (theme) {
3608
+ t = $.fn.fileinputThemes[theme] || {};
3609
+ }
3610
+ if (lang !== 'en' && !$h.isEmpty($.fn.fileinputLocales[lang])) {
3611
+ l = $.fn.fileinputLocales[lang] || {};
3612
+ }
3613
+ opt = $.extend(true, {}, $.fn.fileinput.defaults, t, $.fn.fileinputLocales.en, l, options, self.data());
3614
+ data = new FileInput(this, opt);
3615
+ self.data('fileinput', data);
3616
+ }
3617
+
3618
+ if (typeof option === 'string') {
3619
+ retvals.push(data[option].apply(data, args));
3620
+ }
3621
+ });
3622
+ switch (retvals.length) {
3623
+ case 0:
3624
+ return this;
3625
+ case 1:
3626
+ return retvals[0];
3627
+ default:
3628
+ return retvals;
3629
+ }
3630
+ };
3631
+
3632
+ $.fn.fileinput.defaults = {
3633
+ language: 'en',
3634
+ showCaption: true,
3635
+ showBrowse: true,
3636
+ showPreview: true,
3637
+ showRemove: true,
3638
+ showUpload: true,
3639
+ showCancel: true,
3640
+ showClose: true,
3641
+ showUploadedThumbs: true,
3642
+ browseOnZoneClick: false,
3643
+ autoReplace: false,
3644
+ autoOrientImage: true, // for JPEG images based on EXIF orientation tag
3645
+ generateFileId: null,
3646
+ previewClass: '',
3647
+ captionClass: '',
3648
+ frameClass: 'krajee-default',
3649
+ mainClass: 'file-caption-main',
3650
+ mainTemplate: null,
3651
+ purifyHtml: true,
3652
+ fileSizeGetter: null,
3653
+ initialCaption: '',
3654
+ initialPreview: [],
3655
+ initialPreviewDelimiter: '*$$*',
3656
+ initialPreviewAsData: false,
3657
+ initialPreviewFileType: 'image',
3658
+ initialPreviewConfig: [],
3659
+ initialPreviewThumbTags: [],
3660
+ previewThumbTags: {},
3661
+ initialPreviewShowDelete: true,
3662
+ removeFromPreviewOnError: false,
3663
+ deleteUrl: '',
3664
+ deleteExtraData: {},
3665
+ overwriteInitial: true,
3666
+ previewZoomButtonIcons: {
3667
+ prev: '<i class="glyphicon glyphicon-triangle-left"></i>',
3668
+ next: '<i class="glyphicon glyphicon-triangle-right"></i>',
3669
+ toggleheader: '<i class="glyphicon glyphicon-resize-vertical"></i>',
3670
+ fullscreen: '<i class="glyphicon glyphicon-fullscreen"></i>',
3671
+ borderless: '<i class="glyphicon glyphicon-resize-full"></i>',
3672
+ close: '<i class="glyphicon glyphicon-remove"></i>'
3673
+ },
3674
+ previewZoomButtonClasses: {
3675
+ prev: 'btn btn-navigate',
3676
+ next: 'btn btn-navigate',
3677
+ toggleheader: 'btn btn-default btn-header-toggle',
3678
+ fullscreen: 'btn btn-default',
3679
+ borderless: 'btn btn-default',
3680
+ close: 'btn btn-default'
3681
+ },
3682
+ preferIconicPreview: false,
3683
+ preferIconicZoomPreview: false,
3684
+ allowedPreviewTypes: undefined,
3685
+ allowedPreviewMimeTypes: null,
3686
+ allowedFileTypes: null,
3687
+ allowedFileExtensions: null,
3688
+ defaultPreviewContent: null,
3689
+ customLayoutTags: {},
3690
+ customPreviewTags: {},
3691
+ previewFileIcon: '<i class="glyphicon glyphicon-file"></i>',
3692
+ previewFileIconClass: 'file-other-icon',
3693
+ previewFileIconSettings: {},
3694
+ previewFileExtSettings: {},
3695
+ buttonLabelClass: 'hidden-xs',
3696
+ browseIcon: '<i class="glyphicon glyphicon-folder-open"></i>&nbsp;',
3697
+ browseClass: 'btn btn-primary',
3698
+ removeIcon: '<i class="glyphicon glyphicon-trash"></i>',
3699
+ removeClass: 'btn btn-default',
3700
+ cancelIcon: '<i class="glyphicon glyphicon-ban-circle"></i>',
3701
+ cancelClass: 'btn btn-default',
3702
+ uploadIcon: '<i class="glyphicon glyphicon-upload"></i>',
3703
+ uploadClass: 'btn btn-default',
3704
+ uploadUrl: null,
3705
+ uploadAsync: true,
3706
+ uploadExtraData: {},
3707
+ zoomModalHeight: 480,
3708
+ minImageWidth: null,
3709
+ minImageHeight: null,
3710
+ maxImageWidth: null,
3711
+ maxImageHeight: null,
3712
+ resizeImage: false,
3713
+ resizePreference: 'width',
3714
+ resizeQuality: 0.92,
3715
+ resizeDefaultImageType: 'image/jpeg',
3716
+ resizeIfSizeMoreThan: 0, // in KB
3717
+ minFileSize: 0,
3718
+ maxFileSize: 0,
3719
+ maxFilePreviewSize: 25600, // 25 MB
3720
+ minFileCount: 0,
3721
+ maxFileCount: 0,
3722
+ validateInitialCount: false,
3723
+ msgValidationErrorClass: 'text-danger',
3724
+ msgValidationErrorIcon: '<i class="glyphicon glyphicon-exclamation-sign"></i> ',
3725
+ msgErrorClass: 'file-error-message',
3726
+ progressThumbClass: "progress-bar progress-bar-success progress-bar-striped active",
3727
+ progressClass: "progress-bar progress-bar-success progress-bar-striped active",
3728
+ progressCompleteClass: "progress-bar progress-bar-success",
3729
+ progressErrorClass: "progress-bar progress-bar-danger",
3730
+ progressUploadThreshold: 99,
3731
+ previewFileType: 'image',
3732
+ elCaptionContainer: null,
3733
+ elCaptionText: null,
3734
+ elPreviewContainer: null,
3735
+ elPreviewImage: null,
3736
+ elPreviewStatus: null,
3737
+ elErrorContainer: null,
3738
+ errorCloseButton: '<span class="close kv-error-close">&times;</span>',
3739
+ slugCallback: null,
3740
+ dropZoneEnabled: true,
3741
+ dropZoneTitleClass: 'file-drop-zone-title',
3742
+ fileActionSettings: {},
3743
+ otherActionButtons: '',
3744
+ textEncoding: 'UTF-8',
3745
+ ajaxSettings: {},
3746
+ ajaxDeleteSettings: {},
3747
+ showAjaxErrorDetails: true
3748
+ };
3749
+
3750
+ $.fn.fileinputLocales.en = {
3751
+ fileSingle: 'file',
3752
+ filePlural: 'files',
3753
+ browseLabel: 'Прикрепить &hellip;',
3754
+ removeLabel: 'Убрать',
3755
+ removeTitle: 'Clear selected files',
3756
+ cancelLabel: 'Cancel',
3757
+ cancelTitle: 'Abort ongoing upload',
3758
+ uploadLabel: 'Upload',
3759
+ uploadTitle: 'Upload selected files',
3760
+ msgNo: 'No',
3761
+ msgNoFilesSelected: 'No files selected',
3762
+ msgCancelled: 'Cancelled',
3763
+ msgZoomModalHeading: 'Detailed Preview',
3764
+ msgSizeTooSmall: 'File "{name}" (<b>{size} KB</b>) is too small and must be larger than <b>{minSize} KB</b>.',
3765
+ msgSizeTooLarge: 'File "{name}" (<b>{size} KB</b>) exceeds maximum allowed upload size of <b>{maxSize} KB</b>.',
3766
+ msgFilesTooLess: 'You must select at least <b>{n}</b> {files} to upload.',
3767
+ msgFilesTooMany: 'Number of files selected for upload <b>({n})</b> exceeds maximum allowed limit of <b>{m}</b>.',
3768
+ msgFileNotFound: 'File "{name}" not found!',
3769
+ msgFileSecured: 'Security restrictions prevent reading the file "{name}".',
3770
+ msgFileNotReadable: 'File "{name}" is not readable.',
3771
+ msgFilePreviewAborted: 'File preview aborted for "{name}".',
3772
+ msgFilePreviewError: 'An error occurred while reading the file "{name}".',
3773
+ msgInvalidFileName: 'Invalid or unsupported characters in file name "{name}".',
3774
+ msgInvalidFileType: 'Invalid type for file "{name}". Only "{types}" files are supported.',
3775
+ msgInvalidFileExtension: 'Invalid extension for file "{name}". Only "{extensions}" files are supported.',
3776
+ msgFileTypes: {
3777
+ 'image': 'image',
3778
+ 'html': 'HTML',
3779
+ 'text': 'text',
3780
+ 'video': 'video',
3781
+ 'audio': 'audio',
3782
+ 'flash': 'flash',
3783
+ 'pdf': 'PDF',
3784
+ 'object': 'object'
3785
+ },
3786
+ msgUploadAborted: 'The file upload was aborted',
3787
+ msgUploadThreshold: 'Processing...',
3788
+ msgUploadBegin: 'Initializing...',
3789
+ msgUploadEnd: 'Done',
3790
+ msgUploadEmpty: 'No valid data available for upload.',
3791
+ msgValidationError: 'Validation Error',
3792
+ msgLoading: 'Loading file {index} of {files} &hellip;',
3793
+ msgProgress: 'Loading file {index} of {files} - {name} - {percent}% completed.',
3794
+ msgSelected: '{n} {files} selected',
3795
+ msgFoldersNotAllowed: 'Drag & drop files only! {n} folder(s) dropped were skipped.',
3796
+ msgImageWidthSmall: 'Width of image file "{name}" must be at least {size} px.',
3797
+ msgImageHeightSmall: 'Height of image file "{name}" must be at least {size} px.',
3798
+ msgImageWidthLarge: 'Width of image file "{name}" cannot exceed {size} px.',
3799
+ msgImageHeightLarge: 'Height of image file "{name}" cannot exceed {size} px.',
3800
+ msgImageResizeError: 'Could not get the image dimensions to resize.',
3801
+ msgImageResizeException: 'Error while resizing the image.<pre>{errors}</pre>',
3802
+ msgAjaxError: 'Something went wrong with the {operation} operation. Please try again later!',
3803
+ msgAjaxProgressError: '{operation} failed',
3804
+ ajaxOperations: {
3805
+ deleteThumb: 'file delete',
3806
+ uploadThumb: 'file upload',
3807
+ uploadBatch: 'batch file upload',
3808
+ uploadExtra: 'form data upload'
3809
+ },
3810
+ dropZoneTitle: 'Drag & drop files here &hellip;',
3811
+ dropZoneClickTitle: '<br>(or click to select {files})',
3812
+ previewZoomButtonTitles: {
3813
+ prev: 'View previous file',
3814
+ next: 'View next file',
3815
+ toggleheader: 'Toggle header',
3816
+ fullscreen: 'Toggle full screen',
3817
+ borderless: 'Toggle borderless mode',
3818
+ close: 'Close detailed preview'
3819
+ }
3820
+ };
3821
+
3822
+ $.fn.fileinput.Constructor = FileInput;
3823
+
3824
+ /**
3825
+ * Convert automatically file inputs with class 'file' into a bootstrap fileinput control.
3826
+ */
3827
+ $(document).ready(function () {
3828
+ var $input = $('input.file[type=file]');
3829
+ if ($input.length) {
3830
+ $input.fileinput();
3831
+ }
3832
+ });
3833
+ }));