Files
opensourcepos/app/Views/partial/header_js.php
BudsieBuds e83c23cf0c Improve code style and PSR-12 compliance (#4204)
* Improve code style and PSR-12 compliance
- refactored code formatting to adhere to PSR-12 guidelines
- standardized coding conventions across the codebase
- added missing framework files and reverted markup changes
- reformatted arrays for enhanced readability
- updated language files for consistent styling and clarity
- minor miscellaneous improvements
2025-05-02 19:37:06 +02:00

84 lines
2.3 KiB
PHP

<?php
/**
* @var array $config
*/
?>
<script type="text/javascript">
// Live clock
var clock_tick = function clock_tick() {
setInterval('update_clock();', 1000);
}
// Start the clock immediately
clock_tick();
var update_clock = function update_clock() {
document.getElementById('liveclock').innerHTML = moment().format("<?= dateformat_momentjs($config['dateformat'] . ' ' . $config['timeformat']) ?>");
}
$.notifyDefaults({
placement: {
align: "<?= esc($config['notify_horizontal_position'], 'js') ?>",
from: "<?= esc($config['notify_vertical_position'], 'js') ?>"
}
});
var cookie_name = "<?= esc(config('Cookie')->prefix, 'js') . esc(config('Security')->cookieName, 'js') ?>";
var csrf_token = function() {
return Cookies.get(cookie_name);
};
var csrf_form_base = function() {
return {
<?= esc(config('Security')->tokenName, 'js') ?>: function() {
return csrf_token()
}
}
};
var setup_csrf_token = function() {
$('input[name="<?= esc(config('Security')->tokenName, 'js') ?>"]').val(csrf_token());
};
var ajax = $.ajax;
$.ajax = function() {
var args = arguments[0];
if (args['type'] && args['type'].toLowerCase() == 'post' && csrf_token()) {
if (typeof args['data'] === 'string') {
args['data'] += '&' + $.param(csrf_form_base());
} else {
args['data'] = $.extend(args['data'], csrf_form_base());
}
}
return ajax.apply(this, arguments);
};
$(document).ajaxComplete(setup_csrf_token);
$(document).ready(function() {
$("#logout").click(function(event) {
event.preventDefault();
$.ajax({
url: "<?= site_url('home/logout'); ?>",
data: {
"<?= esc(config('Security')->tokenName, 'js'); ?>": csrf_token()
},
success: function() {
window.location.href = '<?= site_url(); ?>';
},
method: "POST"
});
});
});
var submit = $.fn.submit;
$.fn.submit = function() {
setup_csrf_token();
submit.apply(this, arguments);
};
</script>