Skip to content

Commit

Permalink
Fix #245: Allow initial caption to be set without initial preview
Browse files Browse the repository at this point in the history
  • Loading branch information
kartik-v committed Apr 12, 2015
1 parent 5f79261 commit b84ed2e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ version 4.1.9
4. (enh #241): Enhancements to initial preview delete to perform validations before delete.
5. (bug #243): Correct sending of `deleteExtraData`.
6. (enh #244): Add Serbian translations.
7. (enh #245): Allow initial caption to be set without initial preview.

version 4.1.8
=============
Expand Down
29 changes: 22 additions & 7 deletions js/fileinput.js
Original file line number Diff line number Diff line change
Expand Up @@ -885,10 +885,14 @@
.repl('{other}', otherButtons);
},
initPreview: function (isInit) {
var self = this, cap, out;
var self = this, cap = self.initialCaption || '', out;
if (!previewCache.count(self.id)) {
self.$preview.html('');
self.setCaption('');
if (isInit) {
self.setCaption(cap);
} else {
self.initCaption();
}
return;
}
out = previewCache.out(self.id);
Expand All @@ -904,6 +908,7 @@
resetProgress = function () {
if (self.$preview.find('.kv-file-remove').length === 0) {
self.reset();
self.initialCaption = '';
}
};
self.$preview.find('.kv-file-remove').each(function () {
Expand Down Expand Up @@ -1056,16 +1061,16 @@
});
self.$preview.html('');
cap = (!self.overwriteInitial && self.initialCaption.length > 0) ? self.initialCaption : '';
self.$caption.html(cap);
self.setCaption(cap);
self.setEllipsis();
self.$caption.attr('title', '');
addCss(self.$container, 'file-input-new');
}
if (self.$container.find('.file-preview-frame').length === 0) {
self.initialCaption = '';
self.$caption.html('');
if (!self.initCaption()) {
self.$captionContainer.find('.kv-caption-icon').hide();
}
self.setEllipsis();
self.$captionContainer.find('.kv-caption-icon').hide();
}
self.hideFileIcon();
self.raise('filecleared');
Expand All @@ -1080,7 +1085,7 @@
self.setCaption(out.caption);
} else {
self.$preview.html('');
self.$caption.html('');
self.initCaption();
}
},
reset: function () {
Expand Down Expand Up @@ -1888,6 +1893,16 @@
self.raise('fileimageloaded', previewId);
});
},
initCaption: function () {
var self = this, cap;
if (self.overwriteInitial) {
self.$caption.html('');
return false;
}
cap = self.initialCaption || '';
self.setCaption(cap);
return true;
},
setCaption: function (content, isError) {
var self = this, err = isError || false, title, out;
if (isEmpty(content) || self.$caption.length === 0) {
Expand Down
Loading

0 comments on commit b84ed2e

Please sign in to comment.