Quellcode durchsuchen

Fix #119: Enhance caption to include ellipsis for long file names

Kartik Visweswaran vor 10 Jahren
Ursprung
Commit
50c5284505
6 geänderte Dateien mit 36 neuen und 7 gelöschten Zeilen
  1. 1 0
      CHANGE.md
  2. 1 6
      README.md
  3. 11 0
      css/fileinput.css
  4. 0 0
      css/fileinput.min.css
  5. 23 1
      js/fileinput.js
  6. 0 0
      js/fileinput.min.js

+ 1 - 0
CHANGE.md

@@ -12,6 +12,7 @@ version 4.1.5
 8. (bug #114): Prevent multiple file selection when using single file configuration.
 8. (bug #114): Prevent multiple file selection when using single file configuration.
 9. (enh #115): Autosize file caption responsively on window resize.
 9. (enh #115): Autosize file caption responsively on window resize.
 10. (enh #116): Hide remove and upload buttons until unless file(s) are selected.
 10. (enh #116): Hide remove and upload buttons until unless file(s) are selected.
+11. (enh #119): Enhance caption to include ellipsis for long file names
 
 
 version 4.1.4
 version 4.1.4
 =============
 =============

+ 1 - 6
README.md

@@ -36,9 +36,7 @@ The plugin incorporates a simple HTML markup with enhanced CSS styling of a HTML
 11. Upload action defaults to form submit. Supports an upload route/server action parameter for custom ajax based upload.
 11. Upload action defaults to form submit. Supports an upload route/server action parameter for custom ajax based upload.
 12. Triggers JQuery events for advanced development. Events currently available are `filereset`, `fileclear`, `filecleared`, `fileloaded`, and `fileerror`.
 12. Triggers JQuery events for advanced development. Events currently available are `filereset`, `fileclear`, `filecleared`, `fileloaded`, and `fileerror`.
 13. Disabled and readonly file input support.
 13. Disabled and readonly file input support.
-14. Dynamically auto size the file captions for long file names exceeding container width. New property `autoFitCaption` 
-  is added which defaults to `true`. When this is `true` the plugin will auto fit caption text within the container dynamically
-  and responsively based on window size.
+14. Dynamically auto size the file captions for long file names exceeding container width. 
 15. Raise new `fileimageuploaded` event that fires after image is completely loaded on the preview container.
 15. Raise new `fileimageuploaded` event that fires after image is completely loaded on the preview container.
 16. Autosize preview images when they exceed the size of the preview container.
 16. Autosize preview images when they exceed the size of the preview container.
 17. Completely templatized and extensible to allow configuration of the file-input the way the developer wants.
 17. Completely templatized and extensible to allow configuration of the file-input the way the developer wants.
@@ -156,9 +154,6 @@ _boolean_ whether to display the file upload button. Defaults to `true`. This wi
 #### showCancel
 #### showCancel
 _boolean_ whether to display the file upload cancel button. Defaults to `true`. This will be only enabled and displayed when an AJAX upload is in process.
 _boolean_ whether to display the file upload cancel button. Defaults to `true`. This will be only enabled and displayed when an AJAX upload is in process.
 
 
-#### autoFitCaption
-_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.
-
 #### captionClass
 #### captionClass
 _string_ any additional CSS class to append to the caption container.
 _string_ any additional CSS class to append to the caption container.
 
 

+ 11 - 0
css/fileinput.css

@@ -55,6 +55,17 @@
     display: inline-block;
     display: inline-block;
     overflow: hidden;
     overflow: hidden;
     max-height: 20px;
     max-height: 20px;
+    padding-right: 10px;
+}
+
+.file-caption-ellipsis {
+    position: absolute;
+    right: 10px;
+    margin-top: -6px;
+    font-size: 1.2em;
+    display: none;
+    font-weight: bold;
+    cursor: default;
 }
 }
 
 
 .kv-search-container .kv-search-clear {
 .kv-search-container .kv-search-clear {

Datei-Diff unterdrückt, da er zu groß ist
+ 0 - 0
css/fileinput.min.css


+ 23 - 1
js/fileinput.js

@@ -89,6 +89,7 @@
         '</div>',
         '</div>',
         icon: '<span class="glyphicon glyphicon-file kv-caption-icon"></span>',
         icon: '<span class="glyphicon glyphicon-file kv-caption-icon"></span>',
         caption: '<div tabindex="-1" class="form-control file-caption {class}">\n' +
         caption: '<div tabindex="-1" class="form-control file-caption {class}">\n' +
+        '   <span class="file-caption-ellipsis">&hellip;</span>\n' +
         '   <div class="file-caption-name"></div>\n' +
         '   <div class="file-caption-name"></div>\n' +
         '</div>',
         '</div>',
         modal: '<div id="{id}" class="modal fade">\n' +
         modal: '<div id="{id}" class="modal fade">\n' +
@@ -313,6 +314,7 @@
             self.uploadCount = 0;
             self.uploadCount = 0;
             self.uploadPercent = 0;
             self.uploadPercent = 0;
             self.$element.removeClass('file-loading');
             self.$element.removeClass('file-loading');
+            self.setEllipsis();
         },
         },
         raise: function(event) {
         raise: function(event) {
             var self = this;
             var self = this;
@@ -343,9 +345,23 @@
                 jqXHR: jqXHR
                 jqXHR: jqXHR
             };
             };
         },
         },
+        setEllipsis: function() {
+            var self = this, $ellipsis = self.$captionContainer.find('.file-caption-ellipsis'), $cap = self.$caption,
+                $div = $cap.clone().css('height', 'auto').hide();
+            self.$captionContainer.parent().before($div);
+            if ($div.outerWidth() > $cap.outerWidth()) {
+               $ellipsis.show();
+            } else {
+               $ellipsis.hide();
+            }
+            $div.remove();
+        },
         listen: function () {
         listen: function () {
             var self = this, $el = self.$element, $cap = self.$captionContainer, $btnFile = self.$btnFile;
             var self = this, $el = self.$element, $cap = self.$captionContainer, $btnFile = self.$btnFile;
             $el.on('change', $.proxy(self.change, self));
             $el.on('change', $.proxy(self.change, self));
+            $(window).on('resize', function() {
+                self.setEllipsis();
+            });
             $btnFile.off('click').on('click', function (ev) {
             $btnFile.off('click').on('click', function (ev) {
                 self.raise('filebrowse');
                 self.raise('filebrowse');
                 if (self.isError && !self.isUploadable) {
                 if (self.isError && !self.isUploadable) {
@@ -775,6 +791,7 @@
                 self.showFileIcon();
                 self.showFileIcon();
                 self.$preview.html(self.original.preview);
                 self.$preview.html(self.original.preview);
                 self.$caption.html(self.original.caption);
                 self.$caption.html(self.original.caption);
+                self.setEllipsis();
                 self.initPreviewDeletes();
                 self.initPreviewDeletes();
                 self.$container.removeClass('file-input-new');
                 self.$container.removeClass('file-input-new');
             } else {
             } else {
@@ -785,6 +802,7 @@
                 var cap = (!self.overwriteInitial && self.initialCaption.length > 0) ?
                 var cap = (!self.overwriteInitial && self.initialCaption.length > 0) ?
                     self.original.caption : '';
                     self.original.caption : '';
                 self.$caption.html(cap);
                 self.$caption.html(cap);
+                self.setEllipsis();
                 self.$caption.attr('title', '');
                 self.$caption.attr('title', '');
                 addCss(self.$container, 'file-input-new');
                 addCss(self.$container, 'file-input-new');
             }
             }
@@ -792,6 +810,7 @@
                 self.initialCaption = '';
                 self.initialCaption = '';
                 self.original.caption = '';
                 self.original.caption = '';
                 self.$caption.html('');
                 self.$caption.html('');
+                self.setEllipsis();
                 self.$captionContainer.find('.kv-caption-icon').hide();
                 self.$captionContainer.find('.kv-caption-icon').hide();
             }
             }
             self.hideFileIcon();
             self.hideFileIcon();
@@ -804,6 +823,7 @@
             self.clear(false);
             self.clear(false);
             self.$preview.html(self.original.preview);
             self.$preview.html(self.original.preview);
             self.$caption.html(self.original.caption);
             self.$caption.html(self.original.caption);
+            self.setEllipsis();
             self.$container.find('.fileinput-filename').text('');
             self.$container.find('.fileinput-filename').text('');
             self.raise('filereset');
             self.raise('filereset');
             if (self.initialPreview.length > 0) {
             if (self.initialPreview.length > 0) {
@@ -1419,6 +1439,7 @@
                 self.isError = throwError(msg, null, null, null);
                 self.isError = throwError(msg, null, null, null);
                 self.$captionContainer.find('.kv-caption-icon').hide();
                 self.$captionContainer.find('.kv-caption-icon').hide();
                 self.$caption.html(self.msgValidationError);
                 self.$caption.html(self.msgValidationError);
+                self.setEllipsis();
                 self.$container.removeClass('file-input-new file-input-ajax-new');
                 self.$container.removeClass('file-input-new file-input-ajax-new');
                 return;
                 return;
             }
             }
@@ -1459,6 +1480,8 @@
             }
             }
             self.$caption.html(out);
             self.$caption.html(out);
             self.$caption.attr('title', title);
             self.$caption.attr('title', title);
+            self.$captionContainer.find('.file-caption-ellipsis').attr('title', title);
+            self.setEllipsis();
         },
         },
         initBrowse: function ($container) {
         initBrowse: function ($container) {
             var self = this;
             var self = this;
@@ -1565,7 +1588,6 @@
         showRemove: true,
         showRemove: true,
         showUpload: true,
         showUpload: true,
         showCancel: true,
         showCancel: true,
-        autoFitCaption: true,
         mainClass: '',
         mainClass: '',
         previewClass: '',
         previewClass: '',
         captionClass: '',
         captionClass: '',

Datei-Diff unterdrückt, da er zu groß ist
+ 0 - 0
js/fileinput.min.js


Einige Dateien werden nicht angezeigt, da zu viele Dateien in diesem Diff geändert wurden.