From bec50892deac436e3b1a98473906623fd521156a Mon Sep 17 00:00:00 2001 From: Jessica Lawshe Date: Wed, 19 Sep 2018 17:58:07 -0500 Subject: [PATCH 1/7] Linkable tabs --- services/web/app/views/_scripts/active_tab.pug | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 services/web/app/views/_scripts/active_tab.pug diff --git a/services/web/app/views/_scripts/active_tab.pug b/services/web/app/views/_scripts/active_tab.pug new file mode 100644 index 0000000000..290505d6cb --- /dev/null +++ b/services/web/app/views/_scripts/active_tab.pug @@ -0,0 +1,10 @@ +script(type="text/javascript"). + if (window.location.hash) { + setTimeout(function(){ + tabID = window.location.hash.replace('#', '') + tab = document.getElementById(tabID) + if (tab && typeof(tab) != 'undefined' && tab != null) { + tab.setAttribute('active', true) + } + }, 500); + } \ No newline at end of file From 8e991425370fc0840e9ce2f468f3d4580c7ace6b Mon Sep 17 00:00:00 2001 From: Jessica Lawshe Date: Wed, 19 Sep 2018 18:45:34 -0500 Subject: [PATCH 2/7] Add main CMS controller Main is in index now, and blog controller moved to separate file --- services/web/public/coffee/main.coffee | 1 + 1 file changed, 1 insertion(+) diff --git a/services/web/public/coffee/main.coffee b/services/web/public/coffee/main.coffee index 49b211b0aa..8d6c6d2b26 100644 --- a/services/web/public/coffee/main.coffee +++ b/services/web/public/coffee/main.coffee @@ -24,6 +24,7 @@ define [ "main/affiliations/controllers/UserAffiliationsController" "main/affiliations/factories/UserAffiliationsDataService" "main/keys" + "main/cms/blog" "main/cms/index" "analytics/AbTestingManager" "directives/asyncForm" From baf8b599d756f3f12654f9c6ae3b26e808b15bae Mon Sep 17 00:00:00 2001 From: Alasdair Smith Date: Mon, 24 Sep 2018 10:59:49 +0100 Subject: [PATCH 3/7] Handle hash-bang urls used sometimes in v1 --- services/web/app/views/_scripts/active_tab.pug | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/web/app/views/_scripts/active_tab.pug b/services/web/app/views/_scripts/active_tab.pug index 290505d6cb..d79159739a 100644 --- a/services/web/app/views/_scripts/active_tab.pug +++ b/services/web/app/views/_scripts/active_tab.pug @@ -1,7 +1,7 @@ script(type="text/javascript"). if (window.location.hash) { setTimeout(function(){ - tabID = window.location.hash.replace('#', '') + tabID = window.location.hash.replace(/#!?/, '') tab = document.getElementById(tabID) if (tab && typeof(tab) != 'undefined' && tab != null) { tab.setAttribute('active', true) From 399a9ed604d44b33e58f5a087769c372ba87c5da Mon Sep 17 00:00:00 2001 From: Paulo Reis Date: Mon, 24 Sep 2018 14:43:12 +0100 Subject: [PATCH 4/7] Create bookmarkable tabs directive. --- .../directives/bookmarkableTabset.coffee | 29 +++++++++++++++++++ services/web/public/coffee/main.coffee | 1 + 2 files changed, 30 insertions(+) create mode 100644 services/web/public/coffee/directives/bookmarkableTabset.coffee diff --git a/services/web/public/coffee/directives/bookmarkableTabset.coffee b/services/web/public/coffee/directives/bookmarkableTabset.coffee new file mode 100644 index 0000000000..a0e6dc3640 --- /dev/null +++ b/services/web/public/coffee/directives/bookmarkableTabset.coffee @@ -0,0 +1,29 @@ +define [ + "base" +], (App) -> + App.directive "bookmarkableTabset", ($location, _) -> + restrict: "A" + require: "tabset" + link: (scope, el, attrs, tabset) -> + scope.$applyAsync () -> + hash = $location.hash() + if hash? + matchingTab = _.find tabset.tabs, (tab) -> + tab.bookmarkableTabId == hash + if matchingTab? + matchingTab.select() + + App.directive "bookmarkableTab", ($location) -> + restrict: "A" + require: "tab" + link: (scope, el, attrs, tab) -> + tabScope = el.isolateScope() + tabId = attrs.bookmarkableTab + if tabScope? and tabId? and tabId != "" + tabScope.bookmarkableTabId = tabId + tabScope.$watch "active", (isActive, wasActive) -> + if isActive and !wasActive + $location.hash tabId + + + diff --git a/services/web/public/coffee/main.coffee b/services/web/public/coffee/main.coffee index 8d6c6d2b26..c44c7ba6ed 100644 --- a/services/web/public/coffee/main.coffee +++ b/services/web/public/coffee/main.coffee @@ -37,6 +37,7 @@ define [ "directives/selectAll" "directives/maxHeight" "directives/creditCards" + "directives/bookmarkableTabset" "services/queued-http" "services/validateCaptcha" "filters/formatDate" From 1424ae686acc12ee5c28b43987bfd61eaca9a5e0 Mon Sep 17 00:00:00 2001 From: Paulo Reis Date: Tue, 25 Sep 2018 11:45:29 +0100 Subject: [PATCH 5/7] Add scrollIntoView behaviour. --- .../web/app/views/_scripts/active_tab.pug | 20 +++++++++---------- .../directives/bookmarkableTabset.coffee | 3 ++- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/services/web/app/views/_scripts/active_tab.pug b/services/web/app/views/_scripts/active_tab.pug index d79159739a..c54832586a 100644 --- a/services/web/app/views/_scripts/active_tab.pug +++ b/services/web/app/views/_scripts/active_tab.pug @@ -1,10 +1,10 @@ -script(type="text/javascript"). - if (window.location.hash) { - setTimeout(function(){ - tabID = window.location.hash.replace(/#!?/, '') - tab = document.getElementById(tabID) - if (tab && typeof(tab) != 'undefined' && tab != null) { - tab.setAttribute('active', true) - } - }, 500); - } \ No newline at end of file +//- script(type="text/javascript"). +//- if (window.location.hash) { +//- setTimeout(function(){ +//- tabID = window.location.hash.replace(/#!?/, '') +//- tab = document.getElementById(tabID) +//- if (tab && typeof(tab) != 'undefined' && tab != null) { +//- tab.setAttribute('active', true) +//- } +//- }, 500); +//- } \ No newline at end of file diff --git a/services/web/public/coffee/directives/bookmarkableTabset.coffee b/services/web/public/coffee/directives/bookmarkableTabset.coffee index a0e6dc3640..84251075df 100644 --- a/services/web/public/coffee/directives/bookmarkableTabset.coffee +++ b/services/web/public/coffee/directives/bookmarkableTabset.coffee @@ -12,6 +12,7 @@ define [ tab.bookmarkableTabId == hash if matchingTab? matchingTab.select() + el.children()[0].scrollIntoView({ behavior: "smooth" }) App.directive "bookmarkableTab", ($location) -> restrict: "A" @@ -22,7 +23,7 @@ define [ if tabScope? and tabId? and tabId != "" tabScope.bookmarkableTabId = tabId tabScope.$watch "active", (isActive, wasActive) -> - if isActive and !wasActive + if isActive and !wasActive and $location.hash() != tabId $location.hash tabId From 97fdf72346879f5eb028b30f2ae97fe5cd41afd4 Mon Sep 17 00:00:00 2001 From: Jessica Lawshe Date: Mon, 15 Oct 2018 14:53:52 -0500 Subject: [PATCH 6/7] If hash not empty and remove unused file --- services/web/app/views/_scripts/active_tab.pug | 10 ---------- .../public/coffee/directives/bookmarkableTabset.coffee | 2 +- 2 files changed, 1 insertion(+), 11 deletions(-) delete mode 100644 services/web/app/views/_scripts/active_tab.pug diff --git a/services/web/app/views/_scripts/active_tab.pug b/services/web/app/views/_scripts/active_tab.pug deleted file mode 100644 index c54832586a..0000000000 --- a/services/web/app/views/_scripts/active_tab.pug +++ /dev/null @@ -1,10 +0,0 @@ -//- script(type="text/javascript"). -//- if (window.location.hash) { -//- setTimeout(function(){ -//- tabID = window.location.hash.replace(/#!?/, '') -//- tab = document.getElementById(tabID) -//- if (tab && typeof(tab) != 'undefined' && tab != null) { -//- tab.setAttribute('active', true) -//- } -//- }, 500); -//- } \ No newline at end of file diff --git a/services/web/public/coffee/directives/bookmarkableTabset.coffee b/services/web/public/coffee/directives/bookmarkableTabset.coffee index 84251075df..e6434467a1 100644 --- a/services/web/public/coffee/directives/bookmarkableTabset.coffee +++ b/services/web/public/coffee/directives/bookmarkableTabset.coffee @@ -7,7 +7,7 @@ define [ link: (scope, el, attrs, tabset) -> scope.$applyAsync () -> hash = $location.hash() - if hash? + if hash? and hash != "" matchingTab = _.find tabset.tabs, (tab) -> tab.bookmarkableTabId == hash if matchingTab? From 1362da710b2192e87fcb9a133b56597b4b27ef64 Mon Sep 17 00:00:00 2001 From: Jessica Lawshe Date: Mon, 15 Oct 2018 15:26:00 -0500 Subject: [PATCH 7/7] Watch for hash change for tabs --- .../directives/bookmarkableTabset.coffee | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/services/web/public/coffee/directives/bookmarkableTabset.coffee b/services/web/public/coffee/directives/bookmarkableTabset.coffee index e6434467a1..d5b80f23d2 100644 --- a/services/web/public/coffee/directives/bookmarkableTabset.coffee +++ b/services/web/public/coffee/directives/bookmarkableTabset.coffee @@ -5,8 +5,11 @@ define [ restrict: "A" require: "tabset" link: (scope, el, attrs, tabset) -> - scope.$applyAsync () -> - hash = $location.hash() + linksToTabs = document.querySelectorAll(".link-to-tab"); + _clickLinkToTab = (event) -> + _makeActive(event.currentTarget.getAttribute("href").replace('#', '')) + + _makeActive = (hash) -> if hash? and hash != "" matchingTab = _.find tabset.tabs, (tab) -> tab.bookmarkableTabId == hash @@ -14,6 +17,14 @@ define [ matchingTab.select() el.children()[0].scrollIntoView({ behavior: "smooth" }) + for link in linksToTabs + link.addEventListener("click", _clickLinkToTab) + + scope.$applyAsync () -> + # for page load + hash = $location.hash() + _makeActive(hash) + App.directive "bookmarkableTab", ($location) -> restrict: "A" require: "tab" @@ -25,6 +36,3 @@ define [ tabScope.$watch "active", (isActive, wasActive) -> if isActive and !wasActive and $location.hash() != tabId $location.hash tabId - - -