hippie/source/templates/hippie/partials/_head_script.njk
Stephan Hagedorn b2ea5b01aa Requirements updated and new nunjucks variables
Fixed problems with base paths.
2020-04-04 23:56:49 +02:00

54 lines
1.6 KiB
Text

<!-- head.script.partial -->
<script>
//Entry script at page init
var debugOn = false;
var debugOnScreen = true;
var assetsLoaded = false;
// Get the current time difference between page
// load and when this func was invoked
function getTimeDiff () {
return new Date().getTime() - performance.timing.navigationStart;
}
// log message to console and add
// performance measuring information
function logPerf (msg, arg) {
if (debugOn) {
if (debugOnScreen && assetsLoaded) {
if (!$('#jsLogPerf').length) {
$('<div><div></div></div>')
.css('position', 'relative')
.find('div')
.attr('id', 'jsLogPerf')
.css({
position: 'fixed',
bottom: '16px',
right: '40px',
zIndex: '1000',
padding: '0 8px',
background: 'rgba(255,255,255,.8)',
color: 'rgb(128)',
fontSize: '1rem'
})
.end()
.prependTo('body');
// $('body').prepend('<div style="position:relative;"></div>');
// $('div').first().prepend('<div id="jslogPerf" style="position:fixed;bottom:8px;right:16px;z-index:1000;padding:8px;background:rgb(0,255,255,.5)"></div>');
}
$('#jsLogPerf').append('<p><b>' + getTimeDiff() + '</b>ms :: ' + msg);
// Alternative short-circuit evaluation
// needs element in document but prevents error if not
// $log = $log || $('#jslogPerf');
// $log.append('<p style="margin-bottom:4px;font-size:.75em;"><b>' + getTimeDiff() + '</b>ms :: ' + msg);
}
if (window.console) {
console.debug(getTimeDiff() + 'ms :: ' + msg, (arg ? arg : ''));
// NOTE Non standard feature. Not available on IE
if (console.timeStamp) {
console.timeStamp(msg);
}
}
}
}
</script>