Skip to content

Commit 7108075

Browse files
devvaannshabose
authored andcommitted
feat: overlays are overlapping the live preview content
1 parent 2619fcb commit 7108075

File tree

3 files changed

+51
-44
lines changed

3 files changed

+51
-44
lines changed

src/extensionsIntegrated/Phoenix-live-preview/live-preview.css

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -158,28 +158,26 @@
158158
}
159159

160160
.live-preview-status-overlay {
161-
width: 100%;
162-
position: absolute;
163-
top: 30px;
164-
left: 0;
165-
z-index: 100;
161+
display: flex;
162+
flex-direction: row;
163+
background-color: #666;
164+
color: #ededed;
165+
justify-content: center;
166+
align-items: center;
167+
padding: 0.35em;
168+
position: relative;
166169
}
167170

168171
.live-preview-overlay-message {
169-
color: #ededed;
170-
background-color: #666;
171-
padding: 0.35em;
172-
vertical-align: top;
173172
text-align: center;
173+
flex: 1;
174174
}
175175

176176
.live-preview-overlay-close {
177-
position: absolute;
178-
top: 7px;
179-
right: 12px;
180177
font-size: 12px;
181178
cursor: pointer;
182-
color: #ededed;
179+
margin-left: 10px;
180+
margin-right: 10px;
183181
}
184182

185183
.live-preview-overlay-close:hover {

src/extensionsIntegrated/Phoenix-live-preview/main.js

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -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) {

src/extensionsIntegrated/Phoenix-live-preview/panel.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@
5757
style="margin-left: 10px;margin-right: 10px;cursor: pointer;"
5858
title="{{Strings.CLOSE}}"></i>
5959
</div>
60+
<div class="live-preview-status-overlay forced-hidden">
61+
<span class="live-preview-overlay-message"><!-- the msg will come here dynamically --></span>
62+
<i class="fa fa-times live-preview-overlay-close" title="{{Strings.LIVE_PREVIEW_HIDE_OVERLAY}}"></i>
63+
</div>
6064
<div class="frame-container">
6165
<div style="width: 3px;"></div>
6266
<iframe id="panel-live-preview-frame" title="Live Preview" style="border: none"

0 commit comments

Comments
 (0)