move js for btn-file into php function

the new function printFileChooserJs() must be called in the js method
on every page where a file upload button is used
This commit is contained in:
Uwe Steinmann 2018-09-05 13:34:30 +02:00
parent d519990d5e
commit cefb89a8c2
2 changed files with 26 additions and 20 deletions

View File

@ -329,24 +329,6 @@ $(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]);
});
$(document).on('fileselect', '.upload-file .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);
}
});
$('div.ajax').each(function(index) { /* {{{ */
var element = $(this);
var url = '';

View File

@ -996,7 +996,31 @@ background-image: linear-gradient(to bottom, #882222, #111111);;
}
} /* }}} */
function getFileChooser($varname='userfile', $multiple=false, $accept='') { /* {{{ */
function printFileChooserJs() { /* {{{ */
?>
$(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]);
});
$(document).on('fileselect', '.upload-file .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);
}
});
});
<?php
} /* }}} */
function getFileChooserHtml($varname='userfile', $multiple=false, $accept='') { /* {{{ */
$id = preg_replace('/[^A-Za-z]/', '', $varname);
$html = '
<div id="'.$id.'-upload-files">
@ -1014,7 +1038,7 @@ background-image: linear-gradient(to bottom, #882222, #111111);;
} /* }}} */
function printFileChooser($varname='userfile', $multiple=false, $accept='') { /* {{{ */
echo self::getFileChooser($varname, $multiple, $accept);
echo self::getFileChooserHtml($varname, $multiple, $accept);
} /* }}} */
function printDateChooser($defDate = '', $varName) { /* {{{ */