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 */