-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.js
134 lines (111 loc) · 4.21 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
var Expander = require('makeup-expander');
function nodeListToArray(nodeList) {
return Array.prototype.slice.call(nodeList);
}
function querySelectorAllToArray(selector, parentNode) {
parentNode = parentNode || document;
return nodeListToArray(parentNode.querySelectorAll(selector));
}
window.onload = function(e) {
/* STEP: ENHANCED SKIP-TO LINK */
querySelectorAllToArray('.skipto').forEach(function(el, i) {
el.addEventListener('click', function() {
var targetEl = document.querySelector(el.querySelector('a').getAttribute('href'));
targetEl.setAttribute('tabindex', '-1');
targetEl.focus();
});
});
/* STEP: PAGE ERROR */
var pageError = document.getElementById('page-error');
if (pageError) {
pageError.setAttribute('tabindex', '-1');
pageError.focus();
}
/* STEP: DYNAMIC FIELD ERROR */
querySelectorAllToArray('.field-validation input').forEach(function(item) {
var statusText = document.querySelector('#' + item.getAttribute('aria-describedby') + ' span');
item.addEventListener('blur', function(e) {
if (this.value) {
statusText.removeAttribute('hidden');
} else {
statusText.setAttribute('hidden', 'hidden');
}
})
});
/* STEP: DYNAMIC PAGE ERROR */
var regForm = document.getElementById('reg-form');
if (regForm) {
var placeholderEl = document.getElementById('page-error-placeholder');
var pageErrorTemplate = '' +
'<section aria-labelledby="attention-status" class="page-notice page-notice--attention" id="page-error" role="region" tabindex="-1">' +
'<h2 class="page-notice__status" id="attention-status">' +
'<span aria-label="Attention" role="img"></span>' +
'</h2>' +
'<div class="page-notice__content">' +
'<p>Please fix the following errors:</p>' +
'<ul role="list">' +
'<li><a href="#fname">First Name: please enter your first name</a></li>' +
'<li><a href="#lname">Last Name: please enter your last name</a></li>' +
'</ul>' +
'</div>' +
'</section>';
regForm.addEventListener('submit', function(e) {
e.preventDefault();
placeholderEl.innerHTML = pageErrorTemplate;
placeholderEl.focus();
});
}
/* STEP: CRITICAL ICON */
/* STEP: BUTTON FLYOUT */
querySelectorAllToArray('.expander--click').forEach(function(el, i) {
const widget = new Expander(el, {
collapseOnClickOut: true,
collapseOnFocusOut: true,
expandedClass: 'expander--expanded',
expandOnClick: true,
focusManagement: 'interactive'
});
});
/* STEP: LINK FLYOUT */
querySelectorAllToArray('.expander--hover').forEach(function(el, i) {
const widget = new Expander(el, {
collapseOnMouseOut: true,
expandedClass: 'expander--expanded',
expandOnHover: true
});
});
/* STEP: TOOLTIP */
querySelectorAllToArray('.expander--hover-and-focus').forEach(function(el, i) {
const widget = new Expander(el, {
collapseOnFocusOut: true,
collapseOnMouseOut: true,
expandedClass: 'expander--expanded',
expandOnFocus: true,
expandOnHover: true
});
});
}
/* jQuery Plugins
$(function() {
/* SKIP TO ENHANCED
$('.skipto').skipTo();
/* BUTTON FLYOUT
$('.flyout--click').clickFlyout({focusManagement:'first', closeOnEsc: true});
/* CLICK FLYOUT + HOVER
$('.flyout--hover').hoverFlyout();
/* TOOLTIP
$('.tooltip').tooltip();
/* FAKE MENU
$('.fake-menu').clickFlyout({focusManagement:'first', closeOnEsc: true});
/* MENU
$('.menu').menu().on('menuSelect', '[role=menuitem]', function(e, data) {
alert($(this).text());
});
/*
$('.hijax-form').on('submit', function(e) {
e.preventDefault();
$('.result-status').html('<p>1 result found</p>');
$('main ol').empty().append('<li><a href="http://www.ebay.com">Item 1</a></li>');
});
});
*/