/
jquery.fileinput.js
49 lines (49 loc) · 2.18 KB
/
jquery.fileinput.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
* {{= pkg.name}} v{{= pkg.version}}
*
* Copyright 2011, {{= pkg.author}}
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*/
(function($) {
$.fn.fileinput = function(replacement) {
var selector = this;
var replacementHtml = "<button class=\"fileinput\">Browse...</button>";
if (replacement) {
replacementHtml = $(replacement).removeAttr("id").addClass("fileinput").clone().wrap("<div />").parent().html();
$(replacement).remove();
}
selector.each(function() {
var element = $(this);
element.wrap("<div class=\"fileinput-wrapper\" style=\"position: relative; display: inline-block;\" />");
element.attr("tabindex", "-1").css({"font-size": "100px", height: "100%", filter: "alpha(opacity=0)", "-moz-opacity": 0, opacity: 0, position: "absolute", right: 0, top: 0, "z-index": -1});
element.before(replacementHtml);
var ua = $.browser;
if (ua.opera || (ua.mozilla && ua.version < "2.0")) {
element.css("z-index", "auto");
element.prev(".fileinput").css("z-index", -1);
element.removeAttr("tabindex");
element.prev(".fileinput").attr("tabindex", "-1");
element.hover(function() {
$(this).prev(".fileinput").addClass("hover");
}, function() {
$(this).prev(".fileinput").removeClass("hover");
}).focusin(function() {
$(this).prev(".fileinput").addClass("focus");
}).focusout(function() {
$(this).prev(".fileinput").removeClass("focus");
}).mousedown(function() {
$(this).prev(".fileinput").addClass("active");
}).mouseup(function() {
$(this).prev(".fileinput").removeClass("active");
});
} else {
element.prev(".fileinput").click(function() {
element.click();
});
}
});
return selector;
};
})(jQuery);