@@ -24,9 +24,16 @@ function deleteLetter() {
2424 input . value = input . value . slice ( 0 , - 1 ) ;
2525}
2626
27- window . onload = function ( ) {
27+ window . addEventListener ( 'DOMContentLoaded' , function ( ) {
2828
2929 showInstructionsDialog ( ) ;
30+
31+ setupButton ( 'buttonCopyOrShareResult' , eitherCopyOrShareResult ) ;
32+
33+ showPangramPoints ( ) ;
34+
35+ animateBeeOncePerScreensize ( ) ;
36+
3037 function showInstructionsDialog ( ) {
3138 const dialog = document . getElementById ( 'dialog-instructions' ) ;
3239 const closeButton = document . getElementById ( 'close-dialog' ) ;
@@ -49,6 +56,7 @@ window.onload = function () {
4956 }
5057
5158
59+
5260 const scoreArea = document . getElementById ( 'score-area' ) ;
5361 const score = scoreArea . innerText ;
5462 const sectionResults = document . getElementById ( 'results' ) ;
@@ -119,9 +127,8 @@ window.onload = function () {
119127 img . src = URL . createObjectURL ( svgBlob ) ;
120128
121129 }
122- setupButton ( 'buttonCopyOrShareResult' , eitherCopyOrShareResult ) ;
123-
124130
131+ // Show the pangram bonus points:
125132 function showPangramPoints ( ) {
126133 const pElement = document . querySelector ( 'dialog p' ) ;
127134 if ( pElement && pElement . textContent . includes ( '🐝' ) ) {
@@ -130,5 +137,26 @@ window.onload = function () {
130137 }
131138 }
132139
133- showPangramPoints ( ) ;
134- }
140+
141+ // Show the bee animation only once per session:
142+ function animateBeeOncePerScreensize ( ) {
143+ const bee = document . getElementById ( 'beeOne' ) ;
144+ const beeInnerWrapper = document . getElementById ( 'beeOneInnerWrapper' ) ;
145+ if ( ! sessionStorage . getItem ( 'beeShown' ) ) {
146+ if ( window . innerWidth <= 768 ) {
147+ // Add class for smaller screens and set animation duration
148+ bee . style . animation = 'fly-small-screens 3s, jiggle 1s infinite' ;
149+ bee . style . top = '10%' ;
150+ bee . style . left = '72%' ;
151+ beeInnerWrapper . setAttribute ( 'transform' , 'rotate(90 50 50)' ) ;
152+
153+ } else {
154+ // Add class for larger screens and set animation duration
155+ bee . style . animation = 'fly-large-screens 13s, jiggle 1s infinite' ;
156+ bee . style . top = '10%' ;
157+ bee . style . right = '68%' ;
158+ }
159+ sessionStorage . setItem ( 'beeShown' , 'true' ) ;
160+ }
161+ }
162+ } ) ;
0 commit comments