Skip to content

Commit

Permalink
Merge pull request #2 from a11ydoer/menubarexample
Browse files Browse the repository at this point in the history
fix jscs errors and one copyright info
  • Loading branch information
a11ydoer authored Oct 30, 2016
2 parents 2e94d93 + f775f78 commit 45ed705
Show file tree
Hide file tree
Showing 9 changed files with 294 additions and 247 deletions.
3 changes: 0 additions & 3 deletions examples/menubar/menubar-1/js/.jscsrc

This file was deleted.

120 changes: 60 additions & 60 deletions examples/menubar/menubar-1/js/MenuItemLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,101 +24,101 @@
* The object that is a wrapper for the PopupMenu DOM element that
* contains the menu item DOM element. See PopupMenu.js
*/
var MenuItem = function( domNode, menuObj ) {
var MenuItem = function (domNode, menuObj) {

this.domNode = domNode;
this.menu = menuObj;

this.keyCode = Object.freeze( {
"TAB": 9,
"RETURN": 13,
"ESC": 27,
"SPACE": 32,
"PAGEUP": 33,
"PAGEDOWN": 34,
"END": 35,
"HOME": 36,
"LEFT": 37,
"UP": 38,
"RIGHT": 39,
"DOWN": 40
} );
this.keyCode = Object.freeze({
'TAB': 9,
'RETURN': 13,
'ESC': 27,
'SPACE': 32,
'PAGEUP': 33,
'PAGEDOWN': 34,
'END': 35,
'HOME': 36,
'LEFT': 37,
'UP': 38,
'RIGHT': 39,
'DOWN': 40
});
};

MenuItem.prototype.init = function() {
MenuItem.prototype.init = function () {
this.domNode.tabIndex = -1;

if ( !this.domNode.getAttribute( "role" ) ) {
this.domNode.setAttribute( "role", "menuitem" );
if (!this.domNode.getAttribute('role')) {
this.domNode.setAttribute('role', 'menuitem');
}

this.domNode.addEventListener( "keydown", this.handleKeydown.bind( this ) );
this.domNode.addEventListener( "keypress", this.handleKeypress.bind( this ) );
this.domNode.addEventListener( "click", this.handleClick.bind( this ) );
this.domNode.addEventListener( "focus", this.handleFocus.bind( this ) );
this.domNode.addEventListener( "blur", this.handleBlur.bind( this ) );
this.domNode.addEventListener( "mouseover", this.handleMouseover.bind( this ) );
this.domNode.addEventListener( "mouseout", this.handleMouseout.bind( this ) );
this.domNode.addEventListener('keydown', this.handleKeydown.bind(this));
this.domNode.addEventListener('keypress', this.handleKeypress.bind(this));
this.domNode.addEventListener('click', this.handleClick.bind(this));
this.domNode.addEventListener('focus', this.handleFocus.bind(this));
this.domNode.addEventListener('blur', this.handleBlur.bind(this));
this.domNode.addEventListener('mouseover', this.handleMouseover.bind(this));
this.domNode.addEventListener('mouseout', this.handleMouseout.bind(this));

};

/* EVENT HANDLERS */

MenuItem.prototype.handleKeydown = function( event ) {
MenuItem.prototype.handleKeydown = function (event) {
var tgt = event.currentTarget,
flag = false,
clickEvent;

// Console.log("[MenuItem][handleKeydown]: " + event.keyCode + " " + this.menu)

switch ( event.keyCode ) {
switch (event.keyCode) {
case this.keyCode.SPACE:
case this.keyCode.RETURN:
// Create simulated mouse event to mimic the behavior of ATs
// and let the event handler handleClick do the housekeeping.
try {
clickEvent = new MouseEvent( "click", {
"view": window,
"bubbles": true,
"cancelable": true
} );
clickEvent = new MouseEvent('click', {
'view': window,
'bubbles': true,
'cancelable': true
});
}
catch ( err ) {
if ( document.createEvent ) {
catch (err) {
if (document.createEvent) {
// DOM Level 3 for IE 9+
clickEvent = document.createEvent( "MouseEvents" );
clickEvent.initEvent( "click", true, true );
clickEvent = document.createEvent('MouseEvents');
clickEvent.initEvent('click', true, true);
}
}
tgt.dispatchEvent( clickEvent );
tgt.dispatchEvent(clickEvent);
flag = true;
break;

case this.keyCode.ESC:
this.menu.setFocusToController();
this.menu.close( true );
this.menu.close(true);
flag = true;
break;

case this.keyCode.UP:
this.menu.setFocusToPreviousItem( this );
this.menu.setFocusToPreviousItem(this);
flag = true;
break;

case this.keyCode.DOWN:
this.menu.setFocusToNextItem( this );
this.menu.setFocusToNextItem(this);
flag = true;
break;

case this.keyCode.LEFT:
this.menu.setFocusToController( "previous" );
this.menu.close( true );
this.menu.setFocusToController('previous');
this.menu.close(true);
flag = true;
break;

case this.keyCode.RIGHT:
this.menu.setFocusToController( "next" );
this.menu.close( true );
this.menu.setFocusToController('next');
this.menu.close(true);
flag = true;
break;

Expand All @@ -136,52 +136,52 @@ MenuItem.prototype.handleKeydown = function( event ) {

case this.keyCode.TAB:
this.menu.setFocusToController();
this.menu.close( true );
this.menu.close(true);
break;

default:
break;
}

if ( flag ) {
if (flag) {
event.stopPropagation();
event.preventDefault();
}
};

MenuItem.prototype.handleKeypress = function( event ) {
var char = String.fromCharCode( event.charCode );
MenuItem.prototype.handleKeypress = function (event) {
var char = String.fromCharCode(event.charCode);

function isPrintableCharacter ( str ) {
return str.length === 1 && str.match( /\S/ );
function isPrintableCharacter (str) {
return str.length === 1 && str.match(/\S/);
}

if ( isPrintableCharacter( char ) ) {
this.menu.setFocusByFirstCharacter( this, char );
if (isPrintableCharacter(char)) {
this.menu.setFocusByFirstCharacter(this, char);
}
};

MenuItem.prototype.handleClick = function( event ) {
MenuItem.prototype.handleClick = function (event) {
this.menu.setFocusToController();
this.menu.close( true );
this.menu.close(true);
};

MenuItem.prototype.handleFocus = function( event ) {
MenuItem.prototype.handleFocus = function (event) {
this.menu.hasFocus = true;
};

MenuItem.prototype.handleBlur = function( event ) {
MenuItem.prototype.handleBlur = function (event) {
this.menu.hasFocus = false;
setTimeout( this.menu.close.bind( this.menu, false ), 300 );
setTimeout(this.menu.close.bind(this.menu, false), 300);
};

MenuItem.prototype.handleMouseover = function( event ) {
MenuItem.prototype.handleMouseover = function (event) {
this.menu.hasHover = true;
this.menu.open();

};

MenuItem.prototype.handleMouseout = function( event ) {
MenuItem.prototype.handleMouseout = function (event) {
this.menu.hasHover = false;
setTimeout( this.menu.close.bind( this.menu, false ), 300 );
setTimeout(this.menu.close.bind(this.menu, false), 300);
};
17 changes: 3 additions & 14 deletions examples/menubar/menubar-1/js/MenubarItemLinks.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
/*
* Copyright 2016 University of Illinois
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* This content is licensed according to the W3C Software License at
* https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
*
* File: MenubarItemLinks.js
*
Expand Down Expand Up @@ -85,7 +74,7 @@ MenubarItem.prototype.init = function () {
this.domNode.addEventListener('mouseover', this.handleMouseover.bind(this));
this.domNode.addEventListener('mouseout', this.handleMouseout.bind(this));

// initialize pop up menus
// Initialize pop up menus

var nextElement = this.domNode.nextElementSibling;

Expand Down
Loading

0 comments on commit 45ed705

Please sign in to comment.