Skip to content

Commit 120dd2e

Browse files
committed
Replaced jquery browser detection with a own check
1 parent 420612d commit 120dd2e

4 files changed

+32
-12
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ also in Firefox. It used the size attribute from the input element to change
1010
the width. The calculated size is unfortunately only a approximation to the
1111
real size, so there can be a deviation of some pixels to the desired size.
1212

13+
**Update:** FireFox v22 has changed the look of the file-input element. There is now only one button + label and no more input element.
14+
See bug report: [#838675](https://bugzilla.mozilla.org/show_bug.cgi?id=838675). The plugin will therefore only required for Firefox older versions.
15+
1316
Demo: [http://schueller.me/projects/jquery-plugins/](http://schueller.me/projects/jquery-plugins/#inputFileWidth)
1417

1518
Usage

inputFileWidth.jquery.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"firefox",
99
"input"
1010
],
11-
"version": "1.0.2",
11+
"version": "1.0.3",
1212
"author": {
1313
"name": "Thorsten Schüller",
1414
"email": "[email protected]"

jquery.inputFileWidth-min.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
/*
2-
* jQuery inputFileWidth Plugin v1.0.2
2+
* jQuery inputFileWidth Plugin v1.0.3
33
* Sets the width of an input file element.
44
* Copyright (c) 2010-2013, Thorsten Schüller
55
* http://schueller.me/projects/
66
* Licensed under the MIT license.
77
*/
88
(function(a){a.fn.inputFileWidth=function(b){if(!b){b="100%"
9-
}return this.filter("input:file").each(function(){var h=a(this),d,e,g=0,f,c,j="jquery-inputFileWidthContainer";
10-
if(a.browser.mozilla){if(h.parent("."+j).length){h.unwrap()}h.css("visibility","hidden").width("100%");
11-
h.attr("size",1);h.wrap('<div class="'+j+'" />');d=h.parent().css("overflow","hidden").width(b);
12-
e=d.prop("scrollWidth");for(f=1,c=500;f<c;f++){h.attr("size",f);g=d.prop("scrollWidth");
13-
if(g>e){h.attr("size",f>1?f-1:1);break}}h.css("visibility","visible")}else{h.width(b)
14-
}})}})(jQuery);
9+
}return this.filter("input:file").each(function(){var k=a(this),e,c,m=0,g,l,n="jquery-inputFileWidthContainer",d=navigator.userAgent.toLowerCase(),f,h="",j=0;
10+
f=/(chrome)[ \/]([\w.]+)/.exec(d)||/(webkit)[ \/]([\w.]+)/.exec(d)||/(opera)(?:.*version|)[ \/]([\w.]+)/.exec(d)||/(msie) ([\w.]+)/.exec(d)||d.indexOf("compatible")<0&&/(mozilla)(?:.*? rv:([\w.]+)|)/.exec(d)||[];
11+
h=f[1]||"";j=+f[2]||0;if(h=="mozilla"&&j<22){if(k.parent("."+n).length){k.unwrap()
12+
}k.css("visibility","hidden").width("100%");k.attr("size",1);k.wrap('<div class="'+n+'" />');
13+
e=k.parent().css("overflow","hidden").width(b);c=e.prop("scrollWidth");for(g=1,l=500;
14+
g<l;g++){k.attr("size",g);m=e.prop("scrollWidth");if(m>c){k.attr("size",g>1?g-1:1);
15+
break}}k.css("visibility","visible")}else{k.width(b)}})}})(jQuery);

jquery.inputFileWidth.js

+20-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* jQuery inputFileWidth Plugin v1.0.2
2+
* jQuery inputFileWidth Plugin v1.0.3
33
* Sets the width of an input file element.
44
* Copyright (c) 2010-2013, Thorsten Schüller
55
* http://schueller.me/projects/
@@ -20,10 +20,26 @@
2020
beforeResize,
2121
afterResize = 0,
2222
i, max,
23-
containerClass = "jquery-inputFileWidthContainer";
23+
containerClass = "jquery-inputFileWidthContainer",
24+
ua = navigator.userAgent.toLowerCase(),
25+
uaMatch,
26+
browser = "",
27+
version = 0;
2428

25-
// Only FF need this hack
26-
if ($.browser.mozilla)
29+
// Only FF < version 22 need this hack. To check this I use this
30+
// dirty and old-fashioned user-agent detection (RegEx is taken
31+
// from the old and meanwhile deprecated jQuery.browser check)
32+
uaMatch = /(chrome)[ \/]([\w.]+)/.exec( ua ) ||
33+
/(webkit)[ \/]([\w.]+)/.exec( ua ) ||
34+
/(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) ||
35+
/(msie) ([\w.]+)/.exec( ua ) ||
36+
ua.indexOf("compatible") < 0 &&
37+
/(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) ||
38+
[];
39+
browser = uaMatch[1] || "";
40+
version = +uaMatch[2] || 0;
41+
42+
if (browser == "mozilla" && version < 22)
2743
{
2844
// Remove first an already existing container
2945
if ($this.parent("."+containerClass).length) $this.unwrap();

0 commit comments

Comments
 (0)