Skip to content

Commit

Permalink
Help Button : Javascript editor sugarlabs#3573
Browse files Browse the repository at this point in the history
  • Loading branch information
JanhaviAlekar committed Jan 11, 2024
1 parent 3624371 commit f6ad4ef
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions js/widgets/jseditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,18 @@ class JSEditor {
this._code = JSGenerate.code;
this._jar.updateCode(this._code);
this._setLinesCount(this._code);
}

this._resetHelpButtonColor();
}
_resetHelpButtonColor() {
const helpBtn = docById("js_editor_help_btn");
if (helpBtn) {
// Always set the help button color to white when generating code
helpBtn.style.color = "white";
} else {
console.warn("Help button not found in the DOM.");
}
}
/**
* Refreshes the line numbers by the code in the editor.
*
Expand All @@ -403,21 +413,29 @@ class JSEditor {
* @returns {void}
*/
_toggleHelp() {
this._showingHelp = !this._showingHelp;
const helpBtn = docById("js_editor_help_btn");

if (this._showingHelp) {
helpBtn.style.color = "gold";
this._codeBck = this._code;
this._jar.updateCode(JS_API);
this._setLinesCount(JS_API);

if (helpBtn) {

helpBtn.style.color = (helpBtn.style.color === "gold") ? "white" : "gold";
this._showingHelp = (helpBtn.style.color === "gold");

if (this._showingHelp) {

this._codeBck = this._code;
this._jar.updateCode(JS_API);
this._setLinesCount(JS_API);
} else {

this._jar.updateCode(this._codeBck);
this._setLinesCount(this._codeBck);
this._code = this._codeBck;
}
} else {
helpBtn.style.color = "white";
this._jar.updateCode(this._codeBck);
this._setLinesCount(this._codeBck);
this._code = this._codeBck;
console.warn("Help button not found in the DOM.");
}
}


/**
* Triggered when the "change-style" button is pressed.
Expand Down

0 comments on commit f6ad4ef

Please sign in to comment.