From 1ac4a2050c8076eb96e07e83721ebc9db864db94 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 14:47:21 +0200 Subject: Adding upstream version 0.3.3. Signed-off-by: Daniel Baumann --- public/js/module.js | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 public/js/module.js (limited to 'public/js/module.js') diff --git a/public/js/module.js b/public/js/module.js new file mode 100644 index 0000000..49816bd --- /dev/null +++ b/public/js/module.js @@ -0,0 +1,91 @@ +;(function (Icinga) { + + var Toplevelview = function (module) { + this.module = module; + this.initialize(); + }; + + Toplevelview.prototype = { + initialize: function () { + var addCSSRule = function (sheet, selector, rules, index) { + if ('insertRule' in sheet) { + sheet.insertRule(selector + '{' + rules + '}', index); + } else if ('addRule' in sheet) { + sheet.addRule(selector, rules, index); + } else { + Icinga.module.icinga.logger.debug('Can\'t insert CSS rule'); + } + }; + + var sheet = (function () { + var style = document.createElement('style'); + // WebKit hack + style.appendChild(document.createTextNode('')); + document.head.appendChild(style); + return style.sheet; + })(); + + addCSSRule( + sheet, + '#layout.twocols.wide-layout #col1.module-toplevelview,' + + '#layout.twocols.wide-layout #col1.module-toplevelview ~ #col2', + 'width: 50%', + 0 + ); + + this.module.on('click', '.tlv-view-tree .tlv-tree-node', this.processTreeNodeClick); + this.module.on('click', 'div[href].action', this.buttonClick, this); + this.module.on('rendered', this.rendered); + }, + + rendered: function (ev) { + this.collapseOnLoad(ev); + var $container = $(ev.currentTarget); + $container.find('.codemirror').each(function (i, el) { + var mode = el.getAttribute('data-codemirror-mode'); + var editor = CodeMirror.fromTextArea(el, { + lineNumbers: true, + mode: mode + }); + // avoid entering tab chars + editor.setOption('extraKeys', { + Tab: function(cm) { + var spaces = new Array(cm.getOption('indentUnit') + 1).join(' '); + cm.replaceSelection(spaces); + }, + 'Ctrl-F': 'findPersistent' + }); + }); + }, + + processTreeNodeClick: function (event) { + event.stopPropagation(); + var $el = $(event.currentTarget); + var $parent = $el.parents('.tlv-tree-node'); + var $all = $el.find('.tlv-tree-node'); + if (($parent.length === 0 && $all.hasClass('tlv-collapsed')) || $el.hasClass('tlv-collapsed')) { + $el.removeClass('tlv-collapsed'); + $all.removeClass('tlv-collapsed'); + } else { + $el.addClass('tlv-collapsed'); + $all.addClass('tlv-collapsed'); + } + }, + + collapseOnLoad: function (event) { + var $el = $(event.currentTarget); + $el.find('.tlv-view-tree .tlv-tree-node.tlv-collapsible.ok').addClass('tlv-collapsed'); + }, + + buttonClick: function (event) { + event.stopPropagation(); + var $el = $(event.currentTarget); + var $links = $el.find('a[href]'); + if ($links.length > 0) { + $links[0].click(); + } + } + }; + + Icinga.availableModules.toplevelview = Toplevelview; +}(Icinga)); -- cgit v1.2.3