Skip to content

Commit

Permalink
Fix #259 & Fix #263: Polish translations and enhance parsing file pre…
Browse files Browse the repository at this point in the history
…view thumbs
  • Loading branch information
kartik-v committed Apr 24, 2015
1 parent ddf3f91 commit 41d5757
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 38 deletions.
2 changes: 2 additions & 0 deletions CHANGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ version 4.1.9
14. (bug #253): Fix initial preview delete cache initialization.
15. (bug #257): Fix upload single to replace thumbs correctly.
16. (enh #258): Enhance messages to include file plural and single.
17. (enh #259): Add Polish translations.
18. (enh #263): Enhance parsing of file preview thumbnails and actions.

version 4.1.8
=============
Expand Down
67 changes: 35 additions & 32 deletions js/fileinput.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@
tags: obj.initialPreviewThumbTags,
delimiter: obj.initialPreviewDelimiter,
template: obj.previewGenericTemplate,
msg: function(n) {
msg: function (n) {
return obj.getMsgSelected(n);
},
initId: obj.previewInitId,
footer: obj.getLayoutTemplate('footer'),
isDelete: obj.initialPreviewShowDelete,
caption: obj.initialCaption,
actions: function (showUpload, showDelete, disabled, url, key, index) {
return obj.renderFileActions(showUpload, showDelete, disabled, url, key, index);
actions: function (showUpload, showDelete, disabled, url, key) {
return obj.renderFileActions(showUpload, showDelete, disabled, url, key);
}
};
},
Expand All @@ -59,8 +59,8 @@
});
},
count: function (id, all) {
return !!previewCache.data[id] && !!previewCache.data[id].content ?
(all ? previewCache.data[id].content.length : previewCache.fetch(id).length): 0;
return !!previewCache.data[id] && !!previewCache.data[id].content ?
(all ? previewCache.data[id].content.length : previewCache.fetch(id).length) : 0;
},
get: function (id, i, isDisabled) {
var ind = 'init_' + i, data = previewCache.data[id],
Expand Down Expand Up @@ -156,7 +156,7 @@
url = isSet('url', config) ? config.url : false,
key = isSet('key', config) ? config.key : null,
disabled = (url === false) && isDisabled,
actions = data.isDelete ? data.actions(false, true, disabled, url, key, i) : '',
actions = data.isDelete ? data.actions(false, true, disabled, url, key) : '',
footer = data.footer.repl('{actions}', actions);
return footer
.repl('{caption}', caption)
Expand All @@ -165,7 +165,6 @@
.repl('{indicatorTitle}', '');
}
},
PREVIEW_FRAMES = '.file-preview-frame:not(.file-preview-initial)',
getNum = function (num, def) {
def = def || 0;
if (typeof num === "number") {
Expand Down Expand Up @@ -730,7 +729,7 @@
},
resetFileStack: function () {
var self = this, i = 0, newstack = [];
self.$preview.find(PREVIEW_FRAMES).each(function () {
self.getThumbs().each(function () {
var $thumb = $(this), ind = $thumb.attr('data-fileindex'),
file = self.filestack[ind];
if (ind === -1) {
Expand Down Expand Up @@ -840,15 +839,15 @@
});
});
},
getMsgSelected: function(n) {
getMsgSelected: function (n) {
var self = this, strFiles = n === 1 ? self.fileSingle : self.filePlural;
return self.msgSelected.repl('{n}', n).repl('{files}', strFiles);
},
renderFileFooter: function (caption, width) {
var self = this, config = self.fileActionSettings, footer, out,
template = self.getLayoutTemplate('footer');
if (self.isUploadable) {
footer = template.repl('{actions}', self.renderFileActions(true, true, false, false, false, false));
footer = template.repl('{actions}', self.renderFileActions(true, true, false, false, false));
out = footer.repl('{caption}', caption)
.repl('{width}', width)
.repl('{indicator}', config.indicatorNew)
Expand All @@ -863,7 +862,7 @@
out = replaceTags(out, self.previewThumbTags);
return out;
},
renderFileActions: function (showUpload, showDelete, disabled, url, key, index) {
renderFileActions: function (showUpload, showDelete, disabled, url, key) {
if (!showUpload && !showDelete) {
return '';
}
Expand Down Expand Up @@ -920,14 +919,14 @@
self.initialCaption = '';
}
};

self.$preview.find('.kv-file-remove').each(function () {
var $el = $(this), vUrl = $el.data('url') || self.deleteUrl, vKey = $el.data('key');
if (isEmpty(vUrl) || vKey === undefined) {
return;
}
var $frame = $el.closest('.file-preview-frame'), cache = previewCache.data[self.id],
settings, params,index = $frame.data('fileindex'), config, extraData;
var $frame = $el.closest('.file-preview-frame'), cache = previewCache.data[self.id],
settings, params, index = $frame.data('fileindex'), config, extraData;
index = parseInt(index.replace('init_', ''));
config = isEmpty(cache.config) && isEmpty(cache.config[index]) ? null : cache.config[index];
extraData = isEmpty(config) || isEmpty(config.extra) ? deleteExtraData : config.extra;
Expand All @@ -948,14 +947,14 @@
} else {
addCss($frame, 'file-uploading');
addCss($el, 'disabled');
}
}
},
success: function (data, textStatus, jqXHR) {
var n, cap;
if (data === undefined || data.error === undefined) {
previewCache.unset(self.id, index);
n = previewCache.count(self.id),
cap = n > 0? self.getMsgSelected(n) : '';
n = previewCache.count(self.id);
cap = n > 0 ? self.getMsgSelected(n) : '';
self.raise('filedeleted', [vKey, jqXHR, extraData]);
self.setCaption(cap);
} else {
Expand Down Expand Up @@ -1046,7 +1045,7 @@
xhr[i].abort();
}
}
self.$preview.find(PREVIEW_FRAMES).each(function () {
self.getThumbs().each(function () {
var $thumb = $(this), ind = $thumb.attr('data-fileindex');
$thumb.removeClass('file-uploading');
if (self.filestack[ind] !== undefined) {
Expand All @@ -1071,7 +1070,7 @@
self.initPreviewDeletes();
self.$container.removeClass('file-input-new');
} else {
self.$preview.find(PREVIEW_FRAMES).each(function () {
self.getThumbs().each(function () {
self.clearObjects($(this));
});
self.$preview.html('');
Expand Down Expand Up @@ -1135,6 +1134,10 @@
self.$container.find(".btn-file, .fileinput-remove, .kv-fileinput-upload").removeAttr("disabled");
self.initDragDrop();
},
getThumbs: function (css) {
css = css || '';
return this.$preview.find('.file-preview-frame:not(.file-preview-initial)' + css);
},
getExtraData: function () {
var self = this, data = self.uploadExtraData;
if (typeof self.uploadExtraData === "function") {
Expand Down Expand Up @@ -1235,12 +1238,12 @@
return;
}
chkComplete = function () {
var $thumbs = self.$preview.find(PREVIEW_FRAMES + '.file-uploading');
var $thumbs = self.getThumbs('.file-uploading');
if ($thumbs.length > 0 || self.fileBatchCompleted) {
return;
}
self.fileBatchCompleted = true;
setTimeout(function() {
setTimeout(function () {
previewCache.set(self.id, self.uploadCache.content, self.uploadCache.config, self.uploadCache.tags,
self.uploadCache.append);
if (self.hasInitData) {
Expand Down Expand Up @@ -1353,7 +1356,7 @@
$btnDelete.removeAttr('disabled');
};
setAllUploaded = function () {
$.each(files, function (key, data) {
$.each(files, function (key) {
self.filestack[key] = undefined;
});
self.clearFileInput();
Expand All @@ -1362,7 +1365,7 @@
self.lock();
var outData = self.getOutData(jqXHR);
if (self.showPreview) {
self.$preview.find(PREVIEW_FRAMES).each(function () {
self.getThumbs().each(function () {
var $thumb = $(this), $btnUpload = $thumb.find('.kv-file-upload'), $btnDelete = $thumb.find('.kv-file-remove');
addCss($thumb, 'file-uploading');
$btnUpload.attr('disabled', true);
Expand All @@ -1375,15 +1378,15 @@
}
};
fnSuccess = function (data, textStatus, jqXHR) {
var outData = self.getOutData(jqXHR, data),
var outData = self.getOutData(jqXHR, data), $thumbs = self.getThumbs(),
keys = isEmpty(data.errorkeys) ? [] : data.errorkeys;
if (data.error === undefined || isEmpty(data.error)) {
self.raise('filebatchuploadsuccess', [outData]);
setAllUploaded();
if (self.showPreview) {
self.$preview.find('.kv-file-upload').hide();
self.$preview.find('.kv-file-remove').hide();
self.$preview.find(PREVIEW_FRAMES).each(function () {
$thumbs.find('.kv-file-upload').hide();
$thumbs.find('.kv-file-remove').hide();
$thumbs.each(function () {
var $thumb = $(this), key = $thumb.attr('data-fileindex');
setIndicator(key, 'indicatorSuccess', 'indicatorSuccessTitle');
enableActions(key);
Expand All @@ -1394,7 +1397,7 @@
}
} else {
if (self.showPreview) {
self.$preview.find(PREVIEW_FRAMES).each(function () {
$thumbs.each(function () {
var $thumb = $(this), key = parseInt($thumb.attr('data-fileindex'), 10);
enableActions(key);
if (keys.length === 0) {
Expand Down Expand Up @@ -1428,16 +1431,16 @@
if (!self.showPreview) {
return;
}
self.$preview.find(PREVIEW_FRAMES).each(function () {
self.getThumbs().each(function () {
var $thumb = $(this), key = $thumb.attr('data-fileindex');
$thumb.removeClass('file-uploading');
if (self.filestack[key] !== undefined) {
setIndicator(key, 'indicatorError', 'indicatorErrorTitle');
}
});
self.$preview.find(PREVIEW_FRAMES).removeClass('file-uploading');
self.$preview.find(PREVIEW_FRAMES + ' .kv-file-upload').removeAttr('disabled');
self.$preview.find(PREVIEW_FRAMES + ' .kv-file-delete').removeAttr('disabled');
self.getThumbs().removeClass('file-uploading');
self.getThumbs(' .kv-file-upload').removeAttr('disabled');
self.getThumbs(' .kv-file-delete').removeAttr('disabled');
};
$.each(files, function (key, data) {
if (!isEmpty(files[key])) {
Expand Down
5 changes: 2 additions & 3 deletions js/fileinput.min.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions js/fileinput_locale_pl.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
(function ($) {
"use strict";

$.fn.fileinput.locales._LANG_ = {
$.fn.fileinput.locales.pl = {
fileSingle: 'plik',
filePlural: 'pliki',
browseLabel: 'Przeglądaj …',
Expand All @@ -34,10 +34,10 @@
msgValidationError: 'Błąd podczas przesyłania pliku.',
msgLoading: 'Wczytywanie pliku {index} z {files} …',
msgProgress: 'Wczytywanie pliku {index} z {files} - {name} - {percent}% zakończone.',
msgSelected: '{n} wybranych plików',
msgSelected: '{n} {files} zaznaczonych',
msgFoldersNotAllowed: 'Metodą przeciągnij i upuść, można przenosić tylko pliki. Pominięto {n} katalogów.',
dropZoneTitle: 'Przeciągnij i upuść pliki tu …'
};

$.extend($.fn.fileinput.defaults, $.fn.fileinput.locales._LANG_);
$.extend($.fn.fileinput.defaults, $.fn.fileinput.locales.pl);
})(window.jQuery);

0 comments on commit 41d5757

Please sign in to comment.