Skip to content

Commit

Permalink
Make all refs to window->this.window & document->this.document for us…
Browse files Browse the repository at this point in the history
…e with jsDom. Remove console.log
  • Loading branch information
TotallyInformation committed Jul 7, 2024
1 parent 2b329b9 commit 03ed162
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 96 deletions.
26 changes: 12 additions & 14 deletions front-end/ui.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var require_ui = __commonJS({
if (jsonHighlight) this.syntaxHighlight = jsonHighlight;
else this.syntaxHighlight = function() {
};
if (window["markdownit"]) {
if (this.window["markdownit"]) {
_a.mdOpts = {
html: true,
xhtmlOut: false,
Expand All @@ -62,12 +62,12 @@ var require_ui = __commonJS({
return `<pre class="hljs border"><code>${_a.md.utils.escapeHtml(str).trim()}</code></pre>`;
}
};
_a.md = window["markdownit"](_a.mdOpts);
_a.md = this.window["markdownit"](_a.mdOpts);
}
}
//#region ---- Internal Methods ----
_markDownIt() {
if (!window["markdownit"]) return;
if (!this.window["markdownit"]) return;
if (!this.ui_md_plugins && this.window["uibuilder"] && this.window["uibuilder"].ui_md_plugins) this.ui_md_plugins = this.window["uibuilder"].ui_md_plugins;
_a.mdOpts = {
html: true,
Expand Down Expand Up @@ -96,7 +96,7 @@ var require_ui = __commonJS({
return `<pre><code class="border">${_a.md.utils.escapeHtml(str).trim()}</code></pre>`;
}
};
_a.md = window["markdownit"](_a.mdOpts);
_a.md = this.window["markdownit"](_a.mdOpts);
if (this.ui_md_plugins) {
if (!Array.isArray(this.ui_md_plugins)) {
_a.log("error", "Ui:_markDownIt:plugins", "Could not load plugins, ui_md_plugins is not an array")();
Expand Down Expand Up @@ -522,7 +522,7 @@ var require_ui = __commonJS({
* @returns {HTMLElement|null} Selected HTML element or null
*/
$(cssSelector) {
let el = document.querySelector(cssSelector);
let el = this.document.querySelector(cssSelector);
if (!el) {
_a.log(1, "Uib:$", `No element found for CSS selector ${cssSelector}`)();
return null;
Expand All @@ -542,7 +542,7 @@ var require_ui = __commonJS({
* @returns {HTMLElement[]} Array of DOM elements/nodes. Array is empty if selector is not found.
*/
$$(cssSelector) {
return Array.from(document.querySelectorAll(cssSelector));
return Array.from(this.document.querySelectorAll(cssSelector));
}
/** Add 1 or several class names to an element
* @param {string|string[]} classNames Single or array of classnames
Expand All @@ -565,21 +565,20 @@ var require_ui = __commonJS({
*/
applyTemplate(sourceId, targetId, config) {
if (!config) config = { onceOnly: false };
const template = document.getElementById(sourceId);
const target = document.getElementById(targetId);
const template = this.document.getElementById(sourceId);
const target = this.document.getElementById(targetId);
if (template && target) {
let content;
try {
if (config.onceOnly !== true) content = document.importNode(template.content, true);
else content = document.adoptNode(template.content);
if (config.onceOnly !== true) content = this.document.importNode(template.content, true);
else content = this.document.adoptNode(template.content);
} catch (e) {
_a.log("error", "Ui:applyTemplate", `Source must be a <template>. id='${sourceId}'`)();
return;
}
if (content) {
if (config.attributes) {
const el = content.firstElementChild;
console.log(el, content);
Object.keys(config.attributes).forEach((attrib) => {
el.setAttribute(attrib, config.attributes[attrib]);
});
Expand Down Expand Up @@ -922,8 +921,8 @@ var require_ui = __commonJS({
if (!el) return;
if (!slot) slot = "";
slot = this.sanitiseHTML(slot);
const tempFrag = document.createRange().createContextualFragment(slot);
const elRange = document.createRange();
const tempFrag = this.document.createRange().createContextualFragment(slot);
const elRange = this.document.createRange();
elRange.selectNodeContents(el);
elRange.deleteContents();
el.append(tempFrag);
Expand Down Expand Up @@ -1023,7 +1022,6 @@ var require_ui = __commonJS({
let msg = {};
if (json._ui) msg = json;
else msg._ui = json;
console.log(this);
this._uiManager(msg);
}
/** Get data from the DOM. Returns selection of useful props unless a specific prop requested.
Expand Down
2 changes: 1 addition & 1 deletion front-end/ui.esm.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions front-end/ui.esm.min.js.map

Large diffs are not rendered by default.

26 changes: 12 additions & 14 deletions front-end/ui.iife.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
if (jsonHighlight) this.syntaxHighlight = jsonHighlight;
else this.syntaxHighlight = function() {
};
if (window["markdownit"]) {
if (this.window["markdownit"]) {
_a.mdOpts = {
html: true,
xhtmlOut: false,
Expand All @@ -63,12 +63,12 @@
return `<pre class="hljs border"><code>${_a.md.utils.escapeHtml(str).trim()}</code></pre>`;
}
};
_a.md = window["markdownit"](_a.mdOpts);
_a.md = this.window["markdownit"](_a.mdOpts);
}
}
//#region ---- Internal Methods ----
_markDownIt() {
if (!window["markdownit"]) return;
if (!this.window["markdownit"]) return;
if (!this.ui_md_plugins && this.window["uibuilder"] && this.window["uibuilder"].ui_md_plugins) this.ui_md_plugins = this.window["uibuilder"].ui_md_plugins;
_a.mdOpts = {
html: true,
Expand Down Expand Up @@ -97,7 +97,7 @@
return `<pre><code class="border">${_a.md.utils.escapeHtml(str).trim()}</code></pre>`;
}
};
_a.md = window["markdownit"](_a.mdOpts);
_a.md = this.window["markdownit"](_a.mdOpts);
if (this.ui_md_plugins) {
if (!Array.isArray(this.ui_md_plugins)) {
_a.log("error", "Ui:_markDownIt:plugins", "Could not load plugins, ui_md_plugins is not an array")();
Expand Down Expand Up @@ -523,7 +523,7 @@
* @returns {HTMLElement|null} Selected HTML element or null
*/
$(cssSelector) {
let el = document.querySelector(cssSelector);
let el = this.document.querySelector(cssSelector);
if (!el) {
_a.log(1, "Uib:$", `No element found for CSS selector ${cssSelector}`)();
return null;
Expand All @@ -543,7 +543,7 @@
* @returns {HTMLElement[]} Array of DOM elements/nodes. Array is empty if selector is not found.
*/
$$(cssSelector) {
return Array.from(document.querySelectorAll(cssSelector));
return Array.from(this.document.querySelectorAll(cssSelector));
}
/** Add 1 or several class names to an element
* @param {string|string[]} classNames Single or array of classnames
Expand All @@ -566,21 +566,20 @@
*/
applyTemplate(sourceId, targetId, config) {
if (!config) config = { onceOnly: false };
const template = document.getElementById(sourceId);
const target = document.getElementById(targetId);
const template = this.document.getElementById(sourceId);
const target = this.document.getElementById(targetId);
if (template && target) {
let content;
try {
if (config.onceOnly !== true) content = document.importNode(template.content, true);
else content = document.adoptNode(template.content);
if (config.onceOnly !== true) content = this.document.importNode(template.content, true);
else content = this.document.adoptNode(template.content);
} catch (e) {
_a.log("error", "Ui:applyTemplate", `Source must be a <template>. id='${sourceId}'`)();
return;
}
if (content) {
if (config.attributes) {
const el = content.firstElementChild;
console.log(el, content);
Object.keys(config.attributes).forEach((attrib) => {
el.setAttribute(attrib, config.attributes[attrib]);
});
Expand Down Expand Up @@ -923,8 +922,8 @@
if (!el) return;
if (!slot) slot = "";
slot = this.sanitiseHTML(slot);
const tempFrag = document.createRange().createContextualFragment(slot);
const elRange = document.createRange();
const tempFrag = this.document.createRange().createContextualFragment(slot);
const elRange = this.document.createRange();
elRange.selectNodeContents(el);
elRange.deleteContents();
el.append(tempFrag);
Expand Down Expand Up @@ -1024,7 +1023,6 @@
let msg = {};
if (json._ui) msg = json;
else msg._ui = json;
console.log(this);
this._uiManager(msg);
}
/** Get data from the DOM. Returns selection of useful props unless a specific prop requested.
Expand Down
2 changes: 1 addition & 1 deletion front-end/ui.iife.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions front-end/ui.iife.min.js.map

Large diffs are not rendered by default.

26 changes: 12 additions & 14 deletions front-end/uibuilder.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ var require_ui = __commonJS({
if (jsonHighlight) this.syntaxHighlight = jsonHighlight;
else this.syntaxHighlight = function() {
};
if (window["markdownit"]) {
if (this.window["markdownit"]) {
_a2.mdOpts = {
html: true,
xhtmlOut: false,
Expand All @@ -101,12 +101,12 @@ var require_ui = __commonJS({
return `<pre class="hljs border"><code>${_a2.md.utils.escapeHtml(str).trim()}</code></pre>`;
}
};
_a2.md = window["markdownit"](_a2.mdOpts);
_a2.md = this.window["markdownit"](_a2.mdOpts);
}
}
//#region ---- Internal Methods ----
_markDownIt() {
if (!window["markdownit"]) return;
if (!this.window["markdownit"]) return;
if (!this.ui_md_plugins && this.window["uibuilder"] && this.window["uibuilder"].ui_md_plugins) this.ui_md_plugins = this.window["uibuilder"].ui_md_plugins;
_a2.mdOpts = {
html: true,
Expand Down Expand Up @@ -135,7 +135,7 @@ var require_ui = __commonJS({
return `<pre><code class="border">${_a2.md.utils.escapeHtml(str).trim()}</code></pre>`;
}
};
_a2.md = window["markdownit"](_a2.mdOpts);
_a2.md = this.window["markdownit"](_a2.mdOpts);
if (this.ui_md_plugins) {
if (!Array.isArray(this.ui_md_plugins)) {
_a2.log("error", "Ui:_markDownIt:plugins", "Could not load plugins, ui_md_plugins is not an array")();
Expand Down Expand Up @@ -561,7 +561,7 @@ var require_ui = __commonJS({
* @returns {HTMLElement|null} Selected HTML element or null
*/
$(cssSelector) {
let el = document.querySelector(cssSelector);
let el = this.document.querySelector(cssSelector);
if (!el) {
_a2.log(1, "Uib:$", `No element found for CSS selector ${cssSelector}`)();
return null;
Expand All @@ -581,7 +581,7 @@ var require_ui = __commonJS({
* @returns {HTMLElement[]} Array of DOM elements/nodes. Array is empty if selector is not found.
*/
$$(cssSelector) {
return Array.from(document.querySelectorAll(cssSelector));
return Array.from(this.document.querySelectorAll(cssSelector));
}
/** Add 1 or several class names to an element
* @param {string|string[]} classNames Single or array of classnames
Expand All @@ -604,21 +604,20 @@ var require_ui = __commonJS({
*/
applyTemplate(sourceId, targetId, config) {
if (!config) config = { onceOnly: false };
const template = document.getElementById(sourceId);
const target = document.getElementById(targetId);
const template = this.document.getElementById(sourceId);
const target = this.document.getElementById(targetId);
if (template && target) {
let content;
try {
if (config.onceOnly !== true) content = document.importNode(template.content, true);
else content = document.adoptNode(template.content);
if (config.onceOnly !== true) content = this.document.importNode(template.content, true);
else content = this.document.adoptNode(template.content);
} catch (e) {
_a2.log("error", "Ui:applyTemplate", `Source must be a <template>. id='${sourceId}'`)();
return;
}
if (content) {
if (config.attributes) {
const el = content.firstElementChild;
console.log(el, content);
Object.keys(config.attributes).forEach((attrib) => {
el.setAttribute(attrib, config.attributes[attrib]);
});
Expand Down Expand Up @@ -961,8 +960,8 @@ var require_ui = __commonJS({
if (!el) return;
if (!slot) slot = "";
slot = this.sanitiseHTML(slot);
const tempFrag = document.createRange().createContextualFragment(slot);
const elRange = document.createRange();
const tempFrag = this.document.createRange().createContextualFragment(slot);
const elRange = this.document.createRange();
elRange.selectNodeContents(el);
elRange.deleteContents();
el.append(tempFrag);
Expand Down Expand Up @@ -1062,7 +1061,6 @@ var require_ui = __commonJS({
let msg = {};
if (json._ui) msg = json;
else msg._ui = json;
console.log(this);
this._uiManager(msg);
}
/** Get data from the DOM. Returns selection of useful props unless a specific prop requested.
Expand Down
2 changes: 1 addition & 1 deletion front-end/uibuilder.esm.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions front-end/uibuilder.esm.min.js.map

Large diffs are not rendered by default.

26 changes: 12 additions & 14 deletions front-end/uibuilder.iife.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
if (jsonHighlight) this.syntaxHighlight = jsonHighlight;
else this.syntaxHighlight = function() {
};
if (window["markdownit"]) {
if (this.window["markdownit"]) {
_a2.mdOpts = {
html: true,
xhtmlOut: false,
Expand All @@ -102,12 +102,12 @@
return `<pre class="hljs border"><code>${_a2.md.utils.escapeHtml(str).trim()}</code></pre>`;
}
};
_a2.md = window["markdownit"](_a2.mdOpts);
_a2.md = this.window["markdownit"](_a2.mdOpts);
}
}
//#region ---- Internal Methods ----
_markDownIt() {
if (!window["markdownit"]) return;
if (!this.window["markdownit"]) return;
if (!this.ui_md_plugins && this.window["uibuilder"] && this.window["uibuilder"].ui_md_plugins) this.ui_md_plugins = this.window["uibuilder"].ui_md_plugins;
_a2.mdOpts = {
html: true,
Expand Down Expand Up @@ -136,7 +136,7 @@
return `<pre><code class="border">${_a2.md.utils.escapeHtml(str).trim()}</code></pre>`;
}
};
_a2.md = window["markdownit"](_a2.mdOpts);
_a2.md = this.window["markdownit"](_a2.mdOpts);
if (this.ui_md_plugins) {
if (!Array.isArray(this.ui_md_plugins)) {
_a2.log("error", "Ui:_markDownIt:plugins", "Could not load plugins, ui_md_plugins is not an array")();
Expand Down Expand Up @@ -562,7 +562,7 @@
* @returns {HTMLElement|null} Selected HTML element or null
*/
$(cssSelector) {
let el = document.querySelector(cssSelector);
let el = this.document.querySelector(cssSelector);
if (!el) {
_a2.log(1, "Uib:$", `No element found for CSS selector ${cssSelector}`)();
return null;
Expand All @@ -582,7 +582,7 @@
* @returns {HTMLElement[]} Array of DOM elements/nodes. Array is empty if selector is not found.
*/
$$(cssSelector) {
return Array.from(document.querySelectorAll(cssSelector));
return Array.from(this.document.querySelectorAll(cssSelector));
}
/** Add 1 or several class names to an element
* @param {string|string[]} classNames Single or array of classnames
Expand All @@ -605,21 +605,20 @@
*/
applyTemplate(sourceId, targetId, config) {
if (!config) config = { onceOnly: false };
const template = document.getElementById(sourceId);
const target = document.getElementById(targetId);
const template = this.document.getElementById(sourceId);
const target = this.document.getElementById(targetId);
if (template && target) {
let content;
try {
if (config.onceOnly !== true) content = document.importNode(template.content, true);
else content = document.adoptNode(template.content);
if (config.onceOnly !== true) content = this.document.importNode(template.content, true);
else content = this.document.adoptNode(template.content);
} catch (e) {
_a2.log("error", "Ui:applyTemplate", `Source must be a <template>. id='${sourceId}'`)();
return;
}
if (content) {
if (config.attributes) {
const el = content.firstElementChild;
console.log(el, content);
Object.keys(config.attributes).forEach((attrib) => {
el.setAttribute(attrib, config.attributes[attrib]);
});
Expand Down Expand Up @@ -962,8 +961,8 @@
if (!el) return;
if (!slot) slot = "";
slot = this.sanitiseHTML(slot);
const tempFrag = document.createRange().createContextualFragment(slot);
const elRange = document.createRange();
const tempFrag = this.document.createRange().createContextualFragment(slot);
const elRange = this.document.createRange();
elRange.selectNodeContents(el);
elRange.deleteContents();
el.append(tempFrag);
Expand Down Expand Up @@ -1063,7 +1062,6 @@
let msg = {};
if (json._ui) msg = json;
else msg._ui = json;
console.log(this);
this._uiManager(msg);
}
/** Get data from the DOM. Returns selection of useful props unless a specific prop requested.
Expand Down
2 changes: 1 addition & 1 deletion front-end/uibuilder.iife.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions front-end/uibuilder.iife.min.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit 03ed162

Please sign in to comment.