From 153f3ba2f95af858e3427aa74a010ba5785389aa Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 6 Aug 2015 11:51:57 +0200 Subject: [PATCH] js: Drop function events.handleAnchor() and ui.scrollContainerToAnchor() There is ui.focusElement() now which handles ids as well. refs #8615 --- public/js/icinga/events.js | 26 ++------------------------ public/js/icinga/loader.js | 2 +- public/js/icinga/ui.js | 12 ------------ 3 files changed, 3 insertions(+), 37 deletions(-) diff --git a/public/js/icinga/events.js b/public/js/icinga/events.js index 1d9680ea0..c74c9e97a 100644 --- a/public/js/icinga/events.js +++ b/public/js/icinga/events.js @@ -322,28 +322,6 @@ return false; }, - /** - * Handle anchor, i.e. focus the element which is referenced by the anchor - * - * @param {string} element The name or id of the element to focus - */ - handleAnchor: function(element) { - var $element = $('#' + element); - if (! $element.length) { - // The name attribute is actually deprecated, on anchor tags, - // but we'll possibly handle links from another source - // (module etc) so that's used as a fallback - $element = $('[name="' + element + '"]'); - } - - if ($element.length) { - if (typeof $element.attr('tabindex') === 'undefined') { - $element.attr('tabindex', -1); - } - $element.focus(); - } - }, - /** * Someone clicked a link or tr[href] */ @@ -411,7 +389,7 @@ // This is an anchor only if (href.substr(0, 1) === '#' && href.length > 1 && href.substr(1, 1) !== '!') { - self.handleAnchor(href.substr(1)); + icinga.ui.focusElement(href.substr(1)); return; } @@ -441,7 +419,7 @@ formerUrl = $target.data('icingaUrl'); if (typeof formerUrl !== 'undefined' && formerUrl.split(/#/)[0] === href.split(/#/)[0]) { - icinga.ui.scrollContainerToAnchor($target, href.split(/#/)[1]); + icinga.ui.focusElement(href.split(/#/)[1], $target); $target.data('icingaUrl', href); if (formerUrl !== href) { icinga.history.pushCurrentState(); diff --git a/public/js/icinga/loader.js b/public/js/icinga/loader.js index 32722cb6b..56e2f8532 100644 --- a/public/js/icinga/loader.js +++ b/public/js/icinga/loader.js @@ -560,7 +560,7 @@ oldNotifications.appendTo($('#notifications')); } if (url.match(/#/)) { - this.icinga.ui.scrollContainerToAnchor(req.$target, url.split(/#/)[1]); + this.icinga.ui.focusElement(url.split(/#/)[1], req.$target); } if (newBody) { this.icinga.ui.fixDebugVisibility().triggerWindowResize(); diff --git a/public/js/icinga/ui.js b/public/js/icinga/ui.js index 897a82d06..b9cff23fd 100644 --- a/public/js/icinga/ui.js +++ b/public/js/icinga/ui.js @@ -193,18 +193,6 @@ $col.data('icingaModule', backup['data']['data-icinga-module']); }, - scrollContainerToAnchor: function ($container, anchorName) { - // TODO: Generic issue -> we probably should escape attribute value selectors!? - var $anchor = $("a[name='" + anchorName.replace(/'/, '\\\'') + "']", $container); - if ($anchor.length) { - $container.scrollTop(0); - $container.scrollTop($anchor.first().position().top); - this.icinga.logger.debug('Scrolling ', $container, ' to ', anchorName); - } else { - this.icinga.logger.info('Anchor "' + anchorName + '" not found in ', $container); - } - }, - triggerWindowResize: function () { this.onWindowResize({data: {self: this}}); },