Skip to content
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

Implement ES6 modules JavaScript with webpack #258

Merged
merged 26 commits into from
Dec 17, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d478815
[refs #96] Implement ES6 modules JavaScript with webpack
chrimesdev Nov 27, 2018
4590f4a
[refs #96] Use eslint with the shared NHS.UK config
chrimesdev Nov 27, 2018
506b517
[refs #96] Use gulp to build our Javascript with webpack
chrimesdev Nov 28, 2018
4cf4ab6
[refs #107] Fix a typo in the feedback banner example
chrimesdev Nov 28, 2018
10cc83a
[refs #96] Refactor feedback banner JS to an ES6 module
chrimesdev Nov 28, 2018
67743a1
[refs #96] Refactor skip link JS to an ES6 module
chrimesdev Nov 28, 2018
5781149
[refs #96] Refactor header JS to an ES6 module
chrimesdev Nov 28, 2018
30dfb9b
[refs #96] Tidy up gulp tasks for bundling JavaScript
chrimesdev Nov 29, 2018
e55af5a
[refs #96] Move eslint config file and run linters on test
chrimesdev Nov 29, 2018
1b381a3
[refs #107] Use htmlhint to lint HTML and fix issues
chrimesdev Nov 29, 2018
905e739
Merge branch 'master' into feature/es6-webpack
chrimesdev Dec 3, 2018
848544b
Merge branch 'master' into feature/es6-webpack
chrimesdev Dec 5, 2018
8343aa8
[refs #96] Refactor unsticky feedback banner JS to ES6
chrimesdev Dec 5, 2018
e7eaf83
[refs #96] Use babel preset in webpack for IE10> polyfill
chrimesdev Dec 5, 2018
e6a6e86
[refs #96] Check banner element exists before eventListener
chrimesdev Dec 5, 2018
f02cb5c
[refs #96] Include the missing details.js file
chrimesdev Dec 5, 2018
d8a2d6e
Merge branch 'master' into feature/es6-webpack
chrimesdev Dec 12, 2018
2e6f9e9
[refs #96] Prefix JavaScript modules with nhsuk_
chrimesdev Dec 12, 2018
288f4a7
[refs #96] Include details polyfill via modules
chrimesdev Dec 12, 2018
1fb4459
[refs #96] Minify JavaScript ES6 bundle for npm installations
chrimesdev Dec 17, 2018
5858b13
Merge branch 'master' into feature/es6-webpack
chrimesdev Dec 17, 2018
c0dfc96
[refs #96] Compile the JavaScript to dist instead of packages
chrimesdev Dec 17, 2018
cf0e7a5
[refs #96] ES6 JavaScript install docs and delete specific tools exam…
chrimesdev Dec 17, 2018
af95188
[refs #96] ignore the versioned assets for npm packages
chrimesdev Dec 17, 2018
1d079e8
[refs #96] Fix skip-link js and use DOMContentLoaded
mcheung-nhs Dec 17, 2018
3ecd825
[refs #96] Fix JS eslint issues for arrow functions
chrimesdev Dec 17, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[refs #96] Refactor skip link JS to an ES6 module
Refactor the skip link JavaScript so that it can be imported
as a module, using ES6 syntax.
  • Loading branch information
chrimesdev committed Nov 29, 2018
commit 67743a1fcb96cb8811d4e9307db30208615f4fe8
1 change: 0 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ function compileJS() {
'packages/components/header/typeahead.bundle.min.js',
'packages/components/header/nhs.typeahead.js',
'packages/components/header/header.js',
'packages/components/skip-link/skip-link.js'
])
.pipe(concat('nhsuk.js'))
.pipe(gulp.dest('dist/'));
Expand Down
70 changes: 36 additions & 34 deletions packages/components/skip-link/skip-link.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
// When using VoiceOver on iOS, focus remains on the skip link anchor when
// selected so the next focusable element is not at the jumped to area.
// This Javascript hack focuses on the first H1 header (if one exists, which it
// should) by adding tabindex = -1 to it and then removes it when focus is
// off it.

document.addEventListener('DOMContentLoaded', function() {

var skip = {

link: document.querySelector('.nhsuk-skip-link'),
header: document.getElementsByTagName('H1')[0],

doFocus: function(e) {
this.header.setAttribute('tabIndex', '-1');
this.header.focus();
},

doLeave: function(e) {
this.header.removeAttribute('tabIndex');
}

/*
* Skip link
*
* When using VoiceOver on iOS, focus remains on the skip link anchor
* when elected so the next focusable element is not at the jumped to area.
* This Javascript hack focuses on the first page <h1> element
* (if one exists, which it should) by adding tabindex = -1 to it and
* then removes it when focus is off it.
*/

const skipLinkElement = document.querySelector('.nhsuk-skip-link');
const headingElement = document.getElementsByTagName('H1')[0];

function addFocus() {
headingElement.setAttribute('tabIndex', '-1');
headingElement.focus();
}

function removeFocus() {
headingElement.removeAttribute('tabIndex');
}

function handleSkipLink() {
if (skipLinkElement && headingElement) {
skipLinkElement.addEventListener('click', addFocus);
}
}

if (skip.link && skip.header) {

skip.link.addEventListener('click', function(e) {
e.preventDefault();
skip.doFocus(e);
});

skip.header.addEventListener('blur', function(e) {
skip.doLeave(e);
});

function handleHeader() {
if (skipLinkElement && headingElement) {
headingElement.addEventListener('blur', removeFocus);
}
}

function skipLink() {
handleSkipLink();
handleHeader();
}

})
export default skipLink;
4 changes: 4 additions & 0 deletions packages/nhsuk.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Component imports
import feedbackBanner from './components/feedback-banner/feedback-banner';
import skipLink from './components/skip-link/skip-link';

// Initialize components
feedbackBanner(3000);
skipLink();