@@ -3,34 +3,61 @@ fetch("web-components/course-card/course-card.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+ */
711function createComponent ( html ) {
812
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+ */
920 function setContent ( cssSelector , content , shadow ) {
1021 const selector = shadow . querySelector ( cssSelector ) ;
1122 selector . textContent = content ;
1223 }
1324
25+ /**
26+ * Sets the link of an element based on a CSS selector.
27+ * @param {string } cssSelector - The CSS selector of the element to set the link for.
28+ * @param {string } url - The link url.
29+ * @param {string } name - The name of the element containing the link.
30+ * @param {boolean } shadow - A boolean indicating whether to use the shadow DOM for the element.
31+ * @returns {void }
32+ */
1433 function setLink ( cssSelector , url , name , shadow ) {
1534 const link = shadow . querySelector ( cssSelector ) ;
1635 link . href = url ;
1736 link . setAttribute ( 'aria-label' , `Learn more about ${ name } ` ) ;
1837 }
1938
20- // Web component class
39+ // Web component class representing a course card.
2140 class CourseCard extends HTMLElement {
2241
23- // Creates element with default values
42+ // Creates an instance of CourseCard
2443 constructor ( ) {
2544 super ( ) ;
2645 }
2746
28- // Return array of properties to observe
47+ /**
48+ * Returns an array of properties to observe.
49+ * @returns {Array } An array of property names.
50+ */
2951 static get observedAttributes ( ) {
3052 return [ 'name' , 'desc' , 'imgsrc' , 'level' , 'cost' , 'badge' , 'time' , 'link' , 'livelevel' , 'livecost' , 'livebadge' , 'livetime' , 'livelink' ] ;
3153 }
3254
33- // Called when an attribute is defined or changed
55+ /**
56+ * Called when an attribute is defined or changed.
57+ * @param {string } property - The name of the attribute.
58+ * @param {string } oldValue - The old value of the attribute.
59+ * @param {string } newValue - The new value of the attribute.
60+ */
3461 attributeChangedCallback ( property , oldValue , newValue ) {
3562 if ( oldValue === newValue ) return ;
3663 this [ property ] = newValue ;
@@ -82,5 +109,6 @@ function createComponent(html) {
82109 }
83110 }
84111
112+ // Define new CourseCard element
85113 customElements . define ( 'course-card' , CourseCard ) ;
86114}
0 commit comments