Skip to content

Commit fb5ca41

Browse files
committed
feat: disable all the live preview advance features when its disabled
1 parent 3963fe1 commit fb5ca41

File tree

1 file changed

+46
-35
lines changed

1 file changed

+46
-35
lines changed

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@
3030
*/
3131
function RemoteFunctions(config) {
3232

33-
// this is responsible to make the advanced DOM features active or inactive
34-
// TODO: give this var a better name
35-
let isFlagActive = true;
33+
// this is responsible to make the advanced live preview features active or inactive
34+
let isLPEditFeaturesActive = false;
3635

3736
// this will store the element that was clicked previously (before the new click)
3837
// we need this so that we can remove click styling from the previous element when a new element is clicked
@@ -641,6 +640,11 @@ function RemoteFunctions(config) {
641640

642641
create: function() {
643642
this.remove(); // remove existing box if already present
643+
644+
if(!isLPEditFeaturesActive) {
645+
return;
646+
}
647+
644648
this._style(); // style the box
645649

646650
window.document.body.appendChild(this.body);
@@ -829,6 +833,11 @@ function RemoteFunctions(config) {
829833

830834
create: function() {
831835
this.remove(); // remove existing box if already present
836+
837+
if(!isLPEditFeaturesActive) {
838+
return;
839+
}
840+
832841
this._style(); // style the box
833842

834843
window.document.body.appendChild(this.body);
@@ -1196,7 +1205,7 @@ function RemoteFunctions(config) {
11961205
}
11971206

11981207
function onElementHover(event) {
1199-
if (_hoverHighlight) {
1208+
if (_hoverHighlight && isLPEditFeaturesActive) {
12001209
_hoverHighlight.clear();
12011210

12021211
// Skip highlighting for HTML and BODY tags and for DOM elements which doesn't have 'data-brackets-id'
@@ -1227,24 +1236,24 @@ function RemoteFunctions(config) {
12271236
}
12281237

12291238
function onElementHoverOut(event) {
1230-
if (_hoverHighlight) {
1239+
if (_hoverHighlight && isLPEditFeaturesActive) {
12311240
_hoverHighlight.clear();
1232-
}
12331241

1234-
// Restore original background color
1235-
if (event && event.target && event.target.nodeType === Node.ELEMENT_NODE && event.target.hasAttribute("data-brackets-id")) {
1236-
if (event.target._originalBackgroundColor !== undefined) {
1237-
event.target.style.backgroundColor = event.target._originalBackgroundColor;
1238-
} else {
1239-
event.target.style.backgroundColor = "";
1242+
// Restore original background color
1243+
if (event && event.target && event.target.nodeType === Node.ELEMENT_NODE && event.target.hasAttribute("data-brackets-id")) {
1244+
if (event.target._originalBackgroundColor !== undefined) {
1245+
event.target.style.backgroundColor = event.target._originalBackgroundColor;
1246+
} else {
1247+
event.target.style.backgroundColor = "";
1248+
}
1249+
delete event.target._originalBackgroundColor;
12401250
}
1241-
delete event.target._originalBackgroundColor;
1242-
}
12431251

1244-
// Remove info box when mouse leaves the element
1245-
if (_nodeInfoBox) {
1246-
_nodeInfoBox.remove();
1247-
_nodeInfoBox = null;
1252+
// Remove info box when mouse leaves the element
1253+
if (_nodeInfoBox) {
1254+
_nodeInfoBox.remove();
1255+
_nodeInfoBox = null;
1256+
}
12481257
}
12491258
}
12501259

@@ -1256,7 +1265,7 @@ function RemoteFunctions(config) {
12561265
function onClick(event) {
12571266
// make sure that the feature is enabled and also the clicked element has the attribute 'data-brackets-id'
12581267
if (
1259-
isFlagActive &&
1268+
isLPEditFeaturesActive &&
12601269
event.target.hasAttribute("data-brackets-id") &&
12611270
event.target.tagName !== "BODY" &&
12621271
event.target.tagName !== "HTML"
@@ -1292,7 +1301,6 @@ function RemoteFunctions(config) {
12921301
event.target.style.outline = "1px solid #4285F4";
12931302
previouslyClickedElement = event.target;
12941303
} else if ( // when user clicks on the HTML or the BODY tag, we want to remove the boxes
1295-
isFlagActive &&
12961304
_nodeMoreOptionsBox &&
12971305
(event.target.tagName === "HTML" || event.target.tagName === "BODY")
12981306
) {
@@ -1306,7 +1314,7 @@ function RemoteFunctions(config) {
13061314
*/
13071315
function onDoubleClick(event) {
13081316
if (
1309-
isFlagActive &&
1317+
isLPEditFeaturesActive &&
13101318
event.target.hasAttribute("data-brackets-id") &&
13111319
event.target.tagName !== "BODY" &&
13121320
event.target.tagName !== "HTML"
@@ -1778,7 +1786,8 @@ function RemoteFunctions(config) {
17781786

17791787
// Function to handle direct editing of elements in the live preview
17801788
function startEditing(element) {
1781-
if (!element
1789+
if (!isLPEditFeaturesActive
1790+
|| !element
17821791
|| element.tagName === "BODY"
17831792
|| element.tagName === "HTML"
17841793
|| !element.hasAttribute("data-brackets-id")) {
@@ -1826,7 +1835,7 @@ function RemoteFunctions(config) {
18261835
// Function to finish editing and apply changes
18271836
// isEditSuccessful: this is a boolean value, defaults to true. false only when the edit operation is cancelled
18281837
function finishEditing(element, isEditSuccessful = true) {
1829-
if (!element || !element.hasAttribute("contenteditable")) {
1838+
if (!isLPEditFeaturesActive || !element || !element.hasAttribute("contenteditable")) {
18301839
return;
18311840
}
18321841

@@ -1857,20 +1866,22 @@ function RemoteFunctions(config) {
18571866
// init
18581867
_editHandler = new DOMEditHandler(window.document);
18591868

1860-
// Initialize hover highlight with Chrome-like colors
1861-
_hoverHighlight = new Highlight("#c8f9c5", true); // Green similar to Chrome's padding color
1869+
if (isLPEditFeaturesActive) {
1870+
// Initialize hover highlight with Chrome-like colors
1871+
_hoverHighlight = new Highlight("#c8f9c5", true); // Green similar to Chrome's padding color
1872+
1873+
// Initialize click highlight with animation
1874+
_clickHighlight = new Highlight("#cfc", true); // Light green for click highlight
18621875

1863-
// Initialize click highlight with animation
1864-
_clickHighlight = new Highlight("#cfc", true); // Light green for click highlight
1876+
window.document.addEventListener("mouseover", onElementHover);
1877+
window.document.addEventListener("mouseout", onElementHoverOut);
1878+
window.document.addEventListener("click", onClick);
1879+
window.document.addEventListener("dblclick", onDoubleClick);
1880+
window.document.addEventListener("dragover", onDragOver);
1881+
window.document.addEventListener("drop", onDrop);
1882+
window.document.addEventListener("keydown", onKeyDown);
1883+
}
18651884

1866-
// Add event listeners for hover
1867-
window.document.addEventListener("mouseover", onElementHover);
1868-
window.document.addEventListener("mouseout", onElementHoverOut);
1869-
window.document.addEventListener("click", onClick);
1870-
window.document.addEventListener("dblclick", onDoubleClick);
1871-
window.document.addEventListener("dragover", onDragOver);
1872-
window.document.addEventListener("drop", onDrop);
1873-
window.document.addEventListener("keydown", onKeyDown);
18741885

18751886
return {
18761887
"DOMEditHandler" : DOMEditHandler,

0 commit comments

Comments
 (0)