;(function( $ ) {
// Browser supports HTML5 multiple file?
var multipleSupport = typeof $('<input/>')[0].multiple !== 'undefined',
isIE = /msie/i.test( navigator.userAgent );
$.fn.customFile = function() {
return this.each(function() {
var $file = $(this).addClass('customfile'), // the original file input
$wrap = $('<div class="customfile-wrap">'),
$input = $('<input type="text" class="customfile-filename" />'),
// Button that will be used in non-IE browsers
$button = $('<button type="button" class="customfile-upload">Open</button>'),
// Hack for IE
$label = $('<label class="customfile-upload" for="'+ $file[0].id +'">Open</label>');
// Hide by shifting to the left so we
// can still trigger events
$file.css({
position: 'absolute',
left: '-9999px'
});
$wrap.insertAfter( $file )
.append( $file, $input, ( isIE ? $label : $button ) );
// Prevent focus
$file.attr('tabIndex', -1);
$button.attr('tabIndex', -1);
$button.click(function () {
$file.focus().click(); // Open dialog
});
$file.change(function() {
var files = [], fileArr, filename;
// If multiple is supported then extract
// all filenames from the file array
if ( multipleSupport ) {
fileArr = $file[0].files;
for ( var i = 0, len = fileArr.length; i < len; i++ ) {
files.push( fileArr[i].name );
}
filename = files.join(', ');
// If not supported then just take the value
// and remove the path to just show the filename
} else {
filename = $file.val().split('\\').pop();
}
$input.val( filename ) // Set the value
.attr('title', filename) // Show filename in title tootlip
.focus(); // Regain focus
});
$input.on({
blur: function() { $file.trigger('blur');...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.