Skip to content

Commit aa2e7ae

Browse files
authored
Merge pull request #72 from imsdev/security-course-card
Responsive courses page
2 parents b601de6 + 2261a29 commit aa2e7ae

File tree

12 files changed

+752
-528
lines changed

12 files changed

+752
-528
lines changed

ims-education.html

Lines changed: 495 additions & 502 deletions
Large diffs are not rendered by default.

web-components/course-card/course-card.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ img {
6161
/* Styling for course card */
6262
.course-card {
6363
margin: 1em 0em;
64-
padding: 2em 0em;
64+
padding: 2em;
6565
display: flex;
6666
flex-flow: row wrap;
6767
align-items: flex-start;

web-components/course-card/course-card.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ <h3 class="live-session"></h3>
2323
</div>
2424
</div>
2525
<div class="link-g">
26-
<a class="course-link" target="_blank" rel="noopener noreferrer"></a>
27-
<a class="register-link" target="_blank" rel="noopener noreferrer"></a>
26+
<div class="course-link-g"><a class="course-link" target="_blank" rel="noopener noreferrer"></a></div>
27+
<div class="register-link-g"><a class="register-link" target="_blank" rel="noopener noreferrer"></a></div>
2828
</div>
2929
</div>
3030
</div>

web-components/course-card/course-card.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,21 @@ function createComponent(html) {
3737
* @param {boolean} shadow - A boolean indicating whether to use the shadow DOM for the element.
3838
* @returns {void}
3939
*/
40-
function setImage(cssSelector, image, name, selfpaced, shadow) {
40+
function setImage(cssSelector, image, name, imageInvert, shadow) {
4141
const selector = shadow.querySelector(cssSelector);
4242
// Set image
4343
selector.src = image;
4444
// Set alt text
4545
selector.setAttribute('alt', `${name} badge`);
46-
// Change styling for self-paced course card
47-
if (selfpaced == 'false') {
46+
// Change styling for icons
47+
if (image.includes('icons')) {
4848
const courseCard = shadow.querySelector('.course-card');
4949
courseCard.style.alignItems = 'flex-start';
5050
}
51+
// Invert icon
52+
if (imageInvert == 'true') {
53+
selector.style.filter = 'invert(1)';
54+
}
5155
}
5256

5357
/**
@@ -108,6 +112,7 @@ function createComponent(html) {
108112
// Creates an instance of CourseCard
109113
constructor() {
110114
super();
115+
this.imginvert = "false";
111116
this.selfpaced = "";
112117
this.level = "";
113118
this.cost = "";
@@ -126,7 +131,7 @@ function createComponent(html) {
126131
* @returns {Array} An array of property names.
127132
*/
128133
static get observedAttributes() {
129-
return ['name', 'session', 'desc', 'imgsrc', 'selfpaced', 'level', 'cost', 'badge', 'time', 'start',
134+
return ['name', 'session', 'desc', 'imgsrc', 'imginvert', 'selfpaced', 'level', 'cost', 'badge', 'time', 'start',
130135
'end', 'hours', 'link', 'linktext', 'registerlink'];
131136
}
132137
// Course Card Options
@@ -163,7 +168,7 @@ function createComponent(html) {
163168
shadow.innerHTML = html;
164169

165170
// Set course img
166-
setImage('.course-img', this.imgsrc, this.name, this.selfpaced, shadow);
171+
setImage('.course-img', this.imgsrc, this.name, this.imginvert, shadow);
167172
// Set course name
168173
setContent('.course-name', this.name, shadow);
169174
// Set course desc

web-components/hero-section/hero-section.css

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,22 @@ section {
4242

4343
.hero {
4444
display: grid;
45-
grid-template-columns: 4em 2fr;
46-
/* grid-template-rows: 4em 4em 6em 1fr; */
45+
grid-template-columns: 4em 1fr;
4746
grid-template-rows: 4em repeat(3, 1fr);
4847
padding: 3em;
4948
padding-top: 2em;
5049
align-items: center;
5150
}
5251

52+
.hero-highlight {
53+
grid-template-columns: 4em 1fr 1fr;
54+
}
55+
5356
.hero-no-buttons {
5457
grid-template-rows: 4em repeat(2, 1fr);
5558
}
5659

57-
img {
60+
.image {
5861
grid-column: 1;
5962
grid-row: 2;
6063
max-width: 2em;
@@ -140,10 +143,46 @@ h6, p {
140143
background-color: var(--btn-scnd-hover);
141144
}
142145

146+
.highlight-card {
147+
grid-column: 3;
148+
grid-row: 1 / 6;
149+
background-color: white;
150+
padding: 2em 3em 2em 3em;
151+
margin: 1em;
152+
opacity: 0.75;
153+
display: flex;
154+
flex-flow: column wrap;
155+
gap: 1em;
156+
}
157+
158+
.highlight-card div {
159+
display: flex;
160+
flex-flow: row wrap;
161+
gap: 1em;
162+
}
163+
164+
.highlight-card h2 {
165+
font-weight: normal;
166+
font-size: 28px;
167+
}
168+
169+
.highlight-card h3 {
170+
font-weight: 600;
171+
}
172+
173+
.highlight-card a {
174+
color: #0f62fe;
175+
font-size: 1.125em;
176+
}
177+
143178
@media screen and (min-width: 90em) {
144179
.hero {
145180
grid-template-columns: 4em 4fr 1fr;
146181
}
182+
183+
.hero-highlight {
184+
grid-template-columns: 4em 1fr 1fr;
185+
}
147186
}
148187

149188
@media screen and (max-width: 27em) {
@@ -154,4 +193,9 @@ h6, p {
154193
gap: 1em;
155194
padding: 3em 2em;
156195
}
196+
197+
.highlight-card {
198+
padding: 2em;
199+
margin: 0;
200+
}
157201
}

web-components/hero-section/hero-section.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,13 @@ <h2 class="name"></h2>
1717
<span class="button-secondary-text"></span>
1818
</a>
1919
</div>
20+
<div class="highlight-card">
21+
<div>
22+
<img src="wp-content/icons/icon_event.svg" alt="">
23+
<h3>Coming soon</h3>
24+
</div>
25+
<h2 class="highlight"></h2>
26+
<a class="highlight-link" rel="noopener noreferrer">See details</a>
27+
</div>
2028
</div>
2129
</section>

web-components/hero-section/hero-section.js

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,20 @@ fetch("web-components/hero-section/hero-section.html")
33
.then(stream => stream.text())
44
.then(text => createComponent(text))
55

6-
// Create web component
6+
/**
7+
* Creates a web component using a given HTML template.
8+
* @param {string} html - The HTML template.
9+
* @returns {void}
10+
*/
711
function createComponent(html) {
812

9-
// Set text content
13+
/**
14+
* Sets the content of an element based on a CSS selector.
15+
* @param {string} cssSelector - The CSS selector of the element to set the content for.
16+
* @param {string} content - The content to set for the element.
17+
* @param {boolean} shadow - A boolean indicating whether to use the shadow DOM for the element.
18+
* @returns {void}
19+
*/
1020
function setContent(cssSelector, content, shadow) {
1121
const selector = shadow.querySelector(cssSelector);
1222
// Check if span tag is used in desc
@@ -19,17 +29,35 @@ function createComponent(html) {
1929
}
2030
}
2131

22-
// Set link
23-
function setLink(cssSelector, url, shadow) {
32+
/**
33+
* Sets the link of an element based on a CSS selector
34+
* @param {string} cssSelector - The CSS selector of the element to set the link for
35+
* @param {string} url - The link url
36+
* @param {boolean} shadow - A boolean indicating whether to use the shadow DOM for the element
37+
* @param {string} name - The name of the element containing the link
38+
* @returns {void}
39+
*/
40+
function setLink(cssSelector, url, shadow, name) {
41+
name = name || "";
2442
const link = shadow.querySelector(cssSelector);
2543
link.href = url;
2644
// Open new tab for external links
2745
if (url.includes('https://')) {
2846
link.setAttribute('target', '_blank');
2947
}
48+
// Set aria-label if needed
49+
if (name != "") {
50+
link.setAttribute('aria-label', `See details on ${name}`);
51+
}
3052
}
3153

32-
// Set image
54+
/**
55+
* Sets the image of an element based on a CSS selector.
56+
* @param {string} cssSelector - The CSS selector of the element to set the content for.
57+
* @param {string} src - The image to set for the element.
58+
* @param {boolean} shadow - A boolean indicating whether to use the shadow DOM for the element.
59+
* @returns {void}
60+
*/
3361
function setImage(cssSelector, src, shadow) {
3462
const image = shadow.querySelector(cssSelector);
3563
image.src = src;
@@ -44,12 +72,20 @@ function createComponent(html) {
4472
super();
4573
}
4674

47-
// Return array of properties to observe
75+
/**
76+
* Returns an array of properties to observe.
77+
* @returns {Array} An array of property names.
78+
*/
4879
static get observedAttributes() {
49-
return ['name', 'image', 'section', 'desc', 'linktext', 'link', 'linktext2', 'link2'];
80+
return ['name', 'image', 'section', 'desc', 'linktext', 'link', 'linktext2', 'link2', 'highlight', 'highlightlink'];
5081
}
5182

52-
// Called when an attribute is defined or changed
83+
/**
84+
* Called when an attribute is defined or changed.
85+
* @param {string} property - The name of the attribute.
86+
* @param {string} oldValue - The old value of the attribute.
87+
* @param {string} newValue - The new value of the attribute.
88+
*/
5389
attributeChangedCallback(property, oldValue, newValue) {
5490
if (oldValue === newValue) return;
5591
this[property] = newValue;
@@ -61,6 +97,9 @@ function createComponent(html) {
6197
const shadow = this.attachShadow({mode: 'open'});
6298
shadow.innerHTML = html;
6399

100+
const heroSection = shadow.querySelector('.hero-section');
101+
const hero = shadow.querySelector('.hero');
102+
64103
// Set content
65104
setImage('.image', this.image, shadow);
66105
setContent('.section', this.section, shadow);
@@ -73,8 +112,15 @@ function createComponent(html) {
73112
img.classList.add('large-icon');
74113
}
75114

76-
const heroSection = shadow.querySelector('.hero-section');
77-
const hero = shadow.querySelector('.hero');
115+
// Display highlight card if content is provided
116+
if (this.highlight != undefined) {
117+
setContent('.highlight', this.highlight, shadow);
118+
setLink('.highlight-link', this.highlightlink, shadow, this.highlight);
119+
hero.classList.add('hero-highlight');
120+
} else {
121+
const highlightCard = shadow.querySelector('.highlight-card');
122+
highlightCard.style.display = 'none';
123+
}
78124

79125
// Check if primary button is used
80126
if (this.link != undefined) {

wp-content/icons/icon_event.svg

Lines changed: 11 additions & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading

wp-content/icons/icon_locked.svg

Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)