Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
uw_wcms_ohana
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
WCMS
uw_wcms_ohana
Commits
53a58bc2
Commit
53a58bc2
authored
2 years ago
by
Eric Bremner
Browse files
Options
Downloads
Patches
Plain Diff
ISTWCMS-5656: fixing js for tabs
parent
3c22dc3f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!17
ISTWCMS-5656: adding tabs
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/patterns/04-components/tabs/tabs.js
+72
-2
72 additions, 2 deletions
src/patterns/04-components/tabs/tabs.js
with
72 additions
and
2 deletions
src/patterns/04-components/tabs/tabs.js
+
72
−
2
View file @
53a58bc2
/**
* @file
* JS for tabs.
*/
(
function
(
$
,
Drupal
)
{
...
...
@@ -10,18 +11,87 @@
$
(
'
.uw-contact-expand-all
'
).
click
(
function
()
{
$
(
'
.uw-contact details
'
).
each
(
function
()
{
console
.
log
(
$
(
this
));
$
(
this
).
attr
(
'
open
'
,
''
);
});
});
$
(
'
.uw-contact-collapse-all
'
).
click
(
function
()
{
$
(
'
.uw-contact details
'
).
each
(
function
()
{
console
.
log
(
$
(
this
));
$
(
this
).
removeAttr
(
'
open
'
);
});
});
/**
* Change tabs.
* @param {e} e The event.
* @returns {null}.
*/
function
changeTabs
(
e
)
{
const
target
=
e
.
target
;
const
parent
=
target
.
parentNode
;
const
grandparent
=
parent
.
parentNode
;
// Remove all current selected tabs.
parent
.
querySelectorAll
(
'
[aria-selected="true"]
'
)
.
forEach
(
t
=>
t
.
setAttribute
(
'
aria-selected
'
,
false
));
// Set this tab as selected.
target
.
setAttribute
(
'
aria-selected
'
,
true
);
// Hide all tab panels.
grandparent
.
querySelectorAll
(
'
[role="tabpanel"]
'
)
.
forEach
(
p
=>
p
.
setAttribute
(
'
hidden
'
,
true
));
// Show the selected panel.
grandparent
.
parentNode
.
querySelector
(
`#
${
target
.
getAttribute
(
'
aria-controls
'
)}
`
)
.
removeAttribute
(
'
hidden
'
);
}
window
.
addEventListener
(
'
DOMContentLoaded
'
,
()
=>
{
const
tabs
=
document
.
querySelectorAll
(
'
[role="tab"]
'
);
const
tabList
=
document
.
querySelector
(
'
[role="tablist"]
'
);
if
(
tabs
.
length
===
0
)
{
return
;
}
// Add a click event handler to each tab.
tabs
.
forEach
(
tab
=>
{
tab
.
addEventListener
(
'
click
'
,
changeTabs
);
});
// Enable arrow navigation between tabs in the tab list.
let
tabFocus
=
0
;
tabList
.
addEventListener
(
'
keydown
'
,
e
=>
{
// Move right.
if
(
e
.
keyCode
===
39
||
e
.
keyCode
===
37
)
{
tabs
[
tabFocus
].
setAttribute
(
'
tabindex
'
,
-
1
);
if
(
e
.
keyCode
===
39
)
{
tabFocus
++
;
// If we're at the end, go to the start.
if
(
tabFocus
>=
tabs
.
length
)
{
tabFocus
=
0
;
}
}
// Move left.
else
if
(
e
.
keyCode
===
37
)
{
tabFocus
--
;
// If we're at the start, move to the end.
if
(
tabFocus
<
0
)
{
tabFocus
=
tabs
.
length
-
1
;
}
}
tabs
[
tabFocus
].
setAttribute
(
'
tabindex
'
,
0
);
tabs
[
tabFocus
].
focus
();
}
});
});
});
}
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment