@@ -273,122 +273,6 @@ define(function main(require, exports, module) {
273273 return false ;
274274 }
275275
276- let $livePreviewPanel = null ; // stores the live preview panel, need this as overlay is appended inside this
277- let $overlayContainer = null ; // the overlay container
278- let shouldShowSyncErrorOverlay = true ; // once user closes the overlay we don't show them again
279- let shouldShowConnectingOverlay = true ;
280- let connectingOverlayTimer = null ; // this is needed as we show the connecting overlay after 3s
281- let connectingOverlayTimeDuration = 3000 ;
282-
283- /**
284- * this function is responsible to check whether to show the overlay or not and how it should be shown
285- * because if user has closed the overlay manually, we don't show it again
286- * secondly, for connecting overlay we show that after a 3s timer, but sync error overlay is shown immediately
287- * @param {String } textMessage - the text that is written inside the overlay
288- * @param {Number } status - 1 for connect, 4 for sync error but we match it using MultiBrowserLiveDev
289- */
290- function _handleOverlay ( textMessage , status ) {
291- if ( ! $livePreviewPanel ) {
292- $livePreviewPanel = $ ( "#panel-live-preview" ) ;
293- }
294-
295- // remove any existing overlay & timer
296- _hideOverlay ( ) ;
297-
298- // to not show the overlays if user has already closed it before
299- if ( status === MultiBrowserLiveDev . STATUS_CONNECTING && ! shouldShowConnectingOverlay ) { return ; }
300- if ( status === MultiBrowserLiveDev . STATUS_SYNC_ERROR && ! shouldShowSyncErrorOverlay ) { return ; }
301-
302- // for connecting status, we delay showing the overlay by 3 seconds
303- if ( status === MultiBrowserLiveDev . STATUS_CONNECTING ) {
304- connectingOverlayTimer = setTimeout ( ( ) => {
305- _createAndShowOverlay ( textMessage , status ) ;
306- connectingOverlayTimer = null ;
307- } , connectingOverlayTimeDuration ) ;
308- return ;
309- }
310-
311- // for sync error status, show immediately
312- _createAndShowOverlay ( textMessage , status ) ;
313- }
314-
315- /**
316- * this function is responsible to create & show the overlay.
317- * so overlay is shown when the live preview is connecting or live preview stopped because of some syntax error
318- * @param {String } textMessage - the text that is written inside the overlay
319- * @param {Number } status - 1 for connect, 4 for sync error but we match it using MultiBrowserLiveDev
320- */
321- function _createAndShowOverlay ( textMessage , status ) {
322- if ( ! $livePreviewPanel ) {
323- $livePreviewPanel = $ ( "#panel-live-preview" ) ;
324- }
325-
326- // create the overlay element
327- // styled inside the 'src/extensionsIntegrated/Phoenix-live-preview/live-preview.css'
328- $overlayContainer = $ ( "<div>" ) . addClass ( "live-preview-status-overlay" ) ; // the wrapper for overlay element
329- const $message = $ ( "<div>" ) . addClass ( "live-preview-overlay-message" ) . text ( textMessage ) ;
330-
331- // the close button at the right end of the overlay
332- const $close = $ ( "<div>" ) . addClass ( "live-preview-overlay-close" )
333- . attr ( "title" , Strings . LIVE_PREVIEW_HIDE_OVERLAY )
334- . on ( 'click' , ( ) => {
335- if ( status === MultiBrowserLiveDev . STATUS_CONNECTING ) {
336- shouldShowConnectingOverlay = false ;
337- } else if ( status === MultiBrowserLiveDev . STATUS_SYNC_ERROR ) {
338- shouldShowSyncErrorOverlay = false ;
339- }
340- _hideOverlay ( ) ;
341- } ) ;
342- const $closeIcon = $ ( "<i>" ) . addClass ( "fas fa-times" ) ;
343-
344- $close . append ( $closeIcon ) ;
345- $overlayContainer . append ( $message ) ;
346- $overlayContainer . append ( $close ) ;
347- $livePreviewPanel . append ( $overlayContainer ) ;
348- }
349-
350- /**
351- * responsible to hide the overlay
352- */
353- function _hideOverlay ( ) {
354- _clearConnectingOverlayTimer ( ) ;
355- if ( $overlayContainer ) {
356- $overlayContainer . remove ( ) ;
357- $overlayContainer = null ;
358- }
359- }
360-
361- /**
362- * This is a helper function that just checks that if connectingOverlayTimer exists, we clear it
363- */
364- function _clearConnectingOverlayTimer ( ) {
365- if ( connectingOverlayTimer ) {
366- clearTimeout ( connectingOverlayTimer ) ;
367- connectingOverlayTimer = null ;
368- }
369- }
370-
371- /**
372- * this function adds/remove the full-width class from the overlay container
373- * styled inside 'src/extensionsIntegrated/Phoenix-live-preview/live-preview.css'
374- *
375- * we need this because
376- * normally when live preview has a good width (more than 305px) then a 3px divider is shown at the left end
377- * so in that case we give the overlay a width of (100% - 3px),
378- * but when the live preview width is reduced
379- * then that divider line gets cut off, so in that case we make the width 100% for this overlay
380- *
381- * without this handling, a white gap appears on the left side, which is distracting
382- */
383- function _setOverlayWidth ( ) {
384- if ( ! $overlayContainer || ! $livePreviewPanel . length ) { return ; }
385- if ( $livePreviewPanel . width ( ) <= 305 ) {
386- $overlayContainer . addClass ( "full-width" ) ;
387- } else {
388- $overlayContainer . removeClass ( "full-width" ) ;
389- }
390- }
391-
392276 /** Initialize LiveDevelopment */
393277 AppInit . appReady ( function ( ) {
394278 params . parse ( ) ;
@@ -443,19 +327,6 @@ define(function main(require, exports, module) {
443327 exports . trigger ( exports . EVENT_LIVE_PREVIEW_RELOAD , clientDetails ) ;
444328 } ) ;
445329
446- MultiBrowserLiveDev . on ( MultiBrowserLiveDev . EVENT_STATUS_CHANGE , function ( event , status ) {
447- if ( status === MultiBrowserLiveDev . STATUS_CONNECTING ) {
448- _handleOverlay ( Strings . LIVE_DEV_STATUS_TIP_PROGRESS1 , status ) ;
449- } else if ( status === MultiBrowserLiveDev . STATUS_SYNC_ERROR ) {
450- _handleOverlay ( Strings . LIVE_DEV_STATUS_TIP_SYNC_ERROR , status ) ;
451- } else {
452- _hideOverlay ( ) ;
453- }
454- } ) ;
455- // to understand why we need this, pls read the _setOverlayWidth function
456- new ResizeObserver ( _setOverlayWidth ) . observe ( $ ( "#main-plugin-panel" ) [ 0 ] ) ;
457- EditorManager . on ( "activeEditorChange" , _hideOverlay ) ;
458-
459330 // allow live preview to handle escape key event
460331 // Escape is mainly to hide boxes if they are visible
461332 WorkspaceManager . addEscapeKeyEventHandler ( "livePreview" , _handleLivePreviewEscapeKey ) ;
0 commit comments