Skip to content

Commit cee47ad

Browse files
Near complete rewrite of sidebars JS for reliability:
- Refactored as JavaScript classes. - Everything is now scoped to behaviours without references to instances outside of said behaviours; this is primarily achieved by instantiating classes and assigning them to a property on elements we attach to, and then destroyed when the behaviour detaches. - Did I mention hella object-oriented? See: https://github.com/neurocracy/omnipedia/issues/46
1 parent 2823154 commit cee47ad

File tree

7 files changed

+812
-536
lines changed

7 files changed

+812
-536
lines changed

javascript/sidebars.elements.js

Lines changed: 0 additions & 149 deletions
This file was deleted.

javascript/sidebars.focus.js

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010
// - 'omnipediaSidebarsMenuClose': will move focus to the menu open control if
1111
// sidebars are off-canvas.
1212

13+
AmbientImpact.onGlobals([
14+
'ally.query.tabbable',
15+
], function() {
1316
AmbientImpact.on([
14-
'OmnipediaSiteThemeSidebarsElements',
15-
'OmnipediaSiteThemeSidebarsState',
17+
'OmnipediaSiteThemeSidebars',
1618
'pointerFocusHide',
17-
], function(sidebarsElements, sidebarsState, aiPointerFocusHide, $) {
19+
], function(sidebars, aiPointerFocusHide, $) {
1820
AmbientImpact.addComponent('OmnipediaSiteThemeSidebarsFocus', function(
19-
sidebarsFocus, $
21+
sidebarsFocus, $,
2022
) {
2123

2224
'use strict';
@@ -31,47 +33,53 @@ AmbientImpact.addComponent('OmnipediaSiteThemeSidebarsFocus', function(
3133
this.addBehaviour(
3234
'OmnipediaSiteThemeSidebarsFocus',
3335
'omnipedia-site-theme-sidebars-focus',
34-
sidebarsElements.getSidebarsBehaviourSelector(),
36+
'body',
3537
function(context, settings) {
3638

37-
$(this).on(
38-
'omnipediaSidebarsMenuOpen.' + eventNamespace,
39-
function(event) {
39+
$(this).on(`omnipediaSidebarsMenuOpen.${eventNamespace}`, function(
40+
event, instance,
41+
) {
4042

41-
if (sidebarsState.isOffCanvas() === true) {
42-
43-
aiPointerFocusHide.lock();
44-
45-
sidebarsElements.getSidebarsContainer().focus();
43+
if (instance.isOffCanvas() !== true) {
44+
return;
45+
}
4646

47-
aiPointerFocusHide.unlock();
47+
aiPointerFocusHide.lock();
4848

49-
}
49+
$(ally.query.tabbable({
50+
context: instance.$sidebars,
51+
includeContext: true,
52+
})).first().focus();
5053

51-
}).on('omnipediaSidebarsMenuClose.' + eventNamespace, function(event) {
54+
aiPointerFocusHide.unlock();
5255

53-
if (sidebarsState.isOffCanvas() === true) {
56+
}).on(`omnipediaSidebarsMenuClose.${eventNamespace}`, function(
57+
event, instance,
58+
) {
5459

55-
aiPointerFocusHide.lock();
60+
if (instance.isOffCanvas() !== true) {
61+
return;
62+
}
5663

57-
sidebarsElements.getSidebarsMenuOpen().focus();
64+
aiPointerFocusHide.lock();
5865

59-
aiPointerFocusHide.unlock();
66+
instance.$menuOpen.focus();
6067

61-
}
68+
aiPointerFocusHide.unlock();
6269

6370
});
6471

6572
},
6673
function(context, settings, trigger) {
6774

6875
$(this).off([
69-
'omnipediaSidebarsMenuOpen.' + eventNamespace,
70-
'omnipediaSidebarsMenuClose.' + eventNamespace,
76+
`omnipediaSidebarsMenuOpen.${eventNamespace}`,
77+
`omnipediaSidebarsMenuClose.${eventNamespace}`,
7178
].join(' '));
7279

7380
}
7481
);
7582

7683
});
7784
});
85+
});

0 commit comments

Comments
 (0)