Explorar o código

Updates to release v4.3.9 fixes #902 fixes #905

Kartik Visweswaran %!s(int64=8) %!d(string=hai) anos
pai
achega
5ac24c12d2
Modificáronse 7 ficheiros con 266 adicións e 211 borrados
  1. 5 1
      CHANGE.md
  2. 5 0
      css/fileinput.css
  3. 0 0
      css/fileinput.min.css
  4. 56 20
      js/fileinput.js
  5. 0 9
      js/fileinput.min.js
  6. 0 52
      npm-debug.log
  7. 200 129
      sass/fileinput.scss

+ 5 - 1
CHANGE.md

@@ -3,7 +3,7 @@ Change Log: `bootstrap-fileinput`
 
 ## version 4.3.9
 
-**Date:** 09-Mar-2017 (_under development_)
+**Date:** 25-Mar-2017 (_under development_)
 
 1. (enh #863): New plugin method `zoom` with parameter `frameId` to allow custom triggering of zoomed preview for each thumbnail frame.
 2. (enh #881): Update Spanish Translations.
@@ -19,6 +19,10 @@ Change Log: `bootstrap-fileinput`
 12. (enh #894, #895): Correct file size validation for empty files.
 13. (enh #898): New plugin method to get files in preview and config.
 14. (bug #900): Correct `overwriteInitial` validation for async batch uploads returning dynamic initial preview post upload.
+15. (enh #902): Enhance zoom preview styling for large height images.
+16. (enh #905): Prevent duplicate files to be dragged and dropped.
+17. (enh #906): Add Swedish Translations.
+18. (enh #909): Update German Translations.
 
 ## version 4.3.8
 

+ 5 - 0
css/fileinput.css

@@ -438,6 +438,11 @@
     text-align: center;
 }
 
+.file-zoom-content .file-preview-image, .file-preview-
+.file-zoom-content .file-preview-video {
+    max-height: 100%
+}
+
 .file-preview-initial.sortable-chosen {
     background-color: #d9edf7;
 }

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 0
css/fileinput.min.css


+ 56 - 20
js/fileinput.js

@@ -123,7 +123,8 @@
             /** @namespace div.draggable */
             /** @namespace div.ondragstart */
             /** @namespace div.ondrop */
-            return !$h.isIE(9) && (div.draggable !== undefined || (div.ondragstart !== undefined && div.ondrop !== undefined));
+            return !$h.isIE(9) &&
+                (div.draggable !== undefined || (div.ondragstart !== undefined && div.ondrop !== undefined));
         },
         hasFileUploadSupport: function () {
             return $h.hasFileAPISupport() && window.FormData;
@@ -2641,9 +2642,30 @@
             }
             return fileCount;
         },
+        _getFileId: function (file) {
+            var self = this, custom = self.generateFileId, relativePath;
+            if (typeof custom === 'function') {
+                return custom(file, event);
+            }
+            if (!file) {
+                return null;
+            }
+            /** @namespace file.webkitRelativePath */
+            relativePath = file.webkitRelativePath || file.fileName || file.name || null;
+            if (!relativePath) {
+                return null;
+            }
+            return (file.size + '-' + relativePath.replace(/[^0-9a-zA-Z_-]/img, ''));
+        },
         _getFileName: function (file) {
             return file && file.name ? this.slug(file.name) : undefined;
         },
+        _getFileIds: function (skipNull) {
+            var self = this;
+            return self.fileids.filter(function (n) {
+                return (skipNull ? n !== undefined : n !== undefined && n !== null);
+            });
+        },
         _getFileNames: function (skipNull) {
             var self = this;
             return self.filenames.filter(function (n) {
@@ -2981,6 +3003,17 @@
             }
             self.$captionContainer.focus();
         },
+        _filterDuplicate: function (file, files, fileIds) {
+            var self = this, fileId = self._getFileId(file);
+            if (fileId && fileIds && fileIds.indexOf(fileId) > -1) {
+                return;
+            }
+            if (!fileIds) {
+                fileIds = [];
+            }
+            files.push(file);
+            fileIds.push(fileId);
+        },
         _change: function (e) {
             var self = this, $el = self.$element;
             if (!self.isUploadable && $h.isEmpty($el.val()) && self.fileInputCleared) { // IE 11 fix
@@ -2988,10 +3021,10 @@
                 return;
             }
             self.fileInputCleared = false;
-            var tfiles, msg, total, isDragDrop = arguments.length > 1, isAjaxUpload = self.isUploadable, i = 0, f, n, len,
+            var tfiles = [], msg, total, isDragDrop = arguments.length > 1, isAjaxUpload = self.isUploadable, n, len,
                 files = isDragDrop ? e.originalEvent.dataTransfer.files : $el.get(0).files, ctr = self.filestack.length,
-                isSingleUpload = $h.isEmpty($el.attr('multiple')), flagSingle = (isSingleUpload && ctr > 0), folders = 0,
-                throwError = function (mesg, file, previewId, index) {
+                isSingleUpload = $h.isEmpty($el.attr('multiple')), flagSingle = (isSingleUpload && ctr > 0),
+                folders = 0, fileIds = self._getFileIds(), throwError = function (mesg, file, previewId, index) {
                     var p1 = $.extend(true, {}, self._getOutData({}, {}, files), {id: previewId, index: index}),
                         p2 = {id: previewId, index: index, file: file, files: files};
                     return self.isUploadable ? self._showUploadError(mesg, p1) : self._showError(mesg, p2);
@@ -3003,24 +3036,22 @@
                 self.$container.find('.file-drop-zone .' + self.dropZoneTitleClass).remove();
             }
             if (isDragDrop) {
-                tfiles = [];
-                while (files[i]) {
-                    f = files[i];
-                    if (!f.type && f.size % 4096 === 0) {
+                $.each(files, function (i, f) {
+                    if (f && !f.type && f.size !== undefined && f.size % 4096 === 0) {
                         folders++;
                     } else {
-                        tfiles.push(f);
+                        self._filterDuplicate(f, tfiles, fileIds);
                     }
-                    i++;
-                }
+                });
             } else {
                 if (e.target.files === undefined) {
-                    tfiles = e.target && e.target.value ? [
-                        {name: e.target.value.replace(/^.+\\/, '')}
-                    ] : [];
+                    files = e.target && e.target.value ? [{name: e.target.value.replace(/^.+\\/, '')}] : [];
                 } else {
-                    tfiles = e.target.files;
+                    files = e.target.files;
                 }
+                $.each(files, function (i, f) {
+                    self._filterDuplicate(f, tfiles, fileIds);
+                });
             }
             if ($h.isEmpty(tfiles) || tfiles.length === 0) {
                 if (!isAjaxUpload) {
@@ -3079,16 +3110,16 @@
             return false;
         },
         _resetFileStack: function () {
-            var self = this, i = 0, newstack = [], newnames = [];
+            var self = this, i = 0, newstack = [], newnames = [], newids = [];
             self._getThumbs().each(function () {
-                var $thumb = $(this), ind = $thumb.attr('data-fileindex'),
-                    file = self.filestack[ind];
+                var $thumb = $(this), ind = $thumb.attr('data-fileindex'), file = self.filestack[ind];
                 if (ind === -1) {
                     return;
                 }
                 if (file !== undefined) {
                     newstack[i] = file;
                     newnames[i] = self._getFileName(file);
+                    newids[i] = self._getFileId(file);
                     $thumb.attr({'id': self.previewInitId + '-' + i, 'data-fileindex': i});
                     i++;
                 } else {
@@ -3097,23 +3128,27 @@
             });
             self.filestack = newstack;
             self.filenames = newnames;
+            self.fileids = newids;
         },
         clearStack: function () {
             var self = this;
             self.filestack = [];
             self.filenames = [];
+            self.fileids = [];
             return self.$element;
         },
         updateStack: function (i, file) {
             var self = this;
             self.filestack[i] = file;
             self.filenames[i] = self._getFileName(file);
+            self.fileids[i] = file && self._getFileId(file) || null;
             return self.$element;
         },
         addToStack: function (file) {
             var self = this;
             self.filestack.push(file);
             self.filenames.push(self._getFileName(file));
+            self.fileids.push(self._getFileId(file));
             return self.$element;
         },
         getFileStack: function (skipNull) {
@@ -3300,7 +3335,7 @@
                 self.$preview.find('.file-preview-initial').removeClass($h.SORT_CSS);
                 self._initSortable();
                 self.cacheInitialPreview = self.getPreview();
-                
+
                 for (i = 0; i < len; i++) {
                     if (self.filestack[i] !== undefined) {
                         self._uploadSingle(i, self.filestack, true);
@@ -3344,7 +3379,7 @@
             $modal.modal('show');
             self._initZoomButtons();
         },
-        getPreview: function() {
+        getPreview: function () {
             var self = this;
             return {
                 content: self.initialPreview,
@@ -3402,6 +3437,7 @@
         showUploadedThumbs: true,
         browseOnZoneClick: false,
         autoReplace: false,
+        generateFileId: null,
         previewClass: '',
         captionClass: '',
         frameClass: 'krajee-default',

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 9
js/fileinput.min.js


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 52
npm-debug.log


+ 200 - 129
sass/fileinput.scss

@@ -2,6 +2,8 @@
  * bootstrap-fileinput v4.3.9
  * http://plugins.krajee.com/file-input
  *
+ * Krajee default styling for bootstrap-fileinput.
+ *
  * Author: Kartik Visweswaran
  * Copyright: 2014 - 2017, Kartik Visweswaran, Krajee.com
  *
@@ -29,6 +31,7 @@
 .btn-file {
   position: relative;
   overflow: hidden;
+
   input[type=file] {
     position: absolute;
     top: 0;
@@ -65,10 +68,12 @@
   border: 1px solid #ebccd1;
   border-radius: 4px;
   padding: 15px;
+
   pre, ul {
     margin: 0;
     text-align: left;
   }
+
   pre {
     margin: 5px 0;
   }
@@ -88,74 +93,193 @@
   margin-bottom: 5px;
 }
 
-.file-preview-frame {
-  position: relative;
-  display: table;
-  margin: 8px;
-  height: 160px;
-  border: 1px solid #ddd;
-  box-shadow: 1px 1px 5px 0 #a2958a;
-  padding: 6px;
-  float: left;
-  text-align: center;
-  vertical-align: middle;
-  &:not(.file-preview-error):hover {
-    box-shadow: 3px 3px 5px 0 #333;
+.krajee-default {
+  &.file-preview-frame {
+    position: relative;
+    display: table;
+    margin: 8px;
+    border: 1px solid #ddd;
+    box-shadow: 1px 1px 5px 0 #a2958a;
+    padding: 6px;
+    float: left;
+    text-align: center;
+
+    &:not(.file-preview-error):hover {
+      box-shadow: 3px 3px 5px 0 #333;
+    }
+
+    .kv-file-content {
+      height: 170px;
+    }
+
+    .file-thumbnail-footer {
+      height: 70px;
+    }
   }
-}
 
-.file-preview-image {
-  vertical-align: middle;
-  image-orientation: from-image;
-}
+  .file-preview-image {
+    vertical-align: middle;
+    image-orientation: from-image;
+  }
 
-.file-preview-text {
-  display: block;
-  color: #428bca;
-  border: 1px solid #ddd;
-  font-family: Menlo, Monaco, Consolas, "Courier New", monospace;
-  outline: none;
-  padding: 8px;
-  resize: none;
-}
+  .file-preview-text {
+    display: block;
+    color: #428bca;
+    border: 1px solid #ddd;
+    font-family: Menlo, Monaco, Consolas, "Courier New", monospace;
+    outline: none;
+    padding: 8px;
+    resize: none;
+  }
 
-.file-preview-html {
-  border: 1px solid #ddd;
-  padding: 8px;
-  overflow: auto;
-}
+  .file-preview-html {
+    border: 1px solid #ddd;
+    padding: 8px;
+    overflow: auto;
+  }
 
-.file-zoom-dialog .file-preview-text {
-  font-size: 1.2em;
-}
+  &[data-template="audio"] .file-preview-audio {
+    display: table-cell;
+    vertical-align: middle;
+    height: 170px;
+    border: 1px solid #ddd;
+    border-radius: 5px;
+  }
 
-.file-preview-other {
-  left: 0;
-  top: 0;
-  right: 0;
-  bottom: 0;
-  margin: auto;
-  text-align: center;
-  vertical-align: middle;
-  padding: 10px;
-  &:hover {
-    opacity: 0.8;
+  .file-preview-audio audio {
+    vertical-align: middle;
   }
-}
 
-.file-actions, .file-other-error {
-  text-align: left;
-}
+  .file-zoom-dialog .file-preview-text {
+    font-size: 1.2em;
+  }
+
+  .file-preview-other {
+    left: 0;
+    top: 0;
+    right: 0;
+    bottom: 0;
+    margin: auto;
+    text-align: center;
+    vertical-align: middle;
+    padding: 10px;
+
+    &:hover {
+      opacity: 0.8;
+    }
+  }
+
+  .file-actions, .file-other-error {
+    text-align: left;
+  }
+
+  .file-other-icon {
+    font-size: 8em;
+  }
+
+  .file-actions {
+    margin-top: 15px;
+  }
+
+  .file-footer-buttons {
+    float: right;
+  }
+
+  .file-footer-caption {
+    display: block;
+    white-space: nowrap;
+    overflow: hidden;
+    text-overflow: ellipsis;
+    width: 160px;
+    text-align: center;
+    padding-top: 4px;
+    font-size: 11px;
+    color: #777;
+    margin: 5px auto;
+  }
+
+  .file-preview-error {
+    opacity: 0.65;
+    box-shadow: none;
+  }
+
+  .file-preview-frame:not(.file-preview-error) .file-footer-caption:hover {
+    color: #000;
+  }
+
+  .file-drag-handle, .file-upload-indicator {
+    position: absolute;
+    text-align: center;
+    bottom: -6px;
+    left: -6px;
+    padding: 8px 8px 1px 3px;
+    border-left: none;
+    border-bottom: none;
+    border-right: 1px solid #8a6d3b;
+    border-top: 1px solid #8a6d3b;
+    border-top-right-radius: 24px;
+    font-size: 12px;
+  }
+
+  .file-drag-handle {
+    background-color: #d9edf7;
+    border-color: #bce8f1;
+  }
+
+  .file-upload-indicator {
+    font-size: 13px;
+    background-color: #fcf8e3;
+    border-color: #faebcc;
+    padding-bottom: 0;
+  }
+
+  &.file-preview-error .file-upload-indicator {
+    background-color: #f2dede;
+    border-color: #ebccd1;
+  }
 
-.file-other-icon {
-  font-size: 4.8em;
+  &.file-preview-success .file-upload-indicator {
+    background-color: #dff0d8;
+    border-color: #d6e9c6;
+  }
+
+  &.file-preview-loading .file-upload-indicator {
+    background-color: #e5e5e5;
+    border-color: #777;
+  }
+
+  .file-thumb-progress {
+    height: 10px;
+
+    .progress, .progress-bar {
+      height: 10px;
+      font-size: 9px;
+      line-height: 10px;
+    }
+  }
+
+  .file-thumbnail-footer {
+    position: relative;
+  }
+
+  .file-thumb-progress {
+    position: absolute;
+    top: 35px;
+    left: 0;
+    right: 0;
+  }
+
+  &.kvsortable-ghost {
+    background: #e1edf7;
+    border: 2px solid #a1abff;
+  }
 }
 
 /* noinspection CssOverwrittenProperties */
 
 .file-zoom-dialog .file-other-icon {
   font-size: 8em;
-  font-size: 55vmin;
+  font-size: 65vmin;
 }
 
 .file-input-new {
@@ -187,47 +311,16 @@
   background: transparent url('../img/loading.gif') no-repeat scroll center center content-box !important;
 }
 
-.file-actions {
-  margin-top: 15px;
-}
-
-.file-footer-buttons {
-  float: right;
-}
+.file-sortable .file-drag-handle {
+  cursor: move;
+  cursor: -webkit-grabbing;
+  opacity: 1;
 
-.file-upload-indicator {
-  display: inline;
-  cursor: default;
-  opacity: 0.8;
-  width: 60%;
   &:hover {
-    font-weight: bold;
-    opacity: 1;
+    opacity: 0.7;
   }
 }
 
-.file-footer-caption {
-  display: block;
-  white-space: nowrap;
-  overflow: hidden;
-  text-overflow: ellipsis;
-  width: 160px;
-  text-align: center;
-  padding-top: 4px;
-  font-size: 11px;
-  color: #777;
-  margin: 5px auto;
-}
-
-.file-preview-error {
-  opacity: 0.65;
-  box-shadow: none;
-}
-
-.file-preview-frame:not(.file-preview-error) .file-footer-caption:hover {
-  color: #000;
-}
-
 .file-drop-zone {
   border: 1px dashed #aaa;
   border-radius: 4px;
@@ -254,10 +347,12 @@
     &:hover {
       border: 2px dashed #999;
     }
+
     &:focus {
       border: 2px solid #5acde2;
     }
   }
+
   .file-preview-thumbnails {
     cursor: default;
   }
@@ -273,26 +368,6 @@
   opacity: 0.65;
 }
 
-.file-thumb-progress {
-  height: 10px;
-  .progress, .progress-bar {
-    height: 10px;
-    font-size: 9px;
-    line-height: 10px;
-  }
-}
-
-.file-thumbnail-footer {
-  position: relative;
-}
-
-.file-thumb-progress {
-  position: absolute;
-  top: 35px;
-  left: 0;
-  right: 0;
-}
-
 .file-zoom-fullscreen {
   &.modal {
     position: fixed;
@@ -301,6 +376,7 @@
     bottom: 0;
     left: 0;
   }
+
   .modal-dialog {
     position: fixed;
     margin: 0;
@@ -308,10 +384,12 @@
     height: 100%;
     padding: 0;
   }
+
   .modal-content {
     border-radius: 0;
     box-shadow: none;
   }
+
   .modal-body {
     overflow-y: auto;
   }
@@ -321,6 +399,7 @@
   .modal-body {
     position: relative !important;
   }
+
   .btn-navigate {
     position: absolute;
     padding: 0;
@@ -333,6 +412,7 @@
     font-size: 4em;
     color: #1c94c4;
   }
+
   .floating-buttons {
     position: absolute;
     top: 5px;
@@ -342,6 +422,7 @@
 
 .floating-buttons {
   z-index: 3000;
+
   .btn {
     z-index: 3000;
   }
@@ -360,48 +441,38 @@
         opacity: 0.5;
       }
     }
+
     &[disabled] {
       opacity: 0.3;
     }
   }
+
   .btn-prev {
     left: 1px;
   }
+
   .btn-next {
     right: 1px;
   }
 }
 
-.file-drag-handle {
-  display: inline;
-  margin-right: 2px;
-  font-size: 16px;
-  opacity: 0.6;
-  cursor: not-allowed;
-}
+.file-zoom-content {
+  height: 480px;
+  text-align: center;
 
-.file-sortable .file-drag-handle {
-  cursor: move;
-  cursor: -webkit-grabbing;
-  opacity: 1;
-  &:hover {
-    opacity: 0.7;
+  .file-preview-image {
+    max-height: 100%;
   }
 }
 
-.file-zoom-content {
-  height: 480px;
-  text-align: center;
+.file-preview- .file-zoom-content .file-preview-video {
+  max-height: 100%;
 }
 
 .file-preview-initial.sortable-chosen {
   background-color: #d9edf7;
 }
 
-.file-preview-frame.sortable-ghost {
-  background-color: #eee;
-}
-
 /* IE 10 fix */
 
 .btn-file ::-ms-browse {

Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio