From 6e8ca9cddaa895449ff519a8fafd1caa2fd7f039 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 24 Feb 2021 16:54:56 +0100 Subject: [PATCH] js: Add method `identifyLinkTarget()` to the loader --- public/js/icinga/loader.js | 52 ++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/public/js/icinga/loader.js b/public/js/icinga/loader.js index 5fb782d23..ce9c840fc 100644 --- a/public/js/icinga/loader.js +++ b/public/js/icinga/loader.js @@ -1076,8 +1076,7 @@ } // If everything else fails, our target is the first column... - var $col1 = $('#col1'); - var $target = $col1; + var $target = $('#col1'); // ...but usually we will use our own container... var $container = $el.closest('.container'); @@ -1089,23 +1088,9 @@ if ($el.closest('[data-base-target]').length) { var targetId = $el.closest('[data-base-target]').data('baseTarget'); - // Simulate _next to prepare migration to dynamic column layout - // YES, there are duplicate lines right now. - if (targetId === '_next') { - if (this.icinga.ui.hasOnlyOneColumn()) { - $target = $col1; - } else { - $target = $('#col2'); - } - } else if (targetId === '_self') { - $target = $el.closest('.container'); - } else if (targetId === '_main') { - $target = $col1; - } else { - $target = $('#' + targetId); - if (! $target.length) { - this.icinga.logger.warn('Link target "#' + targetId + '" does not exist in DOM.'); - } + $target = this.identifyLinkTarget(targetId, $el); + if (! $target.length) { + this.icinga.logger.warn('Link target "#' + targetId + '" does not exist in DOM.'); } } @@ -1116,6 +1101,35 @@ return $target; }, + /** + * Identify link target by the given id + * + * The id may also be one of the column aliases: `_next`, `_self` and `_main` + * + * @param {string} id + * @param {object} $of + * @return {object} + */ + identifyLinkTarget: function (id, $of) { + var $target; + + if (id === '_next') { + if (this.icinga.ui.hasOnlyOneColumn()) { + $target = $('#col1'); + } else { + $target = $('#col2'); + } + } else if (id === '_self') { + $target = $of.closest('.container'); + } else if (id === '_main') { + $target = $('#col1'); + } else { + $target = $('#' + id); + } + + return $target; + }, + /** * Smoothly render given HTML to given container */