-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1103 from alphagov/refactor-how-we-calculate-link…
…s-and-sections Refactor how we calculate section and link counts
- Loading branch information
Showing
4 changed files
with
204 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
(function () { | ||
"use strict"; | ||
window.GOVUK = window.GOVUK || {}; | ||
var PageContent = function () { } | ||
|
||
PageContent.getNumberOfSections = function () { | ||
switch(true) { | ||
case isNavigationGridPage(): | ||
return $('a[data-track-category="navGridLinkClicked"]').length; | ||
case isNavigationAccordionPage(): | ||
return $('[data-track-count="accordionSection"]').length; | ||
case isDocumentCollectionPage(): | ||
return $('.document-collection .group-title').length; | ||
case isMainstreamBrowsePage(): | ||
return $('#subsection ul:visible').length || $('#section ul').length; | ||
case isTopicPage(): | ||
return $('.topics-page nav.index-list').length; | ||
case isPolicyAreaPage(): | ||
return $('.topic section h1.label').length; | ||
default: | ||
// It's a content page, not a "finding" page | ||
var sidebarSections = $('[data-track-count="sidebarRelatedItemSection"]').length; | ||
var sidebarTaxons = $('[data-track-count="sidebarTaxonSection"]').length; | ||
|
||
return sidebarSections || sidebarTaxons; | ||
} | ||
}; | ||
|
||
PageContent.getNumberOfLinks = function () { | ||
switch(true) { | ||
case isNavigationGridPage(): | ||
return $('a[data-track-category="navGridLinkClicked"]').length | ||
+ $('a[data-track-category="navGridLeafLinkClicked"]').length; | ||
case isNavigationAccordionPage(): | ||
return $('a[data-track-category="navAccordionLinkClicked"]').length; | ||
case isNavigationLeafPage(): | ||
return $('a[data-track-category="navLeafLinkClicked"]').length; | ||
case isDocumentCollectionPage(): | ||
return $('.document-collection .group-document-list li a').length; | ||
case isMainstreamBrowsePage(): | ||
return $('#subsection ul a:visible').length || | ||
$('#section ul a').length; | ||
case isTopicPage(): | ||
return $('.topics-page .index-list ul a').length || | ||
$('.topics-page .topics ul a').length; | ||
case isPolicyAreaPage(): | ||
return $('section.document-block a').length + | ||
$('section .collection-list h2 a').length; | ||
case isWhitehallFinderPage(): | ||
return $('.document-list .document-row h3 a').length; | ||
case isFinderPage(): | ||
return $('.finder-frontend-content li.document a').length; | ||
default: | ||
// It's a content page, not a "finding" page, count related links | ||
return $('a[data-track-category="relatedLinkClicked"]').length; | ||
} | ||
}; | ||
|
||
function getRenderingApplication () { | ||
return $('meta[name="govuk:rendering-application"]').attr('content'); | ||
}; | ||
|
||
function getFormat () { | ||
return $('meta[name="govuk:format"]').attr('content'); | ||
}; | ||
|
||
function getNavigationPageType () { | ||
return $('meta[name="govuk:navigation-page-type"]').attr('content'); | ||
}; | ||
|
||
function isNavigationGridPage () { | ||
return getRenderingApplication() == 'collections' && | ||
getFormat() == 'taxon' && | ||
getNavigationPageType() == 'grid'; | ||
}; | ||
|
||
function isNavigationAccordionPage () { | ||
return getRenderingApplication() == 'collections' && | ||
getFormat() == 'taxon' && | ||
getNavigationPageType() == 'accordion'; | ||
}; | ||
|
||
function isNavigationLeafPage () { | ||
return getRenderingApplication() == 'collections' && | ||
getFormat() == 'taxon' && | ||
getNavigationPageType() == 'leaf'; | ||
}; | ||
|
||
function isMainstreamBrowsePage () { | ||
return getRenderingApplication() == 'collections' && | ||
getFormat() == 'mainstream_browse_page' | ||
}; | ||
|
||
function isTopicPage () { | ||
return getRenderingApplication() == 'collections' && | ||
getFormat() == 'topic' | ||
}; | ||
|
||
function isPolicyAreaPage () { | ||
return getRenderingApplication() == 'whitehall' && | ||
getFormat() == 'placeholder_policy_area' | ||
}; | ||
|
||
function isDocumentCollectionPage () { | ||
return getRenderingApplication() == 'government-frontend' && | ||
getFormat() == 'document_collection' | ||
}; | ||
|
||
function isFinderPage () { | ||
return getRenderingApplication() == 'finder-frontend' && | ||
getFormat() == 'finder' | ||
}; | ||
|
||
function isWhitehallFinderPage () { | ||
return getRenderingApplication() == 'whitehall' && | ||
getFormat() == 'finder' | ||
}; | ||
|
||
GOVUK.PageContent = PageContent; | ||
})(); |
Oops, something went wrong.