add nicer looking file upload chooser

This commit is contained in:
Uwe Steinmann 2014-05-16 09:17:43 +02:00
parent 376477ec96
commit 315111a778
2 changed files with 35 additions and 0 deletions

View File

@ -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;

View File

@ -748,6 +748,21 @@ background-image: linear-gradient(to bottom, #882222, #111111);;
}
} /* }}} */
function printFileChooser($varname='userfile', $multiple=false, $accept='') { /* {{{ */
?>
<div id="upload-files">
<div id="upload-file">
<div class="input-append">
<input type="text" class="form-control" readonly>
<span class="btn btn-default btn-file">
<?php printMLText("browse");?>&hellip; <input type="file" name="<?php echo $varname; ?>"<?php if($multiple) echo " multiple"; ?><?php if($accept) echo " accept=\"".$accept."\""; ?>>
</span>
</div>
</div>
</div>
<?php
} /* }}} */
function printDateChooser($defDate = -1, $varName) { /* {{{ */
if ($defDate == -1)