-
Notifications
You must be signed in to change notification settings - Fork 278
/
Copy pathindex.js
88 lines (71 loc) · 2.29 KB
/
index.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
/**
* The entry point for tota11y.
*
* Builds and mounts the toolbar.
*/
// Require the base tota11y styles right away so they can be overwritten
require("./less/tota11y.less");
let $ = require("jquery");
let plugins = require("./plugins");
let logoTemplate = require("./templates/logo.handlebars");
// Chrome Accessibility Developer Tools - required once as a global
require("script!./node_modules/accessibility-developer-tools/dist/js/axs_testing.js");
class Toolbar {
appendTo($el) {
let $logo = $(logoTemplate());
let $toolbar;
let activePlugin = null;
let handlePluginClick = (plugin) => {
if (plugin === activePlugin) {
plugin.cleanup();
plugin.panel.destroy();
plugin.$checkbox.attr("checked", false);
activePlugin = null;
} else {
if (activePlugin) {
activePlugin.cleanup();
activePlugin.panel.destroy();
activePlugin.$checkbox.attr("checked", false);
}
plugin.run();
plugin.panel.render();
activePlugin = plugin;
}
};
let $plugins = (
<div className="tota11y-plugins">
{plugins.map((plugin) => plugin.render(handlePluginClick))}
</div>
);
let handleToggleClick = (e) => {
e.preventDefault();
e.stopPropagation();
$toolbar.toggleClass("tota11y-expanded");
};
let $toggle = (
<a href="#"
className="tota11y-toolbar-toggle"
onClick={handleToggleClick}>
<div className="tota11y-toolbar-logo">
{$logo}
</div>
</a>
);
$toolbar = (
<div className="tota11y tota11y-toolbar">
<div className="tota11y-toolbar-body">
{$plugins}
</div>
{$toggle}
</div>
);
$el.append($toolbar);
}
}
$(function() {
// Attach the global `axs` object from Accessibility Developer Tools to $
$.axs = axs;
var bar = new Toolbar();
// TODO: Make this customizable
bar.appendTo($("body"));
});