-
Notifications
You must be signed in to change notification settings - Fork 8
Skip nav #113
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use strict'; | ||
|
||
/* global require, module, document */ | ||
|
||
var $ = require('jquery'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redefinition of '$'. |
||
|
||
/** | ||
* Skip nav link | ||
* @constructor | ||
* @param {string} anchor - CSS selector for the anchor element that will function as the skip nav | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. |
||
* @param {string} targetBody - CSS selector for the main content area to look for a focusable element in | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. |
||
*/ | ||
|
||
function Skipnav(anchor, targetBody) { | ||
this.anchor = anchor; | ||
this.$targetBody = $(targetBody); | ||
this.$target = this.findTarget(); | ||
$(document.body).on('click keyup', this.anchor, this.focusOnTarget.bind(this)); | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unnecessary semicolon. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unnecessary semicolon. |
||
|
||
Skipnav.prototype.findTarget = function() { | ||
return this.$targetBody.find('a, button, :input, [tabindex]').filter(':visible')[0]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. |
||
}; | ||
|
||
Skipnav.prototype.focusOnTarget = function(e) { | ||
if (e.keyCode === 13 || e.type === 'click') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this focus on the target element every time the user clicks anywhere in the body? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was trying to do event delegation. I tweaked it so that the second parameter is the selector for the anchor element. |
||
this.$target.focus(); | ||
} | ||
}; | ||
|
||
module.exports = {Skipnav: Skipnav}; |
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.
Use the function form of "use strict".