Skip to content

Commit 19f3b50

Browse files
committed
Upgrade to release v2.8.0
1 parent 744680b commit 19f3b50

10 files changed

+99
-24
lines changed

CHANGE.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
1+
version 2.8.0
2+
=============
3+
**Date:** 13-Nov-2014
4+
5+
1. (enh #50): Dynamically auto size file captions for long file names exceeding container width. New property `autoFitCaption`
6+
is added which defaults to `true`. When this is `true` the plugin will auto fit caption text within the container dynamically
7+
and responsively based on window size.
8+
2. (enh #51): Autosize preview images when they exceed the size of the preview container.
9+
3. (enh #52): Raise new `fileimageloaded` event.
10+
111
version 2.7.0
212
=============
313
**Date:** 11-Nov-2014
414

515
1. Set release to stable in composer.json.
6-
2. enh #48: Trigger `fileloaded` event when `showPreview` is `false`.
7-
3. enh #49: Set image preview dimensions to auto fit and center
16+
2. (enh #48): Trigger `fileloaded` event when `showPreview` is `false`.
17+
3. (enh #49): Set image preview dimensions to auto fit and center
818

919
version 2.6.0
1020
=============

README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ wide variety of files i.e. images, text, html, video, audio, flash, and objects.
77

88
![File Input Screenshot](https://lh3.googleusercontent.com/-3FiEmc_okc4/VBw_d2LBAJI/AAAAAAAAAL8/KbVj5X9Dus0/w596-h454-no/FileInput.jpg)
99

10-
> NOTE: The latest version of the plugin v2.7.0 has been released. Refer the [CHANGE LOG](https://github.com/kartik-v/bootstrap-fileinput/blob/master/CHANGE.md) for details.
10+
> NOTE: The latest version of the plugin v2.8.0 has been released. Refer the [CHANGE LOG](https://github.com/kartik-v/bootstrap-fileinput/blob/master/CHANGE.md) for details.
1111
1212
## Features
1313

@@ -45,6 +45,11 @@ backward compatibility (BC) for older versions that use custom templates.
4545

4646
The following are the major changes with release v2.4.0:
4747

48+
- Dynamically auto size the file captions for long file names exceeding container width. New property `autoFitCaption`
49+
is added which defaults to `true`. When this is `true` the plugin will auto fit caption text within the container dynamically
50+
and responsively based on window size.
51+
- Raise new `fileimageuploaded` event that fires after image is completely loaded on the preview container.
52+
- Autosize preview images when they exceed the size of the preview container.
4853
- Completely templatized and extensible to allow configuration of the file-input the way the developer wants.
4954
- Plugin has been revamped to build preview intelligence based on various file preview types. The inbuilt file support types are categorized as
5055
`image`, `text`, `html`, `video`, `audio`, `flash`, `object`, and `other`.
@@ -152,6 +157,9 @@ _boolean_ whether to display the file remove/clear button. Defaults to `true`.
152157
#### showUpload
153158
_boolean_ whether to display the file upload button. Defaults to `true`. This will default to a form submit button, unless the uploadUrl is specified.
154159

160+
#### autoFitCaption
161+
_boolean_ whether to automatically size the file caption text to fit the container for long file names overflowing the container. Defaults to `true`. When set to true, the caption text will be dynamically sized. Shrunk file names will be appended with ellipsis, and the complete filename will be displayed as a title on hover.
162+
155163
#### captionClass
156164
_string_ any additional CSS class to append to the caption container.
157165

@@ -702,6 +710,19 @@ $('#input-id').on('filereset', function(event) {
702710
});
703711
```
704712

713+
#### fileimageloaded
714+
This event is triggered when each file image is fully loaded in the preview window. This is only applicable for image file previews and if `showPreview` is set to true. Additional parameters available are:
715+
716+
- `previewId`: the identifier for the preview file container.
717+
718+
719+
**Example:**
720+
```js
721+
$('#input-id').on('filereset', function(event, file, previewId, index) {
722+
console.log("filereset");
723+
});
724+
```
725+
705726
### Plugin Methods
706727
The plugin supports these methods:
707728

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bootstrap-fileinput",
3-
"version": "2.7.0",
3+
"version": "2.8.0",
44
"homepage": "https://github.com/kartik-v/bootstrap-fileinput",
55
"authors": [
66
"Kartik Visweswaran <[email protected]>"

css/fileinput.css

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014
33
* @package bootstrap-fileinput
4-
* @version 2.7.0
4+
* @version 2.8.0
55
*
66
* File input styling for Bootstrap 3.0
77
* Built for Yii Framework 2.0
@@ -53,12 +53,11 @@
5353

5454
.file-caption-name {
5555
display: inline-block;
56-
float: left;
5756
overflow: hidden;
5857
white-space: nowrap;
5958
text-overflow: ellipsis;
60-
width: 85%;
6159
}
60+
6261
.file-error-message {
6362
background-color: #f2dede;
6463
color: #a94442;

css/fileinput.min.css

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ <h1>Bootstrap File Input Example</h1>
1818
<input id="file-1" type="file" multiple=true data-preview-file-type="any">
1919
</div>
2020
<div class="form-group">
21-
<input id="file-1a" type="file" multiple=true class="file" data-preview-file-type="any" data-initial-caption="Kartik" data-overwrite-initial="false">
21+
<input id="file-1a" type="file" multiple=true class="file" data-show-upload="false" data-preview-file-type="any" data-initial-caption="Kartik" data-overwrite-initial="false">
2222
</div>
2323
<div class="form-group">
2424
<input id="file-2" type="file" class="file" readonly=true data-show-upload="false">

examples/large-width-image.jpg

15.2 KB
Loading

js/fileinput.js

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*!
22
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014
3-
* @version 2.7.0
3+
* @version 2.8.0
44
*
55
* File input styled for Bootstrap 3.0 that utilizes HTML5 File Input's advanced
66
* features including the FileReader API.
@@ -45,8 +45,9 @@
4545
' <div class="file-preview-status text-center text-success"></div>\n' +
4646
' <div class="kv-fileinput-error"></div>\n' +
4747
'</div>',
48+
icon: '<span class="glyphicon glyphicon-file kv-caption-icon"></span>',
4849
caption: '<div tabindex="-1" class="form-control file-caption {class}">\n' +
49-
' <span class="glyphicon glyphicon-file kv-caption-icon"></span><div class="file-caption-name"></div>\n' +
50+
' <div class="file-caption-name"></div>\n' +
5051
'</div>',
5152
modal: '<div id="{id}" class="modal fade">\n' +
5253
' <div class="modal-dialog modal-lg">\n' +
@@ -108,7 +109,7 @@
108109
'</div>',
109110
};
110111
var defaultPreviewSettings = {
111-
image: {width: "100%", height: "160px"},
112+
image: {width: "auto", height: "160px"},
112113
html: {width: "320px", height: "180px"},
113114
text: {width: "160px", height: "160px"},
114115
video: {width: "320px", height: "240px"},
@@ -192,6 +193,7 @@
192193
self.reader = null;
193194
self.showCaption = options.showCaption;
194195
self.showPreview = options.showPreview;
196+
self.autoFitCaption = options.autoFitCaption;
195197
self.maxFileSize = options.maxFileSize;
196198
self.maxFileCount = options.maxFileCount;
197199
self.msgSizeTooLarge = options.msgSizeTooLarge;
@@ -270,6 +272,7 @@
270272
caption: self.$caption.html()
271273
};
272274
self.options = options;
275+
self.autoSizeCaption();
273276
self.$element.removeClass('file-loading');
274277
},
275278
getLayoutTemplate: function(t) {
@@ -283,6 +286,11 @@
283286
listen: function () {
284287
var self = this, $el = self.$element, $cap = self.$captionContainer, $btnFile = self.$btnFile;
285288
$el.on('change', $.proxy(self.change, self));
289+
$(window).on('resize', function() {
290+
setTimeout(function() {
291+
self.autoSizeCaption();
292+
}, 100);
293+
});
286294
$btnFile.on('click', function (ev) {
287295
self.clear(false);
288296
$cap.focus();
@@ -298,8 +306,7 @@
298306
initPreview: function () {
299307
var self = this, html = '', content = self.initialPreview, len = self.initialPreviewCount,
300308
cap = self.initialCaption.length, previewId = "preview-" + uniqId(),
301-
caption = (cap > 0) ? self.initialCaption : self.msgSelected.replace(/\{n\}/g, len),
302-
title = $(caption).text();
309+
caption = (cap > 0) ? self.initialCaption : self.msgSelected.replace(/\{n\}/g, len);
303310
if (isArray(content) && len > 0) {
304311
for (var i = 0; i < len; i++) {
305312
previewId += '-' + i;
@@ -322,8 +329,7 @@
322329
}
323330
} else {
324331
if (cap > 0) {
325-
self.$caption.html(caption);
326-
self.$captionContainer.attr('title', title);
332+
self.setCaption(caption);
327333
return;
328334
} else {
329335
return;
@@ -332,8 +338,7 @@
332338
}
333339
self.initialPreviewContent = html;
334340
self.$preview.html(html);
335-
self.$caption.html(caption);
336-
self.$captionContainer.attr('title', title);
341+
self.setCaption(caption);
337342
self.$container.removeClass('file-input-new');
338343
},
339344
clearObjects: function() {
@@ -378,6 +383,7 @@
378383
if (self.reader instanceof FileReader) {
379384
self.reader.abort();
380385
}
386+
self.autoSizeCaption();
381387
self.clearFileInput();
382388
self.resetErrors(true);
383389

@@ -399,7 +405,7 @@
399405
var cap = (!self.overwriteInitial && self.initialCaption.length > 0) ?
400406
self.original.caption : '';
401407
self.$caption.html(cap);
402-
self.$captionContainer.attr('title', '');
408+
self.$caption.attr('title', '');
403409
self.$container.removeClass('file-input-new').addClass('file-input-new');
404410
}
405411
self.hideFileIcon();
@@ -532,6 +538,7 @@
532538
.replace(/\{width\}/g, config.width).replace(/\{height\}/g, config.height);
533539
}
534540
$preview.append("\n" + content);
541+
self.autoSizeImage(previewId);
535542
} else {
536543
self.previewDefault(file, previewId);
537544
}
@@ -640,6 +647,44 @@
640647
slug: function (text) {
641648
return isEmpty(text) ? '' : text.split(/(\\|\/)/g).pop().replace(/[^\w-.\\\/ ]+/g,'');
642649
},
650+
setCaption: function(content) {
651+
var self = this, title = $('<div>' + content + '</div>').text(),
652+
icon = self.layoutTemplates['icon'],
653+
out = icon + title;
654+
if (self.$caption.length == 0) {
655+
return;
656+
}
657+
self.$caption.html(out);
658+
self.$caption.attr('title', title);
659+
self.autoSizeCaption();
660+
},
661+
autoSizeImage: function(previewId) {
662+
var self = this, $preview = self.$preview,
663+
$thumb = $preview.find("#" + previewId),
664+
$img = $thumb.find('img');
665+
if (!$img.length) {
666+
return;
667+
}
668+
$img.on('load', function() {
669+
var w1 = $thumb.width(), w2 = $preview.width();
670+
if (w1 > w2) {
671+
$img.css('width', '100%');
672+
$thumb.css('width', '97%');
673+
}
674+
self.$element.trigger('fileimageloaded', previewId);
675+
});
676+
},
677+
autoSizeCaption: function() {
678+
var self = this;
679+
if (self.$caption.length == 0 || !self.autoFitCaption) {
680+
return;
681+
}
682+
self.$caption.css('width', 0);
683+
setTimeout(function() {
684+
var w = self.$captionContainer.width();
685+
self.$caption.css('width', 0.98 * w);
686+
}, 100);
687+
},
643688
change: function (e) {
644689
var self = this, $el = self.$element, label = self.slug($el.val()),
645690
total = 0, $preview = self.$preview, files = $el.get(0).files, msgSelected = self.msgSelected,
@@ -678,8 +723,7 @@
678723
} else {
679724
self.showFileIcon();
680725
}
681-
self.$caption.html(log);
682-
self.$captionContainer.attr('title', $(log).text());
726+
self.setCaption(log);
683727
self.$container.removeClass('file-input-new');
684728
$el.trigger('fileselect', [numFiles, label]);
685729
},
@@ -776,6 +820,7 @@
776820
showPreview: true,
777821
showRemove: true,
778822
showUpload: true,
823+
autoFitCaption: true,
779824
mainClass: '',
780825
previewClass: '',
781826
captionClass: '',

js/fileinput.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)