-
Notifications
You must be signed in to change notification settings - Fork 236
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run standard --fix for Standard JS linting
This commit can be removed later as these files have already been linted on master, but it may well help with the rebase. I’ve made a start on linting here, to continue with linting run `npm test`, there are still errors in server.js. utils.js and documentation_routes.js.
- Loading branch information
1 parent
430d058
commit c340308
Showing
13 changed files
with
460 additions
and
498 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,127 +1,124 @@ | ||
function ShowHideContent() { | ||
var self = this; | ||
/* global $ */ | ||
/* global jQuery */ | ||
/* global GOVUK */ | ||
|
||
self.escapeElementName = function(str) { | ||
result = str.replace('[', '\\[').replace(']', '\\]') | ||
return(result); | ||
}; | ||
function ShowHideContent () { | ||
var self = this | ||
|
||
self.escapeElementName = function (str) { | ||
var result = str.replace('[', '\\[').replace(']', '\\]') | ||
return (result) | ||
} | ||
|
||
self.showHideRadioToggledContent = function () { | ||
$(".block-label input[type='radio']").each(function () { | ||
var $radio = $(this) | ||
var $radioGroupName = $radio.attr('name') | ||
var $radioLabel = $radio.parent('label') | ||
|
||
var $radio = $(this); | ||
var $radioGroupName = $radio.attr('name'); | ||
var $radioLabel = $radio.parent('label'); | ||
|
||
var dataTarget = $radioLabel.attr('data-target'); | ||
var dataTarget = $radioLabel.attr('data-target') | ||
|
||
// Add ARIA attributes | ||
|
||
// If the data-target attribute is defined | ||
if (dataTarget) { | ||
|
||
// Set aria-controls | ||
$radio.attr('aria-controls', dataTarget); | ||
$radio.attr('aria-controls', dataTarget) | ||
|
||
$radio.on('click', function () { | ||
|
||
// Select radio buttons in the same group | ||
$radio.closest('form').find(".block-label input[name=" + self.escapeElementName($radioGroupName) + "]").each(function () { | ||
var $this = $(this); | ||
$radio.closest('form').find('.block-label input[name=' + self.escapeElementName($radioGroupName) + ']').each(function () { | ||
var $this = $(this) | ||
|
||
var groupDataTarget = $this.parent('label').attr('data-target'); | ||
var $groupDataTarget = $('#' + groupDataTarget); | ||
var groupDataTarget = $this.parent('label').attr('data-target') | ||
var $groupDataTarget = $('#' + groupDataTarget) | ||
|
||
// Hide toggled content | ||
$groupDataTarget.addClass('js-hidden'); | ||
$groupDataTarget.addClass('js-hidden') | ||
// Set aria-expanded and aria-hidden for hidden content | ||
$this.attr('aria-expanded', 'false'); | ||
$groupDataTarget.attr('aria-hidden', 'true'); | ||
}); | ||
$this.attr('aria-expanded', 'false') | ||
$groupDataTarget.attr('aria-hidden', 'true') | ||
}) | ||
|
||
var $dataTarget = $('#' + dataTarget); | ||
$dataTarget.removeClass('js-hidden'); | ||
var $dataTarget = $('#' + dataTarget) | ||
$dataTarget.removeClass('js-hidden') | ||
// Set aria-expanded and aria-hidden for clicked radio | ||
$radio.attr('aria-expanded', 'true'); | ||
$dataTarget.attr('aria-hidden', 'false'); | ||
|
||
}); | ||
|
||
$radio.attr('aria-expanded', 'true') | ||
$dataTarget.attr('aria-hidden', 'false') | ||
}) | ||
} else { | ||
// If the data-target attribute is undefined for a radio button, | ||
// hide visible data-target content for radio buttons in the same group | ||
|
||
$radio.on('click', function () { | ||
|
||
// Select radio buttons in the same group | ||
$(".block-label input[name=" + self.escapeElementName($radioGroupName) + "]").each(function () { | ||
|
||
var groupDataTarget = $(this).parent('label').attr('data-target'); | ||
var $groupDataTarget = $('#' + groupDataTarget); | ||
$('.block-label input[name=' + self.escapeElementName($radioGroupName) + ']').each(function () { | ||
var groupDataTarget = $(this).parent('label').attr('data-target') | ||
var $groupDataTarget = $('#' + groupDataTarget) | ||
|
||
// Hide toggled content | ||
$groupDataTarget.addClass('js-hidden'); | ||
$groupDataTarget.addClass('js-hidden') | ||
// Set aria-expanded and aria-hidden for hidden content | ||
$(this).attr('aria-expanded', 'false'); | ||
$groupDataTarget.attr('aria-hidden', 'true'); | ||
}); | ||
|
||
}); | ||
$(this).attr('aria-expanded', 'false') | ||
$groupDataTarget.attr('aria-hidden', 'true') | ||
}) | ||
}) | ||
} | ||
|
||
}); | ||
}) | ||
} | ||
self.showHideCheckboxToggledContent = function () { | ||
$(".block-label input[type='checkbox']").each(function () { | ||
var $checkbox = $(this) | ||
var $checkboxLabel = $(this).parent() | ||
|
||
$(".block-label input[type='checkbox']").each(function() { | ||
|
||
var $checkbox = $(this); | ||
var $checkboxLabel = $(this).parent(); | ||
|
||
var $dataTarget = $checkboxLabel.attr('data-target'); | ||
var $dataTarget = $checkboxLabel.attr('data-target') | ||
|
||
// Add ARIA attributes | ||
|
||
// If the data-target attribute is defined | ||
if (typeof $dataTarget !== 'undefined' && $dataTarget !== false) { | ||
|
||
// Set aria-controls | ||
$checkbox.attr('aria-controls', $dataTarget); | ||
$checkbox.attr('aria-controls', $dataTarget) | ||
|
||
// Set aria-expanded and aria-hidden | ||
$checkbox.attr('aria-expanded', 'false'); | ||
$('#'+$dataTarget).attr('aria-hidden', 'true'); | ||
$checkbox.attr('aria-expanded', 'false') | ||
$('#' + $dataTarget).attr('aria-hidden', 'true') | ||
|
||
// For checkboxes revealing hidden content | ||
$checkbox.on('click', function() { | ||
|
||
var state = $(this).attr('aria-expanded') === 'false' ? true : false; | ||
$checkbox.on('click', function () { | ||
var state = $(this).attr('aria-expanded') === 'false' | ||
|
||
// Toggle hidden content | ||
$('#'+$dataTarget).toggleClass('js-hidden'); | ||
$('#' + $dataTarget).toggleClass('js-hidden') | ||
|
||
// Update aria-expanded and aria-hidden attributes | ||
$(this).attr('aria-expanded', state); | ||
$('#'+$dataTarget).attr('aria-hidden', !state); | ||
|
||
}); | ||
$(this).attr('aria-expanded', state) | ||
$('#' + $dataTarget).attr('aria-hidden', !state) | ||
}) | ||
} | ||
|
||
}); | ||
}) | ||
} | ||
} | ||
|
||
$(document).ready(function() { | ||
$(document).ready(function () { | ||
// Turn off jQuery animation | ||
jQuery.fx.off = true | ||
|
||
// Use GOV.UK selection-buttons.js to set selected | ||
// and focused states for block labels | ||
var $blockLabels = $(".block-label input[type='radio'], .block-label input[type='checkbox']"); | ||
new GOVUK.SelectionButtons($blockLabels); | ||
var $blockLabels = $(".block-label input[type='radio'], .block-label input[type='checkbox']") | ||
new GOVUK.SelectionButtons($blockLabels) // eslint-disable-line | ||
|
||
// Show and hide toggled content | ||
// Where .block-label uses the data-target attribute | ||
var toggleContent = new ShowHideContent(); | ||
toggleContent.showHideRadioToggledContent(); | ||
toggleContent.showHideCheckboxToggledContent(); | ||
// Use GOV.UK shim-links-with-button-role.js to trigger a link styled to look like a button, | ||
// with role="button" when the space key is pressed. | ||
GOVUK.shimLinksWithButtonRole.init() | ||
|
||
}); | ||
// Details/summary polyfill | ||
// See /javascripts/vendor/details.polyfill.js | ||
|
||
// Where .block-label uses the data-target attribute | ||
// to toggle hidden content | ||
var toggleContent = new ShowHideContent() | ||
toggleContent.showHideRadioToggledContent() | ||
toggleContent.showHideCheckboxToggledContent() | ||
}) |
Oops, something went wrong.