I post here my version of your widget, where we manage somes specific case for Firefox (label, initialization ...).
} else {
// For the reset form case
uploadFeedback
.text("No file selected...")
.attr("class", "customfile-feedback");
uploadButton.text('Browse');
}
})
.click(function(event){ //for IE and Opera, make sure change fires after choosing a file, using an async callback
fileInput.data('val', fileInput.val());
setTimeout(function(){
fileInput.trigger('checkChange');
},100);
});
if(fileInput.attr("id")){
// Manage properly the click on the associated label (in Firefox, we can have some problems)
$("label[for='" + fileInput.attr("id") + "']").live("click", function(event){
event.preventDefault();
event.stopImmediatePropagation();
event.stopPropagation();
fileInput.trigger('click');
});
}
//create custom control container
var upload = $('<div class="customfile"></div>');
//create custom control button
var uploadButton = $('<span class="customfile-button" aria-hidden="true">Browse</span>').appendTo(upload);
//create custom control feedback
var uploadFeedback = $('<span class="customfile-feedback" aria-hidden="true">No file selected...</span>').appendTo(upload);
//match disabled state
if(fileInput.is('[disabled]')){
fileInput.trigger('disable');
}
//on mousemove, keep file input under the cursor to steal click
upload
.mousemove(function(e){
fileInput.css({
'left': e.pageX - upload.offset().left - fileInput.outerWidth() + 20, //position right side 20px right of cursor X)
'top': e.pageY - upload.offset().top - 20
});
})
.insertAfter(fileInput); //insert after the input
fileInput.appendTo(upload);
//return jQuery
return $(this);