From 0a7698698d0f206d9a7af94012411d7eae341024 Mon Sep 17 00:00:00 2001 From: Stefan Galinski <stefan@sgalinski.de> Date: Tue, 19 Jul 2016 22:27:31 +0200 Subject: [PATCH] [FEATURE] Jump to the active tab mentioned by the url hash --- Configuration/TypoScript/Frontend/setup.txt | 1 + Resources/Public/Scripts/Tabs.js | 52 +++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 Resources/Public/Scripts/Tabs.js diff --git a/Configuration/TypoScript/Frontend/setup.txt b/Configuration/TypoScript/Frontend/setup.txt index f7a186d..f5fcef5 100644 --- a/Configuration/TypoScript/Frontend/setup.txt +++ b/Configuration/TypoScript/Frontend/setup.txt @@ -1,6 +1,7 @@ # include the endless scrolling javascript code page.includeJSFooterlibs { sg_news_scrollbrowser = EXT:sg_news/Resources/Public/Scripts/ScrollBrowser.js + sg_news_tabs = EXT:sg_news/Resources/Public/Scripts/Tabs.js } # news feed as own page type diff --git a/Resources/Public/Scripts/Tabs.js b/Resources/Public/Scripts/Tabs.js new file mode 100644 index 0000000..d49c839 --- /dev/null +++ b/Resources/Public/Scripts/Tabs.js @@ -0,0 +1,52 @@ +/*************************************************************** + * Copyright notice + * + * (c) sgalinski Internet Services (https://www.sgalinski.de) + * + * All rights reserved + * + * This script is part of the TYPO3 project. The TYPO3 project 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 3 of the License, or + * (at your option) any later version. + * + * The GNU General Public License can be found at + * http://www.gnu.org/copyleft/gpl.html. + * + * This script 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. + * + * This copyright notice MUST APPEAR in all copies of the script! + ***************************************************************/ + +var SG = SG || {}; + +SG.TabListener = function() { + this.initialize(); +}; + +SG.TabListener.prototype = { + /** + * Jumps to the best tab if a tab hash is set + * + * @return {void} + */ + initialize: function() { + this.checkAndSwitchActiveTab(); + setInterval(this.checkAndSwitchActiveTab, 1000); + }, + + checkAndSwitchActiveTab: function() { + var $tabLink = $('a[href="' + location.hash + '"]'); + if ($tabLink.length && $tabLink.tab) { + $tabLink.tab('show'); + } + } +}; + +$(document).ready(function() { + (new SG.TabListener()); +}); -- GitLab