From d265bcd8988ae9e83b84b375a58e074e5ffa5656 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 30 Sep 2015 11:51:59 +0200 Subject: Make file input look more consistent across browsers --- script/fileselect.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 script/fileselect.js (limited to 'script') diff --git a/script/fileselect.js b/script/fileselect.js new file mode 100644 index 00000000..df4ff7b9 --- /dev/null +++ b/script/fileselect.js @@ -0,0 +1,26 @@ +$(document).on('change', '.btn-file :file', function() { + var input = $(this); + var numFiles = input.get(0).files ? input.get(0).files.length : 1; + var label = input.val().replace(/\\/g, '/').replace(/.*\//, ''); + input.trigger('fileselect', [numFiles, label]); +}); + +$(document).ready(function() { + $('.btn-file :file').on('fileselect', function(event, numFiles, label) { + + var input = $(this).parents('.upload-ex').find(':text'); + var log = numFiles > 1 ? numFiles + ' files selected' : label; + + if (input.length) { + input.val(log); + } else { + if (log) + alert(log); + } + + }); +}); + +$('.upload-ex :text').click(function () { + $(this).parents('.upload-ex').find(':file').click(); +}); \ No newline at end of file -- cgit v1.2.3-55-g7522