Parcourir la source

Fix #44: Add support for IE10 and below

Kartik Visweswaran il y a 10 ans
Parent
commit
f8688265e3
3 fichiers modifiés avec 16 ajouts et 3 suppressions
  1. 1 0
      CHANGE.md
  2. 15 3
      js/fileinput.js
  3. 0 0
      js/fileinput.min.js

+ 1 - 0
CHANGE.md

@@ -6,6 +6,7 @@ version 2.6.0
 - Templatize errorContainer for display within the preview window.
 - Templatize errorContainer for display within the preview window.
 - (enh #42): Enhance plugin to configure the `elErrorContainer` for displaying validation errors.
 - (enh #42): Enhance plugin to configure the `elErrorContainer` for displaying validation errors.
 - (bug #43): Validate special characters in filename before generating caption.
 - (bug #43): Validate special characters in filename before generating caption.
+- (bug #44): Browser IE10 hangs on file clear.
 
 
 version 2.5.0
 version 2.5.0
 =============
 =============

+ 15 - 3
js/fileinput.js

@@ -349,11 +349,23 @@
         },
         },
         clearFileInput: function() {
         clearFileInput: function() {
             var self = this, $el = self.$element;
             var self = this, $el = self.$element;
+            if (isEmpty($el.val())) {
+                return;
+            }
             // Fix for IE ver < 11, that does not clear file inputs
             // Fix for IE ver < 11, that does not clear file inputs
+            // Requires a sequence of steps to prevent IE crashing but
+            // still allow clearing of the file input.
             if (/MSIE/.test(navigator.userAgent)) {
             if (/MSIE/.test(navigator.userAgent)) {
-                $el.wrap('<form>').closest('form').trigger('reset');
-                $el.unwrap();
-            } else {
+                var $frm1 = $el.closest('form');
+                if ($frm1.length) {
+                    $el.wrap('<form>');
+                    var $frm2 = $el.closest('form'), $tmpEl = $(document.createElement('div'));
+                    $frm2.before($tmpEl).after($frm1).trigger('reset');
+                    $el.unwrap().appendTo($tmpEl).unwrap();
+                } else {
+                    $el.wrap('<form>').closest('form').trigger('reset').unwrap();
+                }   
+            } else { // normal input clear behavior for other sane browsers
                 $el.val('');
                 $el.val('');
             }
             }
         },
         },

Fichier diff supprimé car celui-ci est trop grand
+ 0 - 0
js/fileinput.min.js


Certains fichiers n'ont pas été affichés car il y a eu trop de fichiers modifiés dans ce diff