Skip to content

Commit 317b9be

Browse files
committed
refactor: clean up code to fix all eslint issues
1 parent 90c043d commit 317b9be

File tree

1 file changed

+35
-19
lines changed

1 file changed

+35
-19
lines changed

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020
*/
2121

2222
/*jslint forin: true */
23-
/*global Node, MessageEvent*/
2423
/*theseus instrument: false */
2524

2625
/**
2726
* RemoteFunctions define the functions to be executed in the browser. This
2827
* modules should define a single function that returns an object of all
2928
* exported functions.
3029
*/
30+
// eslint-disable-next-line no-unused-vars
3131
function RemoteFunctions(config = {}) {
3232
const GLOBALS = {
3333
// given to internal elements like info box, options box, image gallery and all other phcode internal elements
@@ -133,7 +133,8 @@ function RemoteFunctions(config = {}) {
133133
if(element && // element should exist
134134
element.tagName.toLowerCase() !== "body" && // shouldn't be the body tag
135135
element.tagName.toLowerCase() !== "html" && // shouldn't be the HTML tag
136-
!element.closest(`[${GLOBALS.PHCODE_INTERNAL_ATTR}]`) && // this attribute is used by phoenix internal elements
136+
// this attribute is used by phoenix internal elements
137+
!element.closest(`[${GLOBALS.PHCODE_INTERNAL_ATTR}]`) &&
137138
!_isInsideHeadTag(element)) { // shouldn't be inside the head tag like meta tags and all
138139
return true;
139140
}
@@ -1032,12 +1033,12 @@ function RemoteFunctions(config = {}) {
10321033
showPaddingMargin: true
10331034
};
10341035
var elementBounds = element.getBoundingClientRect(),
1035-
highlight = window.document.createElement("div"),
1036+
highlightDiv = window.document.createElement("div"),
10361037
elementStyling = window.getComputedStyle(element),
10371038
transitionDuration = parseFloat(elementStyling.getPropertyValue('transition-duration')),
10381039
animationDuration = parseFloat(elementStyling.getPropertyValue('animation-duration'));
10391040

1040-
highlight.trackingElement = element; // save which node are we highlighting
1041+
highlightDiv.trackingElement = element; // save which node are we highlighting
10411042

10421043
if (doAnimation) {
10431044
if (transitionDuration) {
@@ -1162,19 +1163,19 @@ function RemoteFunctions(config = {}) {
11621163
drawMarginRect("left")
11631164
];
11641165

1165-
var setupVisualisations = function (arr, config) {
1166+
var setupVisualisations = function (arr, visualConfig) {
11661167
var i;
11671168
for (i = 0; i < arr.length; i++) {
11681169
setVisibility(arr[i]);
11691170

11701171
// Applies to every visualisationElement (padding or margin div)
11711172
arr[i]["transform"] = "none";
11721173
var el = window.document.createElement("div"),
1173-
styles = Object.assign({}, config, arr[i]);
1174+
styles = Object.assign({}, visualConfig, arr[i]);
11741175

11751176
_setStyleValues(styles, el.style);
11761177

1177-
highlight.appendChild(el);
1178+
highlightDiv.appendChild(el);
11781179
}
11791180
};
11801181

@@ -1187,7 +1188,7 @@ function RemoteFunctions(config = {}) {
11871188
remoteHighlight.paddingStyling
11881189
);
11891190

1190-
highlight.className = GLOBALS.HIGHLIGHT_CLASSNAME;
1191+
highlightDiv.className = GLOBALS.HIGHLIGHT_CLASSNAME;
11911192

11921193
var offset = LivePreviewView.screenOffset(element);
11931194

@@ -1236,22 +1237,22 @@ function RemoteFunctions(config = {}) {
12361237
}
12371238
}
12381239

1239-
_setStyleValues(mergedStyles, highlight.style);
1240+
_setStyleValues(mergedStyles, highlightDiv.style);
12401241
_setStyleValues(
12411242
doAnimation ? animateStartValues : animateEndValues,
1242-
highlight.style
1243+
highlightDiv.style
12431244
);
12441245

12451246

12461247
if (doAnimation) {
1247-
_setStyleValues(transitionValues, highlight.style);
1248+
_setStyleValues(transitionValues, highlightDiv.style);
12481249

12491250
window.setTimeout(function () {
1250-
_setStyleValues(animateEndValues, highlight.style);
1251+
_setStyleValues(animateEndValues, highlightDiv.style);
12511252
}, 20);
12521253
}
12531254

1254-
window.document.body.appendChild(highlight);
1255+
window.document.body.appendChild(highlightDiv);
12551256
},
12561257

12571258
add: function (element, doAnimation) {
@@ -1805,10 +1806,14 @@ function RemoteFunctions(config = {}) {
18051806
/**
18061807
* @private
18071808
* @param {Node} node
1808-
* @return {boolean} true if node expects its content to be raw text (not parsed for entities) according to the HTML5 spec.
1809+
* @return {boolean} true if node expects its content to be
1810+
* raw text (not parsed for entities) according to the HTML5 spec.
18091811
*/
18101812
function _isRawTextNode(node) {
1811-
return (node.nodeType === Node.ELEMENT_NODE && /script|style|noscript|noframes|noembed|iframe|xmp/i.test(node.tagName));
1813+
return (
1814+
node.nodeType === Node.ELEMENT_NODE &&
1815+
/script|style|noscript|noframes|noembed|iframe|xmp/i.test(node.tagName)
1816+
);
18121817
}
18131818

18141819
/**
@@ -1843,9 +1848,17 @@ function RemoteFunctions(config = {}) {
18431848
end = (edit.beforeID) ? this._queryBracketsID(edit.beforeID) : null,
18441849
endMissing = edit.beforeID && !end,
18451850
moveNext = start && nextIgnoringHighlights(start),
1846-
current = moveNext || (end && prevIgnoringHighlights(end)) || lastChildIgnoringHighlights(targetElement),
1851+
1852+
current = moveNext ||
1853+
(end && prevIgnoringHighlights(end)) || lastChildIgnoringHighlights(targetElement),
1854+
18471855
next,
1848-
textNode = (edit.content !== undefined) ? this.htmlDocument.createTextNode(_isRawTextNode(targetElement) ? edit.content : this._parseEntities(edit.content)) : null,
1856+
1857+
textNode = (edit.content !== undefined) ?
1858+
this.htmlDocument.createTextNode(
1859+
_isRawTextNode(targetElement) ? edit.content : this._parseEntities(edit.content)
1860+
) : null,
1861+
18491862
lastRemovedWasText,
18501863
isText;
18511864

@@ -1902,7 +1915,8 @@ function RemoteFunctions(config = {}) {
19021915
this.rememberedNodes = {};
19031916

19041917
edits.forEach(function (edit) {
1905-
var editIsSpecialTag = edit.type === "elementInsert" && (edit.tag === "html" || edit.tag === "head" || edit.tag === "body");
1918+
var editIsSpecialTag = edit.type === "elementInsert" &&
1919+
(edit.tag === "html" || edit.tag === "head" || edit.tag === "body");
19061920

19071921
if (edit.type === "rememberNodes") {
19081922
edit.tagIDs.forEach(function (tagID) {
@@ -1979,7 +1993,9 @@ function RemoteFunctions(config = {}) {
19791993
self._insertChildNode(targetElement, childElement, edit);
19801994
break;
19811995
case "textInsert":
1982-
var textElement = self.htmlDocument.createTextNode(_isRawTextNode(targetElement) ? edit.content : self._parseEntities(edit.content));
1996+
var textElement = self.htmlDocument.createTextNode(
1997+
_isRawTextNode(targetElement) ? edit.content : self._parseEntities(edit.content)
1998+
);
19831999
self._insertChildNode(targetElement, textElement, edit);
19842000
break;
19852001
case "textReplace":

0 commit comments

Comments
 (0)