Skip to content
This repository has been archived by the owner on Dec 3, 2017. It is now read-only.

Skip nav #113

Merged
merged 5 commits into from
Sep 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion js/dropdowns.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Dropdown.prototype.handleClickAway = function(e) {
};

Dropdown.prototype.handleFocusAway = function(e) {
var $target = $(e.relatedTarget);
var $target = $(e.target);
if (this.isOpen && !this.$panel.has($target).length) {
this.hide();
}
Expand Down
31 changes: 31 additions & 0 deletions js/skip-nav.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';

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".


/* global require, module, document */

var $ = require('jquery');

Choose a reason for hiding this comment

The 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

Choose a reason for hiding this comment

The 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

Choose a reason for hiding this comment

The 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));
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary semicolon.

Choose a reason for hiding this comment

The 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];

Choose a reason for hiding this comment

The 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') {
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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};