浏览代码

fix: cancel will not remove loading status

Hugh Harlequin 1 年之前
父节点
当前提交
40c5afa0e1
共有 1 个文件被更改,包括 18 次插入16 次删除
  1. 18 16
      js/fileinput.js

+ 18 - 16
js/fileinput.js

@@ -1,5 +1,5 @@
 /*!
- * bootstrap-fileinput v5.5.3
+ * bootstrap-fileinput vh.1.0.0 from v5.5.2
  * http://plugins.krajee.com/file-input
  *
  * Author: Kartik Visweswaran
@@ -1054,6 +1054,19 @@
             if (self.hideThumbnailContent) {
                 $h.addCss(self.$preview, 'hide-content');
             }
+            var fileSelectEle = $el[0];
+            fileSelectEle.onclick = function (e) {
+                window.addEventListener('focus', function () { setTimeout(afterSelected, 300); }, {once: true})
+                e.stopPropagation();  // stop Bubbling and Capture
+            }
+
+            function afterSelected() {
+                self._toggleLoading('hide');
+                (fileSelectEle.value.length == 0) && self._setFileDropZoneTitle();
+            }
+            $el[0].closest('.input-group').addEventListener('click', function (e) {
+                $el.click();
+            })
         },
         _initFileManager: function () {
             var self = this;
@@ -2582,6 +2595,7 @@
                     }
                 });
             }
+            $cont.find('.fileinput-remove').hide();
             self._handler($cont.find('.fileinput-remove:not([disabled])'), 'click', $.proxy(self.clear, self));
             self._handler($cont.find('.fileinput-cancel'), 'click', $.proxy(self.cancel, self));
             self._handler($cont.find('.fileinput-pause'), 'click', $.proxy(self.pause, self));
@@ -5025,7 +5039,6 @@
                 if (!self.$errorContainer.is(':visible') && (!$tar.parents(
                     '.file-preview-thumbnails').length || $tar.parents(
                     '.file-default-preview').length)) {
-                    self.$element.data('zoneClicked', true).trigger('click');
                     $zone.blur();
                 }
             });
@@ -5362,6 +5375,7 @@
                     self.clear();
                 }
                 self._raise('fileselectnone');
+                self._toggleLoading('hide');
                 return;
             }
             self._resetErrors();
@@ -5549,14 +5563,6 @@
             if ($body.length) {
                 $body.off(ev).on('focusout.fileinput', function () {
                     self._toggleLoading('show');
-                }).on('focusin.fileinput', function () {
-                    setTimeout(function () {
-                        if (!$el.val()) {
-                            self._setFileDropZoneTitle();
-                        }
-                        $body.off(ev);
-                        self._toggleLoading('hide');
-                    }, 2500);
                 });
             } else {
                 self._toggleLoading('hide');
@@ -6234,12 +6240,8 @@
         var args = Array.apply(null, arguments), retvals = [];
         args.shift();
         this.each(function () {
-            var options = {};
-            if (typeof option === 'object') {
-                options = $.extend(true, {}, $.fn.fileinput.defaults, option);
-            }
-            var self = $(this), data = self.data('fileinput'),
-                theme = options.theme || self.data('theme') || $.fn.fileinput.defaults.theme, l = {}, t = {},
+            var self = $(this), data = self.data('fileinput'), options = typeof option === 'object' && option,
+                theme = options.theme || self.data('theme'), l = {}, t = {},
                 lang = options.language || self.data('language') || $.fn.fileinput.defaults.language || 'en', opt;
             if (!data) {
                 if (theme) {