summaryrefslogtreecommitdiffstats
path: root/script
diff options
context:
space:
mode:
authorSimon Rettberg2015-09-30 11:51:59 +0200
committerSimon Rettberg2015-09-30 11:51:59 +0200
commitd265bcd8988ae9e83b84b375a58e074e5ffa5656 (patch)
tree78293475298bb002db86a7637c239975dd034db4 /script
parent[diskstat] Fix i18n placeholder name; update translations (diff)
downloadslx-admin-d265bcd8988ae9e83b84b375a58e074e5ffa5656.tar.gz
slx-admin-d265bcd8988ae9e83b84b375a58e074e5ffa5656.tar.xz
slx-admin-d265bcd8988ae9e83b84b375a58e074e5ffa5656.zip
Make file input look more consistent across browsers
Diffstat (limited to 'script')
-rw-r--r--script/fileselect.js26
1 files changed, 26 insertions, 0 deletions
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