/usr/share/zabbix/js/main.js is in zabbix-frontend-php 1:2.2.2+dfsg-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 | /*
** Zabbix
** Copyright (C) 2001-2014 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.
**/
// Array indexOf method for javascript<1.6 compatibility
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function (searchElement) {
'use strict';
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 -= 1000;
if (this.delayLeft < 0) {
location.replace(location.href);
}
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();
}
};
/*
* Main menu
*/
var MMenu = {
menus: {'empty': 0, 'view': 0, 'cm': 0, 'reports': 0, 'config': 0, 'admin': 0},
def_label: null,
sub_active: false,
timeout_reset: null,
timeout_change: null,
mouseOver: function(show_label) {
clearTimeout(this.timeout_reset);
this.timeout_change = setTimeout('MMenu.showSubMenu("' + show_label + '")', 200);
PageRefresh.restart();
},
submenu_mouseOver: function() {
clearTimeout(this.timeout_reset);
clearTimeout(this.timeout_change);
PageRefresh.restart();
},
mouseOut: function() {
clearTimeout(this.timeout_change);
this.timeout_reset = setTimeout('MMenu.showSubMenu("' + this.def_label + '")', 2500);
},
showSubMenu: function(show_label) {
var menu_div = $('sub_' + show_label);
if (!is_null(menu_div)) {
$(show_label).className = 'active';
menu_div.show();
for (var key in this.menus) {
if (key == show_label) {
continue;
}
var menu_cell = $(key);
if (!is_null(menu_cell)) {
if (menu_cell.tagName.toLowerCase() != 'select') {
menu_cell.className = '';
}
}
var sub_menu_cell = $('sub_' + key);
if (!is_null(sub_menu_cell)) {
sub_menu_cell.hide();
}
}
}
}
};
/*
* Automatic checkbox range selection
*/
var chkbxRange = {
startbox: null, // start checkbox obj
startboxName: null, // start checkbox name
chkboxes: {}, // ckbx list
prefix: null, // prefix for cookie name
pageGoName: null, // which checkboxes should be counted by Go button
pageGoCount: 0, // selected checkboxes
selectedIds: {}, // ids of selected checkboxes
goButton: null,
cookieName: null,
init: function() {
var path = new Curl();
var filename = basename(path.getPath(), '.php');
this.cookieName = 'cb_' + filename + (this.prefix ? '_' + this.prefix : '');
this.selectedIds = cookie.readJSON(this.cookieName);
var chkboxes = jQuery('.tableinfo .checkbox:not(:disabled)');
if (chkboxes.length > 0) {
for (var i = 0; i < chkboxes.length; i++) {
this.implement(chkboxes[i]);
}
}
this.selectMainCheckbox();
this.goButton = $('goButton');
if (!is_null(this.goButton)) {
addListener(this.goButton, 'click', this.submitGo.bindAsEventListener(this), false);
}
this.setGo();
},
implement: function(obj) {
var objName = obj.name.split('[')[0];
if (typeof(this.chkboxes[objName]) === 'undefined') {
this.chkboxes[objName] = [];
}
this.chkboxes[objName].push(obj);
addListener(obj, 'click', this.check.bindAsEventListener(this), false);
if (objName == this.pageGoName) {
var objId = jQuery(obj).val();
if (isset(objId, this.selectedIds)) {
obj.checked = true;
}
}
},
// check if all checkboxes are selected and select main checkbox, else disable checkbox, select options and button
selectMainCheckbox: function() {
var mainCheckbox = jQuery('.tableinfo .header .checkbox:not(:disabled)');
if (!mainCheckbox.length) {
return;
}
var countAvailable = jQuery('.tableinfo tr:not(.header) .checkbox:not(:disabled)').length;
if (countAvailable > 0) {
var countChecked = jQuery('.tableinfo tr:not(.header) .checkbox:not(:disabled):checked').length;
mainCheckbox = mainCheckbox[0];
mainCheckbox.checked = (countChecked == countAvailable);
if (mainCheckbox.checked) {
jQuery('.tableinfo .header').addClass('selectedMain');
}
else {
jQuery('.tableinfo .header').removeClass('selectedMain');
}
}
else {
mainCheckbox.disabled = true;
}
},
check: function(e) {
e = e || window.event;
var obj = Event.element(e);
PageRefresh.restart();
if (typeof(obj) === 'undefined' || obj.type.toLowerCase() != 'checkbox' || obj.disabled === true) {
return true;
}
this.setGo();
if (obj.name.indexOf('all_') > -1 || obj.name.indexOf('_single') > -1) {
return true;
}
var objName = obj.name.split('[')[0];
// check range selection
if (e.ctrlKey || e.shiftKey) {
if (!is_null(this.startbox) && this.startboxName == objName && obj.name != this.startbox.name) {
var chkboxes = this.chkboxes[objName];
var flag = false;
for (var i = 0; i < chkboxes.length; i++) {
if (typeof(chkboxes[i]) !== 'undefined') {
if (flag) {
chkboxes[i].checked = this.startbox.checked;
}
if (obj.name == chkboxes[i].name) {
break;
}
if (this.startbox.name == chkboxes[i].name) {
flag = true;
}
}
}
if (flag) {
this.setGo();
this.selectMainCheckbox();
return true;
}
else {
for (var i = chkboxes.length - 1; i >= 0; i--) {
if (typeof(chkboxes[i]) !== 'undefined') {
if (flag) {
chkboxes[i].checked = this.startbox.checked;
}
if (obj.name == chkboxes[i].name) {
this.setGo();
this.selectMainCheckbox();
return true;
}
if (this.startbox.name == chkboxes[i].name) {
flag = true;
}
}
}
}
}
this.setGo();
}
else {
this.selectMainCheckbox();
}
this.startbox = obj;
this.startboxName = objName;
},
checkAll: function(name, value) {
if (typeof(this.chkboxes[name]) === 'undefined') {
return false;
}
var chkboxes = this.chkboxes[name];
for (var i = 0; i < chkboxes.length; i++) {
if (typeof(chkboxes[i]) !== 'undefined' && chkboxes[i].disabled !== true) {
var objName = chkboxes[i].name.split('[')[0];
if (objName == name) {
chkboxes[i].checked = value;
}
}
}
var mainCheckbox = jQuery('.tableinfo .header .checkbox:not(:disabled)')[0];
if (mainCheckbox.checked) {
jQuery('.tableinfo .header').addClass('selectedMain');
}
else {
jQuery('.tableinfo .header').removeClass('selectedMain');
}
},
clearSelectedOnFilterChange: function() {
cookie.eraseArray(this.cookieName);
},
setGo: function() {
if (!is_null(this.pageGoName)) {
if (typeof(this.chkboxes[this.pageGoName]) !== 'undefined') {
var chkboxes = this.chkboxes[this.pageGoName];
for (var i = 0; i < chkboxes.length; i++) {
if (typeof(chkboxes[i]) !== 'undefined') {
var box = chkboxes[i];
var objName = box.name.split('[')[0];
var objId = box.name.split('[')[1];
objId = objId.substring(0, objId.lastIndexOf(']'));
var crow = getParent(box, 'tr');
if (box.checked) {
if (!is_null(crow)) {
var origClass = crow.getAttribute('origClass');
if (is_null(origClass)) {
crow.setAttribute('origClass', crow.className);
}
crow.className = 'selected';
}
if (objName == this.pageGoName) {
this.selectedIds[objId] = objId;
}
}
else {
if (!is_null(crow)) {
var origClass = crow.getAttribute('origClass');
if (!is_null(origClass)) {
crow.className = origClass;
crow.removeAttribute('origClass');
}
}
if (objName == this.pageGoName) {
delete(this.selectedIds[objId]);
}
}
}
}
}
var countChecked = 0;
for (var key in this.selectedIds) {
if (!empty(this.selectedIds[key])) {
countChecked++;
}
}
if (!is_null(this.goButton)) {
var tmp_val = this.goButton.value.split(' ');
this.goButton.value = tmp_val[0] + ' (' + countChecked + ')';
}
cookie.createJSON(this.cookieName, this.selectedIds);
if (jQuery('#go').length) {
jQuery('#go')[0].disabled = (countChecked == 0);
}
if (jQuery('#goButton').length) {
jQuery('#goButton')[0].disabled = (countChecked == 0);
}
this.pageGoCount = countChecked;
}
},
submitGo: function(e) {
e = e || window.event;
var goSelect = $('go');
var confirmText = goSelect.options[goSelect.selectedIndex].getAttribute('confirm');
if (!is_null(confirmText) && !confirm(confirmText)) {
Event.stop(e);
return false;
}
var form = getParent(this.goButton, 'form');
for (var key in this.selectedIds) {
if (!empty(this.selectedIds[key])) {
create_var(form.name, this.pageGoName + '[' + key + ']', key, false);
}
}
return true;
}
};
/*
* Audio Control System
*/
var AudioList = {
list: {}, // audio files options
dom: {}, // dom objects links
standart: {
'embed': {
'enablejavascript': 'true',
'autostart': 'false',
'loop': 0
},
'audio': {
'autobuffer': 'autobuffer',
'autoplay': null,
'controls': null
}
},
play: function(audiofile) {
if (!this.create(audiofile)) {
return false;
}
if (IE) {
try {
this.dom[audiofile].Play();
}
catch(e) {
setTimeout(this.play.bind(this, audiofile), 500);
}
}
else {
this.dom[audiofile].play();
}
},
pause: function(audiofile) {
if (!this.create(audiofile)) {
return false;
}
if (IE) {
try {
this.dom[audiofile].Stop();
}
catch(e) {
setTimeout(this.pause.bind(this, audiofile), 1000);
}
}
else {
this.dom[audiofile].pause();
}
},
stop: function(audiofile) {
if (!this.create(audiofile)) {
return false;
}
if (IE) {
this.dom[audiofile].setAttribute('loop', '0');
}
else {
this.dom[audiofile].removeAttribute('loop');
}
if (!IE) {
try {
if (!this.dom[audiofile].paused) {
this.dom[audiofile].currentTime = 0;
}
else if (this.dom[audiofile].currentTime > 0) {
this.dom[audiofile].play();
this.dom[audiofile].currentTime = 0;
this.dom[audiofile].pause();
}
}
catch(e) {
}
}
if (!is_null(this.list[audiofile].timeout)) {
clearTimeout(this.list[audiofile].timeout);
this.list[audiofile].timeout = null;
}
this.pause(audiofile);
this.endLoop(audiofile);
},
stopAll: function(e) {
for (var name in this.list) {
if (empty(this.dom[name])) {
continue;
}
this.stop(name);
}
},
volume: function(audiofile, vol) {
if (!this.create(audiofile)) {
return false;
}
},
loop: function(audiofile, params) {
if (!this.create(audiofile)) {
return false;
}
if (isset('repeat', params)) {
if (IE) {
this.play(audiofile);
}
else {
if (this.list[audiofile].loop == 0) {
if (params.repeat != 0) {
this.startLoop(audiofile, params.repeat);
}
else {
this.endLoop(audiofile);
}
}
if (this.list[audiofile].loop != 0) {
this.list[audiofile].loop--;
this.play(audiofile);
}
}
}
else if (isset('seconds', params)) {
if (IE) {
this.dom[audiofile].setAttribute('loop', '1');
}
else {
this.startLoop(audiofile, 9999999);
this.list[audiofile].loop--;
}
this.play(audiofile);
this.list[audiofile].timeout = setTimeout(AudioList.stop.bind(AudioList, audiofile), 1000 * parseInt(params.seconds, 10));
}
},
startLoop: function(audiofile, loop) {
if (!isset(audiofile, this.list)) {
return false;
}
if (isset('onEnded', this.list[audiofile])) {
this.endLoop(audiofile);
}
this.list[audiofile].loop = parseInt(loop, 10);
this.list[audiofile].onEnded = this.loop.bind(this, audiofile, {'repeat' : 0});
addListener(this.dom[audiofile], 'ended', this.list[audiofile].onEnded);
},
endLoop: function(audiofile) {
if (!isset(audiofile, this.list)) {
return true;
}
this.list[audiofile].loop = 0;
if (isset('onEnded', this.list[audiofile])) {
removeListener(this.dom[audiofile], 'ended', this.list[audiofile].onEnded);
this.list[audiofile].onEnded = null;
delete(this.list[audiofile].onEnded);
}
},
create: function(audiofile, params) {
if (typeof(audiofile) == 'undefined') {
return false;
}
if (isset(audiofile, this.list)) {
return true;
}
if (typeof(params) == 'undefined') {
params = {};
}
if (!isset('audioList', this.dom)) {
this.dom.audioList = document.createElement('div');
document.getElementsByTagName('body')[0].appendChild(this.dom.audioList);
this.dom.audioList.setAttribute('id', 'audiolist');
}
if (IE) {
this.dom[audiofile] = document.createElement('embed');
this.dom.audioList.appendChild(this.dom[audiofile]);
this.dom[audiofile].setAttribute('name', audiofile);
this.dom[audiofile].setAttribute('src', 'audio/' + audiofile);
this.dom[audiofile].style.display = 'none';
for (var key in this.standart.embed) {
if (isset(key, params)) {
this.dom[audiofile].setAttribute(key, params[key]);
}
else if (!is_null(this.standart.embed[key])) {
this.dom[audiofile].setAttribute(key, this.standart.embed[key]);
}
}
}
else {
this.dom[audiofile] = document.createElement('audio');
this.dom.audioList.appendChild(this.dom[audiofile]);
this.dom[audiofile].setAttribute('id', audiofile);
this.dom[audiofile].setAttribute('src', 'audio/' + audiofile);
for (var key in this.standart.audio) {
if (isset(key, params)) {
this.dom[audiofile].setAttribute(key, params[key]);
}
else if (!is_null(this.standart.audio[key])) {
this.dom[audiofile].setAttribute(key, this.standart.audio[key]);
}
}
this.dom[audiofile].load();
}
this.list[audiofile] = params;
this.list[audiofile].loop = 0;
this.list[audiofile].timeout = null;
return true;
},
remove: function(audiofile) {
if (!isset(audiofile, this.dom)) {
return true;
}
$(this.dom[audiofile]).remove();
delete(this.dom[audiofile]);
delete(this.list[audiofile]);
}
};
/*
* Replace standard blink functionality
*/
/**
* Sets HTML elements to blink.
* Example of usage:
* <span class="blink" data-time-to-blink="60">test 1</span>
* <span class="blink" data-time-to-blink="30">test 2</span>
* <span class="blink" data-toggle-class="normal">test 3</span>
* <span class="blink">test 3</span>
* <script type="text/javascript">
* jQuery(document).ready(function(
* jqBlink.blink();
* ));
* </script>
* Elements with class 'blink' will blink for 'data-seconds-to-blink' seconds
* If 'data-seconds-to-blink' is omitted, element will blink forever.
* For elements with class 'blink' and attribute 'data-toggle-class' class will be toggled.
* @author Konstantin Buravcov
*/
var jqBlink = {
shown: false, // are objects currently shown or hidden?
blinkInterval: 1000, // how fast will they blink (ms)
secondsSinceInit: 0,
/**
* Shows/hides the elements and repeats it self after 'this.blinkInterval' ms
*/
blink: function() {
var objects = jQuery('.blink');
// maybe some of the objects should not blink any more?
objects = this.filterOutNonBlinking(objects);
// changing visibility state
fun = this.shown ? 'removeClass' : 'addClass';
jQuery.each(objects, function() {
if (typeof jQuery(this).data('toggleClass') !== 'undefined') {
jQuery(this)[fun](jQuery(this).data('toggleClass'));
}
else {
jQuery(this).css('visibility', jqBlink.shown ? 'hidden' : 'visible');
}
})
// reversing the value of indicator attribute
this.shown = !this.shown;
// I close my eyes only for a moment, and a moment's gone
this.secondsSinceInit += this.blinkInterval / 1000;
// repeating this function with delay
setTimeout(jQuery.proxy(this.blink, this), this.blinkInterval);
},
/**
* Check all currently found objects and exclude ones that should stop blinking by now
*/
filterOutNonBlinking: function(objects) {
var that = this;
return objects.filter(function() {
var obj = jQuery(this);
if (typeof obj.data('timeToBlink') !== 'undefined') {
var shouldBlink = parseInt(obj.data('timeToBlink'), 10) > that.secondsSinceInit;
// if object stops blinking, it should be left visible
if (!shouldBlink && !that.shown) {
obj.css('visibility', 'visible');
}
return shouldBlink;
}
else {
// no time-to-blink attribute, should blink forever
return true;
}
});
}
};
/*
* HintBox class.
*/
var hintBox = {
createBox: function(e, target, hintText, width, className, isStatic) {
var box = jQuery('<div></div>').addClass('hintbox');
if (typeof hintText === 'string') {
hintText = hintText.replace(/\n/g, '<br />');
}
if (!empty(className)) {
box.append(jQuery('<span></span>').addClass(className).html(hintText));
}
else {
box.html(hintText);
}
if (!empty(width)) {
box.css('width', width + 'px');
}
if (isStatic) {
var close_link = jQuery('<div>' + locale['S_CLOSE'] + '</div>')
.addClass('link')
.css({
'text-align': 'right',
'border-bottom': '1px #333 solid'
}).click(function() {
hintBox.hideHint(e, target, true);
});
box.prepend(close_link);
}
jQuery('body').append(box);
return box;
},
HintWraper: function(e, target, hintText, width, className) {
target.isStatic = false;
jQuery(target).on('mouseenter', function(e, d) {
if (d) {
e = d;
}
hintBox.showHint(e, target, hintText, width, className, false);
}).on('mouseleave', function(e) {
hintBox.hideHint(e, target);
}).on('remove', function(e) {
hintBox.deleteHint(target);
});
jQuery(target).removeAttr('onmouseover');
jQuery(target).trigger('mouseenter', e);
},
showStaticHint: function(e, target, hint, width, className, resizeAfterLoad) {
var isStatic = target.isStatic;
hintBox.hideHint(e, target, true);
if (!isStatic) {
target.isStatic = true;
hintBox.showHint(e, target, hint, width, className, true);
if (resizeAfterLoad) {
hint.one('load', function(e) {
hintBox.positionHint(e, target);
});
}
}
},
showHint: function(e, target, hintText, width, className, isStatic) {
if (target.hintBoxItem) {
return;
}
target.hintBoxItem = hintBox.createBox(e, target, hintText, width, className, isStatic);
hintBox.positionHint(e, target);
target.hintBoxItem.show();
},
positionHint: function(e, target) {
var wWidth = jQuery(window).width(),
wHeight = jQuery(window).height(),
scrollTop = jQuery(window).scrollTop(),
scrollLeft = jQuery(window).scrollLeft(),
top, left;
// uses stored clientX on afterload positioning when there is no event
if (e.clientX) {
target.clientX = e.clientX;
target.clientY = e.clientY;
}
// doesn't fit in the screen horizontaly
if (target.hintBoxItem.width() + 10 > wWidth) {
left = scrollLeft + 2;
}
// 10px to right if fit
else if (wWidth - target.clientX - 10 > target.hintBoxItem.width()) {
left = scrollLeft + target.clientX + 10;
}
// 10px from screen right side
else {
left = scrollLeft + wWidth - 10 - target.hintBoxItem.width();
}
// 10px below if fit
if (wHeight - target.clientY - target.hintBoxItem.height() - 10 > 0) {
top = scrollTop + target.clientY + 10;
}
// 10px above if fit
else if (target.clientY - target.hintBoxItem.height() - 10 > 0) {
top = scrollTop + target.clientY - target.hintBoxItem.height() - 10;
}
// 10px below as fallback
else {
top = scrollTop + target.clientY + 10;
}
// fallback if doesnt't fit verticaly but could fit if aligned to right or left
if ((top - scrollTop + target.hintBoxItem.height() > wHeight)
&& (target.clientX - 10 > target.hintBoxItem.width() || wWidth - target.clientX - 10 > target.hintBoxItem.width())) {
// align to left if fit
if (wWidth - target.clientX - 10 > target.hintBoxItem.width()) {
left = scrollLeft + target.clientX + 10;
}
// align to right
else {
left = scrollLeft + target.clientX - target.hintBoxItem.width() - 10;
}
// 10px from bottom if fit
if (wHeight - 10 > target.hintBoxItem.height()) {
top = scrollTop + wHeight - target.hintBoxItem.height() - 10;
}
// 10px from top
else {
top = scrollTop + 10;
}
}
target.hintBoxItem.css({
top: top + 'px',
left: left + 'px',
zIndex: 100
});
},
hideHint: function(e, target, hideStatic) {
if (target.isStatic && !hideStatic) {
return;
}
hintBox.deleteHint(target);
},
deleteHint: function(target) {
if (target.hintBoxItem) {
target.hintBoxItem.remove();
delete target.hintBoxItem;
if (target.isStatic) {
delete target.isStatic;
}
}
}
};
/*
* Color picker
*/
function hide_color_picker() {
if (!color_picker) {
return;
}
color_picker.style.zIndex = 1000;
color_picker.style.visibility = 'hidden';
color_picker.style.left = '-' + ((color_picker.style.width) ? color_picker.style.width : 100) + 'px';
curr_lbl = null;
curr_txt = null;
}
function show_color_picker(id) {
if (!color_picker) {
return;
}
curr_lbl = document.getElementById('lbl_' + id);
curr_txt = document.getElementById(id);
var pos = getPosition(curr_lbl);
color_picker.x = pos.left;
color_picker.y = pos.top;
color_picker.style.left = (color_picker.x + 20) + 'px';
color_picker.style.top = color_picker.y + 'px';
color_picker.style.visibility = 'visible';
}
function create_color_picker() {
if (color_picker) {
return;
}
color_picker = document.createElement('div');
color_picker.setAttribute('id', 'color_picker');
color_picker.innerHTML = color_table;
document.body.appendChild(color_picker);
hide_color_picker();
}
function set_color(color) {
if (curr_lbl) {
curr_lbl.style.background = curr_lbl.style.color = '#' + color;
curr_lbl.title = '#' + color;
}
if (curr_txt) {
curr_txt.value = color.toString().toUpperCase();
}
hide_color_picker();
}
function set_color_by_name(id, color) {
curr_lbl = document.getElementById('lbl_' + id);
curr_txt = document.getElementById(id);
set_color(color);
}
/*
* Zabbix ajax requests
*/
function add2favorites(favobj, favid) {
if ('undefined' == typeof(Ajax)) {
throw('Prototype.js lib is required!');
}
if (typeof(favid) == 'undefined' || empty(favid)) {
return;
}
var params = {
'favobj': favobj,
'favid': favid,
'favaction': 'add'
};
send_params(params);
}
function rm4favorites(favobj, favid, menu_rowid) {
if ('undefined' == typeof(Ajax)) {
throw('Prototype.js lib is required!');
}
if (typeof(favobj) == 'undefined' || typeof(favid) == 'undefined') {
throw 'No agruments sent to function [rm4favorites()].';
}
var params = {
'favobj': favobj,
'favid': favid,
'favcnt': menu_rowid,
'favaction': 'remove'
};
send_params(params);
}
function changeFlickerState(id) {
deselectAll();
var state = showHide(id);
switchElementsClass($('flicker_icon_l'), 'dbl_arrow_up', 'dbl_arrow_down');
switchElementsClass($('flicker_icon_r'), 'dbl_arrow_up', 'dbl_arrow_down');
send_params({
favaction: 'flop',
favobj: 'filter',
favref: id,
favstate: state
});
// resize multiselect
if (typeof(flickerResizeMultiselect) === 'undefined' && state == 1) {
flickerResizeMultiselect = true;
if (jQuery('.multiselect').length > 0) {
jQuery('#' + id).multiSelect.resize();
}
}
}
function changeHatStateUI(icon, divid) {
deselectAll();
var switchIcon = function() {
switchElementsClass(icon, 'arrowup', 'arrowdown');
};
jQuery($(divid).parentNode).
find('.body').toggle().end().
find('.footer').toggle().end();
switchIcon();
var hat_state = jQuery(icon).hasClass('arrowup') ? 1 : 0;
if (false === hat_state) {
return false;
}
var params = {
'favaction': 'flop',
'favobj': 'hat',
'favref': divid,
'favstate': hat_state
};
send_params(params);
}
function change_hat_state(icon, divid) {
deselectAll();
var switchIcon = function() {
switchElementsClass(icon, 'arrowup', 'arrowdown');
};
var hat_state = showHide(divid);
switchIcon();
if (false === hat_state) {
return false;
}
var params = {
'favaction': 'flop',
'favobj': 'hat',
'favref': divid,
'favstate': hat_state
};
send_params(params);
}
function send_params(params) {
if (typeof(params) === 'undefined') {
params = [];
}
var url = new Curl(location.href);
url.setQuery('?output=ajax');
new Ajax.Request(url.getUrl(), {
'method': 'post',
'parameters': params,
'onSuccess': function() { },
'onFailure': function() {
document.location = url.getPath() + '?' + Object.toQueryString(params);
}
}
);
}
function setRefreshRate(pmasterid, dollid, interval, params) {
if (typeof(Ajax) == 'undefined') {
throw('Prototype.js lib is required!');
}
if (typeof(params) == 'undefined' || is_null(params)) {
params = {};
}
params['pmasterid'] = pmasterid;
params['favobj'] = 'set_rf_rate';
params['favref'] = dollid;
params['favcnt'] = interval;
send_params(params);
}
function switch_mute(icon) {
deselectAll();
var sound_state = switchElementsClass(icon, 'iconmute', 'iconsound');
if (false === sound_state) {
return false;
}
sound_state = (sound_state == 'iconmute') ? 1 : 0;
var params = {
'favobj': 'sound',
'favref': 'sound',
'favstate': sound_state
};
send_params(params);
}
function createPlaceholders() {
if (IE) {
jQuery(document).ready(function() {
jQuery('[placeholder]')
.focus(function() {
var obj = jQuery(this);
if (obj.val() == obj.attr('placeholder')) {
obj.val('');
obj.removeClass('placeholder');
}
})
.blur(function() {
var obj = jQuery(this);
if (obj.val() == '' || obj.val() == obj.attr('placeholder')) {
obj.val(obj.attr('placeholder'));
obj.addClass('placeholder');
}
})
.blur();
jQuery('form').submit(function() {
jQuery('.placeholder').each(function() {
var obj = jQuery(this);
if (obj.val() == obj.attr('placeholder')) {
obj.val('');
}
});
});
});
}
}
|