@@ -5,66 +5,70 @@ class PopUpInfo extends HTMLElement {
55 super ( ) ;
66
77 // Create a shadow root
8- var shadow = this . attachShadow ( { mode : 'open' } ) ;
8+ const shadow = this . attachShadow ( { mode : 'open' } ) ;
99
1010 // Create spans
11- var wrapper = document . createElement ( 'span' ) ;
12- wrapper . setAttribute ( 'class' , 'wrapper' ) ;
13- var icon = document . createElement ( 'span' ) ;
14- icon . setAttribute ( 'class' , 'icon' ) ;
11+ const wrapper = document . createElement ( 'span' ) ;
12+ wrapper . setAttribute ( 'class' , 'wrapper' ) ;
13+
14+ const icon = document . createElement ( 'span' ) ;
15+ icon . setAttribute ( 'class' , 'icon' ) ;
1516 icon . setAttribute ( 'tabindex' , 0 ) ;
16- var info = document . createElement ( 'span' ) ;
17- info . setAttribute ( 'class' , 'info' ) ;
17+
18+ const info = document . createElement ( 'span' ) ;
19+ info . setAttribute ( 'class' , 'info' ) ;
1820
1921 // Take attribute content and put it inside the info span
20- var text = this . getAttribute ( 'data-text' ) ;
22+ const text = this . getAttribute ( 'data-text' ) ;
2123 info . textContent = text ;
2224
2325 // Insert icon
24- var imgUrl ;
26+ let imgUrl ;
2527 if ( this . hasAttribute ( 'img' ) ) {
2628 imgUrl = this . getAttribute ( 'img' ) ;
2729 } else {
2830 imgUrl = 'img/default.png' ;
2931 }
30- var img = document . createElement ( 'img' ) ;
32+
33+ const img = document . createElement ( 'img' ) ;
3134 img . src = imgUrl ;
3235 icon . appendChild ( img ) ;
3336
3437 // Create some CSS to apply to the shadow dom
35- var style = document . createElement ( 'style' ) ;
38+ const style = document . createElement ( 'style' ) ;
3639 console . log ( style . isConnected ) ;
3740
38- style . textContent = '.wrapper {' +
39- 'position: relative;' +
40- '}' +
41-
42- '.info {' +
43- 'font-size: 0.8rem;' +
44- 'width: 200px;' +
45- 'display: inline-block;' +
46- 'border: 1px solid black;' +
47- 'padding: 10px;' +
48- 'background: white;' +
49- 'border-radius: 10px;' +
50- 'opacity: 0;' +
51- 'transition: 0.6s all;' +
52- 'position: absolute;' +
53- 'bottom: 20px;' +
54- 'left: 10px;' +
55- 'z-index: 3;' +
56- '}' +
41+ style . textContent = `
42+ .wrapper {
43+ position: relative;
44+ }
5745
58- 'img {' +
59- 'width: 1.2rem' +
60- '}' +
46+ .info {
47+ font-size: 0.8rem;
48+ width: 200px;
49+ display: inline-block;
50+ border: 1px solid black;
51+ padding: 10px;
52+ background: white;
53+ border-radius: 10px;
54+ opacity: 0;
55+ transition: 0.6s all;
56+ position: absolute;
57+ bottom: 20px;
58+ left: 10px;
59+ z-index: 3;
60+ }
6161
62- '.icon:hover + .info, .icon:focus + .info {' +
63- 'opacity : 1;' +
64- '}' ;
62+ img {
63+ width : 1.2rem;
64+ }
6565
66- // attach the created elements to the shadow dom
66+ .icon:hover + .info, .icon:focus + .info {
67+ opacity: 1;
68+ }
69+ ` ;
6770
71+ // Attach the created elements to the shadow dom
6872 shadow . appendChild ( style ) ;
6973 console . log ( style . isConnected ) ;
7074 shadow . appendChild ( wrapper ) ;
0 commit comments