-
Notifications
You must be signed in to change notification settings - Fork 278
/
Copy pathindex.js
94 lines (79 loc) · 2.57 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
89
90
91
92
93
94
/**
* 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 {
/**
* Renders the toolbar and appends it the specified element.
*/
appendTo($el) {
let $logo = $(logoTemplate());
let $toolbar;
// Manages the state of the toolbar when a plugin is clicked, and
// toggles the appropriate plugins
let activePlugin = null;
let handlePluginClick = (plugin) => {
// If the plugin was already selected, toggle it off
if (plugin === activePlugin) {
plugin.deactivate();
activePlugin = null;
} else {
// Deactivate the active plugin if there is one
if (activePlugin) {
activePlugin.deactivate();
}
// Activate the selected plugin
plugin.activate();
activePlugin = plugin;
}
};
let $plugins = (
<div className="tota11y-plugins">
{
plugins.map((plugin) => {
// Render each plugin with the click handler
return 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"));
});