@@ -156,7 +156,9 @@ define(function (require, exports, module) {
156156 let modeThatWasSelected = null ;
157157
158158 // live Preview overlay variables (overlays are shown when live preview is connecting or there's a syntax error)
159- let $overlayContainer = null ; // the overlay container
159+ let $statusOverlay = null ; // reference to the static overlay element
160+ let $statusOverlayMessage = null ; // reference to the message span
161+ let $statusOverlayClose = null ; // reference to the close button
160162 let shouldShowSyncErrorOverlay = true ; // once user closes the overlay we don't show them again
161163 let shouldShowConnectingOverlay = true ;
162164 let connectingOverlayTimer = null ; // this is needed as we show the connecting overlay after 3s
@@ -224,57 +226,57 @@ define(function (require, exports, module) {
224226 connectingOverlayTimer = null ;
225227 return ;
226228 }
227- _createAndShowOverlay ( textMessage , status ) ;
229+ _showOverlay ( textMessage , status ) ;
228230 connectingOverlayTimer = null ;
229231 } , connectingOverlayTimeDuration ) ;
230232 return ;
231233 }
232234
233235 // for sync error status, show immediately
234- _createAndShowOverlay ( textMessage , status ) ;
236+ _showOverlay ( textMessage , status ) ;
235237 }
236238
237239 /**
238- * this function is responsible to create & show the overlay.
240+ * this function is init the overlay.
239241 * so overlay is shown when the live preview is connecting or live preview stopped because of some syntax error
240- * @param {String } textMessage - the text that is written inside the overlay
241- * @param {Number } status - 1 for connect, 4 for sync error but we match it using MultiBrowserLiveDev
242242 */
243- function _createAndShowOverlay ( textMessage , status ) {
243+ function _initOverlay ( ) {
244244 if ( ! $panel ) { return ; }
245+ $statusOverlay = $panel . find ( ".live-preview-status-overlay" ) ;
246+ $statusOverlayMessage = $statusOverlay . find ( ".live-preview-overlay-message" ) ;
247+ $statusOverlayClose = $statusOverlay . find ( ".live-preview-overlay-close" ) ;
248+
249+ $statusOverlayClose . on ( "click" , ( ) => {
250+ const currentStatue = $statusOverlay . data ( "status" ) ;
251+ if ( currentStatue === MultiBrowserLiveDev . STATUS_CONNECTING ) {
252+ shouldShowConnectingOverlay = false ;
253+ } else if ( currentStatue === MultiBrowserLiveDev . STATUS_SYNC_ERROR ) {
254+ shouldShowSyncErrorOverlay = false ;
255+ }
256+ _hideOverlay ( ) ;
257+ } ) ;
258+ }
245259
246- // create the overlay element
247- // styled inside the 'live-preview.css'
248- $overlayContainer = $ ( "<div>" ) . addClass ( "live-preview-status-overlay" ) ; // the wrapper for overlay element
249- const $message = $ ( "<div>" ) . addClass ( "live-preview-overlay-message" ) . text ( textMessage ) ;
250-
251- // the close button at the right end of the overlay
252- const $close = $ ( "<div>" ) . addClass ( "live-preview-overlay-close" )
253- . attr ( "title" , Strings . LIVE_PREVIEW_HIDE_OVERLAY )
254- . on ( 'click' , ( ) => {
255- if ( status === MultiBrowserLiveDev . STATUS_CONNECTING ) {
256- shouldShowConnectingOverlay = false ;
257- } else if ( status === MultiBrowserLiveDev . STATUS_SYNC_ERROR ) {
258- shouldShowSyncErrorOverlay = false ;
259- }
260- _hideOverlay ( ) ;
261- } ) ;
262- const $closeIcon = $ ( "<i>" ) . addClass ( "fas fa-times" ) ;
260+ /**
261+ * Show the overlay with the given message and status
262+ * @param {String } textMessage - the text that is written inside the overlay
263+ * @param {Number } status - 1 for connect, 4 for sync error but we match it using MultiBrowserLiveDev
264+ */
265+ function _showOverlay ( textMessage , status ) {
266+ if ( ! $statusOverlay ) { return ; }
263267
264- $close . append ( $closeIcon ) ;
265- $overlayContainer . append ( $message ) ;
266- $overlayContainer . append ( $close ) ;
267- $panel . append ( $overlayContainer ) ;
268+ $statusOverlayMessage . text ( textMessage ) ;
269+ $statusOverlay . data ( "status" , status ) ;
270+ $statusOverlay . removeClass ( "forced-hidden" ) ;
268271 }
269272
270273 /**
271274 * responsible to hide the overlay
272275 */
273276 function _hideOverlay ( ) {
274277 _clearConnectingOverlayTimer ( ) ;
275- if ( $overlayContainer ) {
276- $overlayContainer . remove ( ) ;
277- $overlayContainer = null ;
278+ if ( $statusOverlay ) {
279+ $statusOverlay . addClass ( "forced-hidden" ) ;
278280 }
279281 }
280282
@@ -785,6 +787,9 @@ define(function (require, exports, module) {
785787 _loadPreview ( true , true ) ;
786788 Metrics . countEvent ( Metrics . EVENT_TYPE . LIVE_PREVIEW , "reloadBtn" , "click" ) ;
787789 } ) ;
790+
791+ // init the status overlay
792+ _initOverlay ( ) ;
788793 }
789794
790795 async function _loadPreview ( force , isReload ) {
0 commit comments