/* ** Zabbix ** Copyright (C) 2001-2023 Zabbix SIA ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation; either version 2 of the License, or ** (at your option) any later version. ** ** This program is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** ** You should have received a copy of the GNU General Public License ** along with this program; if not, write to the Free Software ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. **/ // Global constants. // Sync with SASS variable: $ui-transition-duration. const UI_TRANSITION_DURATION = 300; const PROFILE_TYPE_INT = 2; const PROFILE_TYPE_STR = 3; // Array indexOf method for javascript<1.6 compatibility if (!Array.prototype.indexOf) { Array.prototype.indexOf = function (searchElement) { if (this === void 0 || this === null) { throw new TypeError(); } var t = Object(this); var len = t.length >>> 0; if (len === 0) { return -1; } var n = 0; if (arguments.length > 0) { n = Number(arguments[1]); if (n !== n) { // shortcut for verifying if it's NaN n = 0; } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) { n = (n > 0 || -1) * Math.floor(Math.abs(n)); } } if (n >= len) { return -1; } var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); for (; k < len; k++) { if (k in t && t[k] === searchElement) { return k; } } return -1; } } /* * Page refresh */ var PageRefresh = { delay: null, // refresh timeout delayLeft: null, // left till refresh timeout: null, // link to timeout init: function(time) { this.delay = time; this.delayLeft = this.delay; this.start(); }, check: function() { if (is_null(this.delay)) { return false; } this.delayLeft = Math.max(-1, this.delayLeft - 1000); if (this.delayLeft < 0 && !overlays_stack.length) { if (ED) { sessionStorage.scrollTop = $('.wrapper').scrollTop(); } location.reload(); } else { this.timeout = setTimeout('PageRefresh.check()', 1000); } }, start: function() { if (is_null(this.delay)) { return false; } this.timeout = setTimeout('PageRefresh.check()', 1000); }, stop: function() { clearTimeout(this.timeout); }, restart: function() { this.stop(); this.delayLeft = this.delay; this.start(); } }; /* * Audio control system. */ var AudioControl = { timeoutHandler: null, loop: function(timeout) { AudioControl.timeoutHandler = setTimeout( function() { if (new Date().getTime() >= timeout) { AudioControl.stop(); } else { AudioControl.loop(timeout); } }, 1000 ); }, playOnce: function(name) { this.stop(); var obj = jQuery('#audio'); if (obj.length > 0 && obj.data('name') === name) { obj.trigger('play'); } else { this.create(name, false); } }, playLoop: function(name, delay) { this.stop(); var obj = jQuery('#audio'); if (obj.length > 0 && obj.data('name') === name) { obj.trigger('play'); } else { this.create(name, true); } AudioControl.loop(new Date().getTime() + delay * 1000); }, stop: function() { var obj = document.getElementById('audio'); if (obj !== null) { clearTimeout(AudioControl.timeoutHandler); jQuery(obj).trigger('pause'); } }, create: function(name, loop) { var obj = jQuery('#audio'); if (obj.length == 0 || obj.data('name') !== name) { obj.remove(); var audioOptions = { id: 'audio', 'data-name': name, src: 'audio/' + name, preload: 'auto', autoplay: true }; if (loop) { audioOptions.loop = true; } jQuery('body').append(jQuery('