forked from gett/scaler-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery-file-plugin.js
45 lines (37 loc) · 946 Bytes
/
jquery-file-plugin.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
jQuery.fn.file = function(fn) {
return this.each(function() {
var el = $(this);
var holder = $('<div></div>').appendTo(el).css({
position:'absolute',
overflow:'hidden',
'-moz-opacity':'0',
filter:'alpha(opacity: 0)',
opacity:'0',
zoom:'1',
width:el.outerWidth()+'px',
height:el.outerHeight()+'px',
'z-index':1
});
var wid = 0;
var inp;
var addInput = function() {
var current = inp = holder.html('<input '+(window.FormData ? 'multiple ' : '')+'type="file" style="border:none; position:absolute">').find('input');
wid = wid || current.width();
current.change(function() {
current.unbind('change');
addInput();
fn(current[0]);
});
};
var position = function(e) {
holder.offset(el.offset());
if (e) {
inp.offset({left:e.pageX-wid+25, top:e.pageY-10});
}
};
addInput();
el.mouseover(position);
el.mousemove(position);
position();
});
};