-
Notifications
You must be signed in to change notification settings - Fork 278
/
Copy pathindex.js
118 lines (100 loc) · 3.28 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/**
* 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 {
constructor() {
this.activePlugin = null;
}
/**
* Manages the state of the toolbar when a plugin is clicked, and toggles
* the appropriate plugins on and off.
*/
handlePluginClick(plugin) {
// If the plugin was already selected, toggle it off
if (plugin === this.activePlugin) {
plugin.deactivate();
this.activePlugin = null;
} else {
// Deactivate the active plugin if there is one
if (this.activePlugin) {
this.activePlugin.deactivate();
}
// Activate the selected plugin
plugin.activate();
this.activePlugin = plugin;
}
}
/**
* Renders the toolbar and appends it to the specified element.
*/
appendTo($el) {
let $logo = $(logoTemplate());
let $toolbar;
let $defaultPlugins = plugins.default.map((Plugin) => { // eslint-disable-line no-unused-vars
// Render each plugin with the bound click handler
return <Plugin onClick={::this.handlePluginClick} />;
});
let $experimentalPlugins = null;
if (plugins.experimental.length) {
$experimentalPlugins = (
<div>
<div className="tota11y-plugins-separator">
Experimental
</div>
{
plugins.experimental.map((Plugin) => { // eslint-disable-line no-unused-vars
return (
<Plugin onClick={::this.handlePluginClick} />
);
})
}
</div>
);
}
let $plugins = (
<div className="tota11y-plugins">
{$defaultPlugins}
{$experimentalPlugins}
</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"));
});