-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor how we calculate section and link counts #1103
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason for this specific order that might not be obvious to the next person to touch this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question. Before, the order was important because of document collections. They are both navigation pages and content pages, so the return statement needed a specific order. But with this
switch
statement, we look for navigation pages first (and they are findable in a deterministic way now since alphagov/whitehall#3358), and default to a content page at the bottom. That means we don't rely on ordering anymore.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍