diff --git a/js/widgets/help.js b/js/widgets/help.js index b52e74ecfb..8ebd0c9552 100644 --- a/js/widgets/help.js +++ b/js/widgets/help.js @@ -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; @@ -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"; @@ -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; @@ -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)); } @@ -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 = ''; - let findIcon = + const findIcon = ''; - 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 = ""; @@ -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, @@ -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]); @@ -245,7 +261,7 @@ class HelpWidget { } _showPage(page) { - let helpBody = docById("helpBodyDiv"); + const helpBody = docById("helpBodyDiv"); let body = ""; if ( [ @@ -268,8 +284,8 @@ class HelpWidget { body = body + "
" + HELPCONTENT[page][1] + "
"; 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 + '{ this._prepareBlockList(blocks); @@ -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 && @@ -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 && @@ -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"); @@ -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)); } @@ -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 = ''; - let findIcon = + const findIcon = ''; - 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) { @@ -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, @@ -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); } };