@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1/**
2 * @provides javelin-behavior-toggle-class
3 * @requires javelin-behavior
4 * javelin-stratcom
5 * javelin-dom
6 */
7
8/**
9 * Toggle CSS classes when an element is clicked. This behavior is activated
10 * by adding the sigil `jx-toggle-class` to an element, and a key `map` to its
11 * data. The `map` should be a map from element IDs to the classes that should
12 * be toggled on them.
13 *
14 * Optionally, you may provide a `state` key to set the default state of the
15 * element.
16 */
17JX.behavior('toggle-class', function(config, statics) {
18 function install() {
19 JX.Stratcom.listen(
20 'click',
21 'jx-toggle-class',
22 function(e) {
23 e.kill();
24
25 var t = e.getNodeData('jx-toggle-class');
26 t.state = !t.state;
27 for (var k in t.map) {
28 JX.DOM.alterClass(JX.$(k), t.map[k], t.state);
29 }
30 });
31
32 return true;
33 }
34
35 statics.install = statics.install || install();
36});