From d131addd6380a75e7c73644e71c6f9fd8213a742 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Fri, 6 Jan 2017 13:33:23 +0000 Subject: [PATCH] Allow tips to be enabled/disabled via menu option --- editor/js/main.js | 1 + editor/js/ui/tab-info.js | 42 +++++++++++++++++++++++-------- red/api/locales/en-US/editor.json | 3 ++- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/editor/js/main.js b/editor/js/main.js index 17dd1963a..0e58ed040 100644 --- a/editor/js/main.js +++ b/editor/js/main.js @@ -231,6 +231,7 @@ } menuOptions.push({id:"menu-item-keyboard-shortcuts",label:RED._("menu.label.keyboardShortcuts"),onselect:"core:show-help"}); + menuOptions.push({id:"menu-item-show-tips",label:RED._("menu.label.showTips"),toggle:true,selected:true,onselect:"core:toggle-show-tips"}); menuOptions.push({id:"menu-item-help", label: RED.settings.theme("menu.menu-item-help.label","Node-RED website"), href: RED.settings.theme("menu.menu-item-help.url","http://nodered.org/docs") diff --git a/editor/js/ui/tab-info.js b/editor/js/ui/tab-info.js index cf22367b6..0a3b88339 100644 --- a/editor/js/ui/tab-info.js +++ b/editor/js/ui/tab-info.js @@ -148,15 +148,30 @@ RED.sidebar.info = (function() { var tips = (function() { - var startDelay = 2000; + var started = false; + var enabled = true; + var startDelay = 1000; var cycleDelay = 10000; var startTimeout; var refreshTimeout; var tipCount = -1; + RED.actions.add("core:toggle-show-tips",function(state) { + if (state === undefined) { + RED.menu.toggleSelected("menu-item-show-tips"); + } else { + enabled = state; + if (enabled) { + if (started) { + startTips(); + } + } else { + stopTips(); + } + } + }); function setTip() { - var r = Math.floor(Math.random() * tipCount); var tip = RED._("infotips:info.tip"+r); @@ -184,8 +199,9 @@ RED.sidebar.info = (function() { setTip(); }) } - return { - start: function() { + function startTips() { + started = true; + if (enabled) { if (!startTimeout && !refreshTimeout) { $(content).html(""); if (tipCount === -1) { @@ -195,14 +211,20 @@ RED.sidebar.info = (function() { } startTimeout = setTimeout(setTip,startDelay); } - }, - stop: function() { - clearInterval(refreshTimeout); - clearTimeout(startTimeout); - refreshTimeout = null; - startTimeout = null; } } + function stopTips() { + started = false; + clearInterval(refreshTimeout); + clearTimeout(startTimeout); + refreshTimeout = null; + startTimeout = null; + $(".node-info-tip").remove(); + } + return { + start: startTips, + stop: stopTips + } })(); function clear() { diff --git a/red/api/locales/en-US/editor.json b/red/api/locales/en-US/editor.json index cad166866..5ac8aaad5 100644 --- a/red/api/locales/en-US/editor.json +++ b/red/api/locales/en-US/editor.json @@ -53,7 +53,8 @@ "keyboardShortcuts": "Keyboard shortcuts", "login": "Login", "logout": "Logout", - "editPalette":"Manage palette" + "editPalette":"Manage palette", + "showTips": "Show tips" } }, "user": {