From fcd56d6e93ca90c66ef0c0fbea67d4910d8a2a70 Mon Sep 17 00:00:00 2001 From: Rocco Howard Date: Wed, 3 Aug 2016 20:38:25 +1000 Subject: [PATCH 1/5] Show parent tabs if they exist Based on a new setting as to not change current behaviour, this change locates parent tabs (using the .tab-pane class) and shows them before we show the requested tab from the url hash. --- jquery.stickytabs.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/jquery.stickytabs.js b/jquery.stickytabs.js index a1a653e..618a21a 100644 --- a/jquery.stickytabs.js +++ b/jquery.stickytabs.js @@ -2,7 +2,7 @@ * jQuery Plugin: Sticky Tabs * * @author Aidan Lister - * @version 1.2.0 + * @version 1.2.4 */ (function ( $ ) { $.fn.stickyTabs = function( options ) { @@ -12,6 +12,7 @@ getHashCallback: function(hash, btn) { return hash }, selectorAttribute: "href", backToTop: false, + showParentTabs: false, initialTab: $('li.active > a', context) }, options ); @@ -19,12 +20,23 @@ var showTabFromHash = function() { var hash = settings.selectorAttribute == "href" ? window.location.hash : window.location.hash.substring(1); if (hash != '') { - var selector = hash ? 'a[' + settings.selectorAttribute +'="' + hash + '"]' : settings.initialTab; + var selector = hash ? 'a[' + settings.selectorAttribute +'="' + hash + '"]' : settings.initialTab; + if (settings.showParentTabs === true) { + showParentTabs(hash); + } $(selector, context).tab('show'); setTimeout(backToTop, 1); } } + var showParentTabs = function(hash) { + parent_hash = $('a[' + settings.selectorAttribute +'="' + hash + '"]').parents('.tab-pane').attr('id'); + if (parent_hash !== undefined) { + $('a[' + settings.selectorAttribute +'="#' + parent_hash + '"]').tab('show'); + showParentTabs('#' + parent_hash); + } + } + // We use pushState if it's available so the page won't jump, otherwise a shim. var changeHash = function(hash) { if (history && history.pushState) { From 3c265e12f3971e4f94a859f3a4ee699884190c7c Mon Sep 17 00:00:00 2001 From: Rocco Howard Date: Wed, 3 Aug 2016 20:39:08 +1000 Subject: [PATCH 2/5] Updated version --- bower.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bower.json b/bower.json index 2e5e3c9..7158c05 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "jquery-stickytabs", - "version": "1.2.3", + "version": "1.2.4", "homepage": "https://github.com/aidanlister/jquery-stickytabs", "authors": [ "Aidan Lister " From 59edf05acff361886c3bc445ba930d4f0f375d01 Mon Sep 17 00:00:00 2001 From: Rocco Howard Date: Wed, 3 Aug 2016 20:39:37 +1000 Subject: [PATCH 3/5] Updated version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index dac6ebd..4cb9343 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jquery-stickytabs", - "version": "1.2.3", + "version": "1.2.4", "description": "jquery-stickytabs =================", "main": "jquery.stickytabs.js", "directories": { From 425935a6a5ba11c4a4935fd9a9bc5c43fe04cc72 Mon Sep 17 00:00:00 2001 From: Rocco Howard Date: Wed, 3 Aug 2016 20:41:05 +1000 Subject: [PATCH 4/5] Updated readme with new option --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 0c9adbf..8df25d7 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ $(function() { |------|-------|-----------| | selectorAttribute | false | Override the default `href` attribute used as selector when you need to activate multiple TabPanels at once with a single Tab using the `data-target` attribute. | | backToTop |false | Prevent the page from jumping down to the tab content by setting the backToTop setting to true. | +| showParentTabs |false | Show the parent tabs so the selected tab comes into view if it is part of another tab grouping. | NuGet package ============= From 5e052197bc4d53f9a7e893da44f915b5707ecc6e Mon Sep 17 00:00:00 2001 From: Rocco Howard Date: Wed, 3 Aug 2016 20:42:16 +1000 Subject: [PATCH 5/5] Fixed whitespace --- jquery.stickytabs.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/jquery.stickytabs.js b/jquery.stickytabs.js index 618a21a..3b95bee 100644 --- a/jquery.stickytabs.js +++ b/jquery.stickytabs.js @@ -21,11 +21,11 @@ var hash = settings.selectorAttribute == "href" ? window.location.hash : window.location.hash.substring(1); if (hash != '') { var selector = hash ? 'a[' + settings.selectorAttribute +'="' + hash + '"]' : settings.initialTab; - if (settings.showParentTabs === true) { - showParentTabs(hash); - } - $(selector, context).tab('show'); - setTimeout(backToTop, 1); + if (settings.showParentTabs === true) { + showParentTabs(hash); + } + $(selector, context).tab('show'); + setTimeout(backToTop, 1); } }