Skip to content

Commit bb762b3

Browse files
committed
functionality for adding jump links to list
1 parent 89c20e1 commit bb762b3

3 files changed

Lines changed: 36 additions & 5 deletions

File tree

ims-videos.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@
101101
link="https://mediacenter.ibm.com/channel/IMS%2BEducational%2BVideos/122579632"
102102
></hero-section>
103103

104-
<jump-links></jump-links>
104+
<jump-links
105+
links="All roles, IMS database, System programming, Application development"
106+
></jump-links>
105107

106108
<!-- =========================== Filter =========================== -->
107109
<!-- remember, the behaviour is that clicking pulls you to the anchors -->

web-components/jump-links/jump-links.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
<link rel="stylesheet" href="wp-includes/css/grids-responsive-min.css">
44

55
<div class="jump-links pure-g">
6-
<ul class="pure-u-1">
7-
<li>
6+
<ul class="list pure-u-1">
7+
<!-- <li>
88
<img src="wp-content/icons/icon_jump-link.svg" alt="">
99
<a href="#all">All roles</a>
1010
</li>
@@ -31,6 +31,6 @@
3131
<li>
3232
<img src="wp-content/icons/icon_jump-link.svg" alt="">
3333
<a href="#support">Support</a>
34-
</li>
34+
</li> -->
3535
</ul>
3636
</div>

web-components/jump-links/jump-links.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,33 @@ fetch("web-components/jump-links/jump-links.html")
99
* @returns {void}
1010
*/
1111
function createComponent(html) {
12+
13+
function createLink(link, shadow) {
14+
let newListItem = document.createElement('li');
15+
let newImage = document.createElement('img');
16+
newImage.src = "wp-content/icons/icon_jump-link.svg";
17+
newImage.alt = "jump link";
18+
newListItem.appendChild(newImage);
19+
let newLink = document.createElement('a');
20+
newLink.textContent = link;
21+
let linkSrc = "#" + (link.toLowerCase().replaceAll(' ', '-'));
22+
newLink.href = linkSrc;
23+
newListItem.appendChild(newLink);
24+
let list = shadow.querySelector('.list');
25+
list.appendChild(newListItem);
26+
}
27+
1228
// Web component class
1329
class JumpLinks extends HTMLElement {
1430

31+
/**
32+
* Returns an array of properties to observe.
33+
* @returns {Array} An array of property names.
34+
*/
35+
static get observedAttributes() {
36+
return ['links'];
37+
}
38+
1539
/**
1640
* Called when an attribute is defined or changed.
1741
* @param {string} property - The name of the attribute.
@@ -26,8 +50,13 @@ function createComponent(html) {
2650
// Invoked when element is added to document
2751
connectedCallback() {
2852
// Create shadow root for element
29-
const shadow = this.attachShadow({mode: 'closed'});
53+
const shadow = this.attachShadow({mode: 'open'});
3054
shadow.innerHTML = html;
55+
56+
const linksArr = (this.links).split(', ');
57+
linksArr.forEach(link => {
58+
createLink(link, shadow);
59+
});
3160
}
3261
}
3362

0 commit comments

Comments
 (0)