Skip to content

Commit

Permalink
widgets/help - fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ksraj123 committed Jan 23, 2021
1 parent 80da1d2 commit a4b194f
Showing 1 changed file with 67 additions and 48 deletions.
115 changes: 67 additions & 48 deletions js/widgets/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@

// This widget displays help about a block or a button.

/*global _, docById, getMacroExpansion, HELPCONTENT*/

/*
Globals locations
- js/utils/utils.js
_, docById
- js/macros.js
getMacroExpansion
- js/turtledefs.js
HELPCONTENT
*/

class HelpWidget {
static ICONSIZE = 32;

Expand All @@ -20,7 +35,7 @@ class HelpWidget {
this.index = 0;
this.isOpen = true;

let widgetWindow = window.widgetWindows.windowFor(this, "help", "help");
const widgetWindow = window.widgetWindows.windowFor(this, "help", "help");
widgetWindow.getWidgetBody().style.overflowY = "auto";
// const canvasHeight = docById("myCanvas").getBoundingClientRect().height;
widgetWindow.getWidgetBody().style.maxHeight = "500px";
Expand All @@ -42,7 +57,7 @@ class HelpWidget {
}

_setup(blocks) {
let iconSize = HelpWidget.ICONSIZE;
const iconSize = HelpWidget.ICONSIZE;
// Which help page are we on?
let page = 0;

Expand Down Expand Up @@ -89,7 +104,7 @@ class HelpWidget {
};
} else {
if (blocks.activeBlock.name !== null) {
let label = blocks.blockList[blocks.activeBlock].protoblock.staticLabels[0];
const label = blocks.blockList[blocks.activeBlock].protoblock.staticLabels[0];
this.widgetWindow.updateTitle(_(label));
}

Expand All @@ -110,9 +125,9 @@ class HelpWidget {
} else {
// display help for this block
if (blocks.activeBlock.name !== null) {
let name = blocks.blockList[blocks.activeBlock].name;
const name = blocks.blockList[blocks.activeBlock].name;

let advIcon =
const advIcon =
'<a\
class="tooltipped"\
data-toggle="tooltip"\
Expand All @@ -125,7 +140,7 @@ class HelpWidget {
></a\
>';

let findIcon =
const findIcon =
'<a\
class="tooltipped"\
data-toggle="tooltip"\
Expand All @@ -139,16 +154,14 @@ class HelpWidget {
></a\
>';

let showPaletteParamater =
blocks.blockList[blocks.activeBlock].protoblock.palette.name;
// Each block's help entry contains a help string, the
// path of the help svg, an override name for the help
// svg file, and an optional macro name for generating
// the help output.
let message = blocks.blockList[blocks.activeBlock].protoblock.helpString;
const message = blocks.blockList[blocks.activeBlock].protoblock.helpString;

if (message) {
let helpBody = docById("helpBodyDiv");
const helpBody = docById("helpBodyDiv");
helpBody.style.height = "";

let body = "";
Expand Down Expand Up @@ -195,20 +208,23 @@ class HelpWidget {
helpBody.innerHTML += advIcon;
}

let object = blocks.palettes.getProtoNameAndPalette(name);
const object = blocks.palettes.getProtoNameAndPalette(name);

let loadButton = docById("loadButton");
const loadButton = docById("loadButton");
if (loadButton !== null) {
loadButton.onclick = () => {
if (message.length < 4) {
// If there is nothing specified, just load the block.
console.debug("CLICK: " + name);
// console.debug("CLICK: " + name);

let protoblk = object[0];
let paletteName = object[1];
let protoName = object[2];
const protoblk = object[0];
const paletteName = object[1];
const protoName = object[2];

let protoResult = blocks.protoBlockDict.hasOwnProperty(protoName);
const protoResult = Object.prototype.hasOwnProperty.call(
blocks.protoBlockDict,
protoName
);
if (protoResult) {
blocks.palettes.dict[paletteName].makeBlockFromSearch(
protoblk,
Expand All @@ -221,18 +237,18 @@ class HelpWidget {
} else if (typeof message[3] === "string") {
// If it is a string, load the macro
// assocuated with this block
let blocksToLoad = getMacroExpansion(message[3], 100, 100);
console.debug("CLICK: " + blocksToLoad);
const blocksToLoad = getMacroExpansion(message[3], 100, 100);
// console.debug("CLICK: " + blocksToLoad);
blocks.loadNewBlocks(blocksToLoad);
} else {
// Load the blocks.
let blocksToLoad = message[3];
console.debug("CLICK: " + blocksToLoad);
const blocksToLoad = message[3];
// console.debug("CLICK: " + blocksToLoad);
blocks.loadNewBlocks(blocksToLoad);
}
};
}
let findIconMethod = docById("findIcon");
const findIconMethod = docById("findIcon");

findIconMethod.onclick = () => {
blocks.palettes.showPalette(object[1]);
Expand All @@ -245,7 +261,7 @@ class HelpWidget {
}

_showPage(page) {
let helpBody = docById("helpBodyDiv");
const helpBody = docById("helpBodyDiv");
let body = "";
if (
[
Expand All @@ -268,8 +284,8 @@ class HelpWidget {
body = body + "<p>" + HELPCONTENT[page][1] + "</p>";

if (HELPCONTENT[page].length > 3) {
let link = HELPCONTENT[page][3];
console.debug(page + " " + link);
const link = HELPCONTENT[page][3];
// console.debug(page + " " + link);
body =
body +
'<p><a href="' +
Expand All @@ -280,7 +296,7 @@ class HelpWidget {
}

if ([_("Congratulations.")].indexOf(HELPCONTENT[page][0]) !== -1) {
let cell = docById("right-arrow");
const cell = docById("right-arrow");

cell.onclick = () => {
this._prepareBlockList(blocks);
Expand All @@ -296,7 +312,7 @@ class HelpWidget {
// Prepare a list of beginner and advanced blocks and cycle through their help

_prepareBlockList(blocks) {
for (let key in blocks.protoBlockDict) {
for (const key in blocks.protoBlockDict) {
if (
blocks.protoBlockDict[key].beginnerModeBlock === true &&
blocks.protoBlockDict[key].helpString !== undefined &&
Expand All @@ -306,7 +322,7 @@ class HelpWidget {
}
}

for (let key in blocks.protoBlockDict) {
for (const key in blocks.protoBlockDict) {
if (
blocks.protoBlockDict[key].beginnerModeBlock === false &&
blocks.protoBlockDict[key].helpString !== undefined &&
Expand All @@ -328,7 +344,7 @@ class HelpWidget {
// called recursively to cycle through help string of all blocks (Beginner Blocks First)

_blockHelp(block, blocks) {
let widgetWindow = window.widgetWindows.windowFor(this, "help", "help");
const widgetWindow = window.widgetWindows.windowFor(this, "help", "help");
this.widgetWindow = widgetWindow;
widgetWindow.clear();
this._helpDiv = document.createElement("div");
Expand Down Expand Up @@ -359,7 +375,7 @@ class HelpWidget {
this._blockHelp(blocks.protoBlockDict[this.appendedBlockList[this.index]], blocks);
};
if (block.name !== null) {
let label = block.staticLabels[0];
const label = block.staticLabels[0];
this.widgetWindow.updateTitle(_(label));
}

Expand All @@ -369,8 +385,8 @@ class HelpWidget {
// this._showPage(0);

if (block.name !== null) {
let name = block.name;
let advIcon =
const name = block.name;
const advIcon =
'<a\
class="tooltipped"\
data-toggle="tooltip"\
Expand All @@ -383,7 +399,7 @@ class HelpWidget {
></a\
>';

let findIcon =
const findIcon =
'<a\
class="tooltipped"\
data-toggle="tooltip"\
Expand All @@ -397,9 +413,9 @@ class HelpWidget {
></a\
>';

let message = block.helpString;
const message = block.helpString;

let helpBody = docById("helpBodyDiv");
const helpBody = docById("helpBodyDiv");
helpBody.style.height = "500px";
helpBody.style.backgroundColor = "#e8e8e8";
if (message) {
Expand Down Expand Up @@ -447,25 +463,28 @@ class HelpWidget {
helpBody.innerHTML += advIcon;
}

let findIconMethod = docById("findIcon");
const findIconMethod = docById("findIcon");

findIconMethod.onclick = () => {
block.palette.palettes.showPalette(block.palette.name);
};

let loadButton = docById("loadButton");
const loadButton = docById("loadButton");
if (loadButton !== null) {
loadButton.onclick = () => {
if (message.length < 4) {
// If there is nothing specified, just
// load the block.
console.debug("CLICK: " + name);
let obj = blocks.palettes.getProtoNameAndPalette(name);
let protoblk = obj[0];
let paletteName = obj[1];
let protoName = obj[2];

let protoResult = blocks.protoBlockDict.hasOwnProperty(protoName);
// console.debug("CLICK: " + name);
const obj = blocks.palettes.getProtoNameAndPalette(name);
const protoblk = obj[0];
const paletteName = obj[1];
const protoName = obj[2];

const protoResult = Object.prototype.hasOwnProperty.call(
blocks.protoBlockDict,
protoName
);
if (protoResult) {
blocks.palettes.dict[paletteName].makeBlockFromSearch(
protoblk,
Expand All @@ -478,13 +497,13 @@ class HelpWidget {
} else if (typeof message[3] === "string") {
// If it is a string, load the macro
// assocuated with this block
let blocksToLoad = getMacroExpansion(message[3], 100, 100);
console.debug("CLICK: " + blocksToLoad);
const blocksToLoad = getMacroExpansion(message[3], 100, 100);
// console.debug("CLICK: " + blocksToLoad);
blocks.loadNewBlocks(blocksToLoad);
} else {
// Load the blocks.
let blocksToLoad = message[3];
console.debug("CLICK: " + blocksToLoad);
const blocksToLoad = message[3];
// console.debug("CLICK: " + blocksToLoad);
blocks.loadNewBlocks(blocksToLoad);
}
};
Expand Down

0 comments on commit a4b194f

Please sign in to comment.