Skip to content
This repository was archived by the owner on Aug 31, 2022. It is now read-only.

Commit f9be31c

Browse files
author
scottjehl
committed
initial commit
0 parents  commit f9be31c

File tree

11 files changed

+149
-0
lines changed

11 files changed

+149
-0
lines changed

css/basic.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
body { font-family: "Segoe UI", Arial, sans-serif; }
2+
label{ display:block; }

css/enhanced.css

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
body { font-size: 62.5%; margin: 50px; }
2+
fieldset { padding: .6em 0;border:0;border-top: 1px dotted #ddd; }
3+
legend { font-size: 1.5em; font-weight: bold; color: #555; padding: .5em 1em .5em 0; background: #fff; }
4+
label { font-size: 1.4em; display: block; margin: .5em 10px .5em 0; }
5+
input#upload { background: #aaa url(../images/bg-btn.png) bottom repeat-x; padding: .4em 1.2em;border: 1px solid #aaa; color: #222; font-size: 1.2em; font-weight: bold; -moz-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px; cursor: pointer; margin: 2em 0; }
6+
input#upload:hover { background: #eee; color: #111; border-color:#777; }
7+
8+
9+
/*custom upload elements*/
10+
.customfile-input { position: absolute; height: 100px; cursor: pointer; background: transparent; border: 0; opacity: 0; -moz-opacity: 0; filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0); z-index: 999; }
11+
12+
.customfile { width: 400px; background: #666; cursor: pointer; overflow: hidden; padding: 2px; border: 1px solid #444; -moz-border-radius:7px; -webkit-border-radius:7px; border-radius:7px; position: relative; }
13+
.customfile-disabled { opacity: .5; filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0); cursor: default; }
14+
.customfile-feedback { display: block; margin: 1px 1px 1px 5px; font-size: 1.2em; color: #fff; font-style: italic; padding: .3em .6em; }
15+
.customfile-feedback-populated { color: #fff; font-style: normal; font-weight: bold; padding-left: 20px; background: url(../images/icon-generic.gif) left 4px no-repeat; }
16+
.customfile-button { border: 1px solid #999; background: #333 url(../images/bg-submit.gif) bottom repeat-x; color: #fff; font-weight: bold; float: right; width: 50px; padding: .3em .6em; text-align: center; text-decoration: none; font-size: 1.2em; -moz-border-radius:5px; -webkit-border-radius:5px; border-radius:5px; }
17+
.customfile-hover .customfile-button, .customfile-focus .customfile-button { color:#111; background: #aaa url(../images/bg-btn.png) bottom repeat-x; border-color:#aaa; padding: .3em .6em; }
18+
.customfile-focus .customfile-button { outline: 1px dotted #ccc; }
19+
20+
/*file type icons*/
21+
.customfile-ext-jpg, .customfile-ext-gif, .customfile-ext-png, .customfile-ext-jpeg, .customfile-ext-bmp { background-image: url(../images/icon-image.gif);}
22+
.customfile-ext-mp3, .customfile-ext-mp4, .customfile-ext-mov, .customfile-ext-swf, .customfile-ext-wav, .customfile-ext-m4v { background-image: url(../images/icon-media.gif);}
23+
.customfile-ext-zip, .customfile-ext-tar, .customfile-ext-sit { background-image: url(../images/icon-zip.gif);}
24+
25+

images/bg-btn.png

291 Bytes
Loading

images/bg-submit.gif

341 Bytes
Loading

images/icon-generic.gif

341 Bytes
Loading

images/icon-image.gif

355 Bytes
Loading

images/icon-media.gif

359 Bytes
Loading

images/icon-zip.gif

355 Bytes
Loading

index.html

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
5+
<title>File Uploader</title>
6+
<link href="css/basic.css" type="text/css" rel="stylesheet" />
7+
<script type="text/javascript" src="http://filamentgroup.github.com/EnhanceJS/enhance.js"></script>
8+
<script type="text/javascript">
9+
// Run capabilities test
10+
enhance({
11+
loadScripts: [
12+
'https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js',
13+
'js/jQuery.fileinput.js',
14+
'js/example.js'
15+
],
16+
loadStyles: ['css/enhanced.css']
17+
});
18+
</script>
19+
</head>
20+
<body>
21+
22+
<!-- realistic form attributes: <form action="#" method="post" enctype="multipart/form-data"> -->
23+
<form action="#">
24+
<fieldset>
25+
<legend>Profile image</legend>
26+
<label for="file">Choose photo</label>
27+
<input type="file" name="file" id="file" />
28+
<input type="submit" name="upload" id="upload" value="Upload photo" />
29+
</fieldset>
30+
</form>
31+
32+
33+
</body>
34+
</html>

js/example.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
$(function(){
2+
$('#file').customFileInput();
3+
});

js/jQuery.fileinput.js

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/**
2+
* --------------------------------------------------------------------
3+
* jQuery customfileinput plugin
4+
* Author: Scott Jehl, scott@filamentgroup.com
5+
* Copyright (c) 2009 Filament Group
6+
* licensed under MIT (filamentgroup.com/examples/mit-license.txt)
7+
* --------------------------------------------------------------------
8+
*/
9+
$.fn.customFileInput = function(){
10+
//apply events and styles for file input element
11+
var fileInput = $(this)
12+
.addClass('customfile-input') //add class for CSS
13+
.mouseover(function(){ upload.addClass('customfile-hover'); })
14+
.mouseout(function(){ upload.removeClass('customfile-hover'); })
15+
.focus(function(){
16+
upload.addClass('customfile-focus');
17+
fileInput.data('val', fileInput.val());
18+
})
19+
.blur(function(){
20+
upload.removeClass('customfile-focus');
21+
$(this).trigger('checkChange');
22+
})
23+
.bind('disable',function(){
24+
fileInput.attr('disabled',true);
25+
upload.addClass('customfile-disabled');
26+
})
27+
.bind('enable',function(){
28+
fileInput.removeAttr('disabled');
29+
upload.removeClass('customfile-disabled');
30+
})
31+
.bind('checkChange', function(){
32+
if(fileInput.val() && fileInput.val() != fileInput.data('val')){
33+
fileInput.trigger('change');
34+
}
35+
})
36+
.bind('change',function(){
37+
//get file name
38+
var fileName = $(this).val().split(/\\/).pop();
39+
//get file extension
40+
var fileExt = 'customfile-ext-' + fileName.split('.').pop().toLowerCase();
41+
//update the feedback
42+
uploadFeedback
43+
.text(fileName) //set feedback text to filename
44+
.removeClass(uploadFeedback.data('fileExt') || '') //remove any existing file extension class
45+
.addClass(fileExt) //add file extension class
46+
.data('fileExt', fileExt) //store file extension for class removal on next change
47+
.addClass('customfile-feedback-populated'); //add class to show populated state
48+
//change text of button
49+
uploadButton.text('Change');
50+
})
51+
.click(function(){ //for IE and Opera, make sure change fires after choosing a file, using an async callback
52+
fileInput.data('val', fileInput.val());
53+
setTimeout(function(){
54+
fileInput.trigger('checkChange');
55+
},100);
56+
});
57+
58+
//create custom control container
59+
var upload = $('<div class="customfile"></div>');
60+
//create custom control button
61+
var uploadButton = $('<span class="customfile-button" aria-hidden="true">Browse</span>').appendTo(upload);
62+
//create custom control feedback
63+
var uploadFeedback = $('<span class="customfile-feedback" aria-hidden="true">No file selected...</span>').appendTo(upload);
64+
65+
//match disabled state
66+
if(fileInput.is('[disabled]')){
67+
fileInput.trigger('disable');
68+
}
69+
70+
71+
//on mousemove, keep file input under the cursor to steal click
72+
upload
73+
.mousemove(function(e){
74+
fileInput.css({
75+
'left': e.pageX - upload.offset().left - fileInput.outerWidth() + 20, //position right side 20px right of cursor X)
76+
'top': e.pageY - upload.offset().top - $(window).scrollTop() - 3
77+
});
78+
})
79+
.insertAfter(fileInput); //insert after the input
80+
81+
fileInput.appendTo(upload);
82+
83+
//return jQuery
84+
return $(this);
85+
};

0 commit comments

Comments
 (0)