forked from w3c/aria-practices
-
Notifications
You must be signed in to change notification settings - Fork 0
/
listbox-rearrangeable.js
71 lines (63 loc) · 2.55 KB
/
listbox-rearrangeable.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
/*
* This content is licensed according to the W3C Software License at
* https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
*/
/**
* ARIA Listbox Examples
* @function onload
* @desc Initialize the listbox examples once the page has loaded
*/
window.addEventListener('load', function () {
var ex1 = document.getElementById('ex1');
var ex1ImportantListbox = new aria.Listbox(document.getElementById('ss_imp_list'));
var ex1Toolbar = new aria.Toolbar(ex1.querySelector('[role="toolbar"]'));
var ex1UnimportantListbox = new aria.Listbox(document.getElementById('ss_unimp_list'));
ex1ImportantListbox.enableMoveUpDown(
document.getElementById('ex1-up'),
document.getElementById('ex1-down')
);
ex1ImportantListbox.setupMove(document.getElementById('ex1-delete'), ex1UnimportantListbox);
ex1ImportantListbox.setHandleItemChange(function (event, items) {
var updateText = '';
switch (event) {
case 'added':
updateText = 'Moved ' + items[0].innerText + ' to important features.';
break;
case 'removed':
updateText = 'Moved ' + items[0].innerText + ' to unimportant features.';
break;
case 'moved_up':
case 'moved_down':
var pos = Array.prototype.indexOf.call(this.listboxNode.children, items[0]);
pos++;
updateText = 'Moved to position ' + pos;
break;
}
if (updateText) {
var ex1LiveRegion = document.getElementById('ss_live_region');
ex1LiveRegion.innerText = updateText;
}
});
ex1UnimportantListbox.setupMove(document.getElementById('ex1-add'), ex1ImportantListbox);
var ex2 = document.getElementById('ex2');
var ex2ImportantListbox = new aria.Listbox(document.getElementById('ms_imp_list'));
var ex2UnimportantListbox = new aria.Listbox(document.getElementById('ms_unimp_list'));
ex2ImportantListbox.setupMove(document.getElementById('ex2-add'), ex2UnimportantListbox);
ex2UnimportantListbox.setupMove(document.getElementById('ex2-delete'), ex2ImportantListbox);
ex2UnimportantListbox.setHandleItemChange(function (event, items) {
var updateText = '';
var itemText = items.length === 1 ? '1 item' : items.length + ' items';
switch (event) {
case 'added':
updateText = 'Added ' + itemText + ' to chosen features.';
break;
case 'removed':
updateText = 'Removed ' + itemText + ' from chosen features.';
break;
}
if (updateText) {
var ex1LiveRegion = document.getElementById('ms_live_region');
ex1LiveRegion.innerText = updateText;
}
});
});