let Util = { timerSeconds: 1, /** * Get URL query */ query: function(name) { let queries = window.location.search.replace('?', '').split('&'); for(let i = 0; i < queries.length; i++) { let query = queries[i].split('='); let keyName = query[0]; let value = query[1]; if (keyName == name) return value; } }, /** * Notify */ notify: function(message) { if (!document.getElementById('notifications')) { let container = document.createElement('div'); container.setAttribute('id', 'notifications'); document.body.appendChild(container); } let dialog = document.createElement('div'); let text = document.createTextNode(message); dialog.appendChild(text); dialog.setAttribute('class', 'dialog'); setTimeout(function() { dialog.remove(); }, 8000); document.getElementById('notifications').insertBefore(dialog, document.getElementById('notifications').firstChild); }, /** * Start call timer */ startTimer: function() { this.timer = setInterval(() => { let date = new Date(null); console.log(this.timerSeconds); date.setSeconds(this.timerSeconds); document.getElementById('timer').innerHTML = date.toISOString().substr(11, 8); this.timerSeconds++; }, 1000); }, /** * Stop call timer */ stopTimer: function() { clearInterval(this.timer); this.timer = null; this.timerSeconds = 0; document.getElementById('timer').innerHTML = '00:00:00'; }, /** * Page navigation */ navigate: function(container, path) { this.load(container, path, function() { if ($('#side').css('display') == 'block') { $('#side').css('display', 'none'); $('#container').removeClass('side-display'); } else { $('#side').css('display', 'block'); $('#container').addClass('side-display'); } }); }, /** * Load view * @param {String} container Container element * @param {String} path Path to view */ load: function(container, path, cb) { $(container).load(path + '/?token=' + this.query('token'), function(response, status) { if (status == 'error') alert(response); cb(); }); }, showSpinner: function() { }, hideSpinner: function() { } };