@@ -6,25 +6,32 @@ fetch("web-components/hero-section/hero-section.html")
66// Create web component
77function createComponent ( html ) {
88
9+ // Set text content
910 function setContent ( cssSelector , content , shadow ) {
1011 const selector = shadow . querySelector ( cssSelector ) ;
12+ // Check if p tag is used in desc
1113 if ( content . includes ( '<p>' ) ) {
14+ // Create paragraph element and add it to the document
1215 let paragraph = document . createElement ( 'p' ) ;
1316 paragraph . innerHTML = content ;
1417 selector . appendChild ( paragraph ) ;
1518 } else {
19+ // Update the text
1620 selector . textContent = content ;
1721 }
1822 }
1923
24+ // Set link
2025 function setLink ( cssSelector , url , shadow ) {
2126 const link = shadow . querySelector ( cssSelector ) ;
2227 link . href = url ;
28+ // Open new tab for external links
2329 if ( url . includes ( 'https://' ) ) {
2430 link . setAttribute ( 'target' , '_blank' ) ;
2531 }
2632 }
2733
34+ // Set image
2835 function setImage ( cssSelector , src , shadow ) {
2936 const image = shadow . querySelector ( cssSelector ) ;
3037 image . src = src ;
@@ -57,21 +64,24 @@ function createComponent(html) {
5764 const shadow = this . attachShadow ( { mode : 'closed' } ) ;
5865 shadow . innerHTML = html ;
5966
67+ // Set content
6068 setContent ( '.section' , this . section , shadow ) ;
6169 setContent ( '.name' , this . name , shadow ) ;
6270 setContent ( '.desc' , this . desc , shadow ) ;
6371 setLink ( '.button-primary' , this . link , shadow ) ;
6472 setContent ( '.button-primary-text' , this . linktext , shadow ) ;
6573
74+ // Check if secondary button is used
6675 if ( this . link2 != "" ) {
6776 setLink ( '.button-secondary' , this . link2 , shadow ) ;
6877 setContent ( '.button-secondary-text' , this . linktext2 , shadow ) ;
6978 } else {
79+ // Hide the secondary button if no link is provided
7080 const buttonSecondary = shadow . querySelector ( '.button-secondary' ) ;
7181 buttonSecondary . style . display = 'none' ;
7282 }
7383
74- // Check if links are external
84+ // Change background and icon based on provided section
7585 const heroSection = shadow . querySelector ( '.hero' ) ;
7686 switch ( this . section ) {
7787 case 'Engage' :
0 commit comments