From 315111a778d166e198333dd0df6215d813ab72d8 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Fri, 16 May 2014 09:17:43 +0200 Subject: [PATCH] add nicer looking file upload chooser --- styles/bootstrap/application.js | 20 ++++++++++++++++++++ views/bootstrap/class.Bootstrap.php | 15 +++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/styles/bootstrap/application.js b/styles/bootstrap/application.js index 7dab3e3ba..804cdf07f 100644 --- a/styles/bootstrap/application.js +++ b/styles/bootstrap/application.js @@ -213,6 +213,26 @@ $(document).ready( function() { }); +$(document).ready( function() { + $(document).on('change', '.btn-file :file', function() { + var input = $(this), + numFiles = input.get(0).files ? input.get(0).files.length : 1, + label = input.val().replace(/\\/g, '/').replace(/.*\//, ''); + input.trigger('fileselect', [numFiles, label]); + }); + + $('#upload-files').on('fileselect', '.btn-file :file', function(event, numFiles, label) { + var input = $(this).parents('.input-append').find(':text'), + log = numFiles > 1 ? numFiles + ' files selected' : label; + + if( input.length ) { + input.val(log); + } else { + if( log ) alert(log); + } + }); +}); + function allowDrop(ev) { ev.preventDefault(); return false; diff --git a/views/bootstrap/class.Bootstrap.php b/views/bootstrap/class.Bootstrap.php index 27487099c..5037a7bbe 100644 --- a/views/bootstrap/class.Bootstrap.php +++ b/views/bootstrap/class.Bootstrap.php @@ -748,6 +748,21 @@ background-image: linear-gradient(to bottom, #882222, #111111);; } } /* }}} */ + function printFileChooser($varname='userfile', $multiple=false, $accept='') { /* {{{ */ +?> +
+
+
+ + + > + +
+
+
+