Skip to content

Commit

Permalink
Fix linting problems and format
Browse files Browse the repository at this point in the history
* Prettify jseditor.js

* Linting jseditor.js

* Fixed Error

* Fix linting warnings

* Remove console spam

Co-authored-by: Anindya Kundu <[email protected]>
  • Loading branch information
daksh4469 and meganindya authored Feb 5, 2021
1 parent 35fe116 commit 42dbb7f
Showing 1 changed file with 27 additions and 35 deletions.
62 changes: 27 additions & 35 deletions js/widgets/jseditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* You should have received a copy of the GNU Affero General Public License along with this
* library; if not, write to the Free Software Foundation, 51 Franklin Street, Suite 500 Boston,
* MA 02110-1335 USA.
*/
*/

/**
* @class
Expand All @@ -21,6 +21,11 @@
*
* Private members' names begin with underscore '_".
*/

/* global docById, MusicBlocks, hljs, CodeJar, JSGenerate, JS_API */

/* exported JSEditor */

class JSEditor {
/**
* @constructor
Expand All @@ -29,8 +34,11 @@ class JSEditor {
this.isOpen = true;
this._showingHelp = false;

this.widgetWindow =
window.widgetWindows.windowFor(this, "JavaScript Editor", "JavaScript Editor");
this.widgetWindow = window.widgetWindows.windowFor(
this,
"JavaScript Editor",
"JavaScript Editor"
);
this.widgetWindow.clear();
this.widgetWindow.show();
this.widgetWindow.setPosition(160, 132);
Expand All @@ -47,12 +55,7 @@ class JSEditor {

// setup editor window styles
this._currentStyle = 0;
this._styles = [
"dracula",
"github",
"railscasts",
"vs",
].map((name) => {
this._styles = ["dracula", "github", "railscasts", "vs"].map((name) => {
const link = document.createElement("link");
link.href = `././lib/codejar/styles/${name}.min.css`;
link.rel = "stylesheet";
Expand All @@ -75,10 +78,9 @@ class JSEditor {
this.widgetWindow.onmaximize = () => {
const editor = this.widgetWindow.getWidgetBody().childNodes[0];
editor.style.width = this.widgetWindow._maximized ? "100%" : "39rem";
editor.style.height =
this.widgetWindow._maximized ?
`calc(100vh - ${64 + 33}px` :
`${docById("overlayCanvas").height - 33 - 128 - 12}px`;
editor.style.height = this.widgetWindow._maximized
? `calc(100vh - ${64 + 33}px`
: `${docById("overlayCanvas").height - 33 - 128 - 12}px`;
};

this._editor.style.width = "39rem";
Expand Down Expand Up @@ -249,7 +251,7 @@ class JSEditor {
this._editor.appendChild(editorconsole);

const highlight = (editor) => {
editor.textContent = editor.textContent;
// editor.textContent = editor.textContent;
hljs.highlightBlock(editor);
};

Expand All @@ -261,13 +263,12 @@ class JSEditor {
this._jar.updateCode(this._code);
this._jar.updateOptions({
tab: " ".repeat(4), // default is '\t'
indentOn: /[(\[]$/, // default is /{$/
spellcheck: false, // default is false
addClosing: true // default is true
indentOn: /[(]$/, // default is /{$/
spellcheck: false, // default is false
addClosing: true // default is true
});
this._jar.onUpdate(code => {
if (!this._showingHelp)
this._code = code;
this._jar.onUpdate((code) => {
if (!this._showingHelp) this._code = code;
this._setLinesCount(this._code);
});

Expand All @@ -285,15 +286,15 @@ class JSEditor {
* @returns {void}
*/
static logConsole(message, color) {
if (color === undefined)
color = "midnightblue";
if (color === undefined) color = "midnightblue";
if (docById("editorConsole")) {
if (docById("editorConsole").innerHTML !== "")
docById("editorConsole").innerHTML += "</br>";
docById("editorConsole").innerHTML += `<span style="color: ${color}">${message}</span>`;
} else {
console.error("EDITOR MISSING!");
// console.error("EDITOR MISSING!");
}
// eslint-disable-next-line
console.log("%c" + message, `color: ${color}`);
}

Expand All @@ -304,13 +305,9 @@ class JSEditor {
* @returns {void}
*/
_runCode() {
if (this._showingHelp)
return;

if (docById("editorConsole"))
docById("editorConsole").innerHTML = "";
if (this._showingHelp) return;

console.debug("Run JavaScript");
if (docById("editorConsole")) docById("editorConsole").innerHTML = "";

try {
MusicBlocks.init(true);
Expand All @@ -327,8 +324,6 @@ class JSEditor {
* @returns {void}
*/
_generateCode() {
console.debug("Generate JavaScript");

JSGenerate.run(true);
this._code = JSGenerate.code;
this._jar.updateCode(this._code);
Expand All @@ -342,8 +337,7 @@ class JSEditor {
* @returns {void}
*/
_setLinesCount(code) {
if (!docById("editorLines"))
return;
if (!docById("editorLines")) return;

const linesCount = code.replace(/\n+$/, "\n").split("\n").length + 1;
let text = "";
Expand All @@ -364,13 +358,11 @@ class JSEditor {
const helpBtn = docById("js_editor_help_btn");

if (this._showingHelp) {
console.debug("Showing Help");
helpBtn.style.color = "gold";
this._codeBck = this._code;
this._jar.updateCode(JS_API);
this._setLinesCount(JS_API);
} else {
console.debug("Hiding Help");
helpBtn.style.color = "white";
this._jar.updateCode(this._codeBck);
this._setLinesCount(this._codeBck);
Expand Down

0 comments on commit 42dbb7f

Please sign in to comment.