From a807f6a6c35f9019f58a0e8800b74f0aacd197d9 Mon Sep 17 00:00:00 2001 From: David Westerink Date: Mon, 5 Nov 2018 13:01:34 +0100 Subject: [PATCH] Fix shortcut for Validator using WazeWrap This fixes the shortcut not working for us. There is a lot of code involved for adding the shortcut in a good way, so I propose using WazeWrap for add the shortcut. In the future we could utilize WazeWrap for more things? --- meta/meta-begin.js | 1 + meta/wme-externs.js | 11 +++++++++++ src/basic.js | 9 +++++++++ src/login.js | 3 +++ src/other.js | 2 +- 5 files changed, 25 insertions(+), 1 deletion(-) diff --git a/meta/meta-begin.js b/meta/meta-begin.js index c733441..fd89ece 100644 --- a/meta/meta-begin.js +++ b/meta/meta-begin.js @@ -5,6 +5,7 @@ // @match https://beta.waze.com/*editor* // @match https://www.waze.com/*editor* // @exclude https://www.waze.com/*user/*editor/* +// @require https://greasyfork.org/scripts/24851-wazewrap/code/WazeWrap.js // @grant none // @icon https://raw.githubusercontent.com/WMEValidator/release/master/img/WV-icon96.png // @namespace a diff --git a/meta/wme-externs.js b/meta/wme-externs.js index 6db94f4..c5fec73 100644 --- a/meta/wme-externs.js +++ b/meta/wme-externs.js @@ -32,6 +32,17 @@ var I18n = { currentLocale: function () { }, } +/////////////////////////////////////////////////////////////////////////// +// WazeWrap Namespace +/** @type {Object} */ +var WazeWrap = { + Interface: { + Shortcut: { + add: function () { }, + } + } +} + /////////////////////////////////////////////////////////////////////////// // OpenLayers Namespace /** @type {Object} */ diff --git a/src/basic.js b/src/basic.js index 0dafb37..36719b2 100644 --- a/src/basic.js +++ b/src/basic.js @@ -738,3 +738,12 @@ function onChangeIsImperial() { _RT.$isMapChanged = true; async(F_LOGIN); } + +/** +* Toggle WME Validator from shortcut +*/ +function onToggleValidator(){ + // switch Validator on/off + _RT.$switchValidator = true; + async(F_UPDATEUI); +} diff --git a/src/login.js b/src/login.js index 038bbc6..1446cc5 100644 --- a/src/login.js +++ b/src/login.js @@ -1217,6 +1217,9 @@ function F_LOGIN() { $('#user-tabs+div.tab-content').append( '
' ); + // Create Shortcut + new WazeWrap.Interface.Shortcut(GL_LAYERACCEL, 'Toggle WME Validator', + 'wmevalidator', 'WME Validator', GL_LAYERSHORTCUT, onToggleValidator, null).add(); // append user interface after the details or ad the bottom _THUI.appendUI(document.getElementById("sidepanel-" + ID_PREFIX), _UI, "i" + ID_PREFIX); diff --git a/src/other.js b/src/other.js index 9142629..4ec6353 100644 --- a/src/other.js +++ b/src/other.js @@ -434,7 +434,7 @@ function F_INIT() { WM = nW.map; WMo = nW.model; WC = nW.controller; - if (!Wa || !WLM || !WSM || !WM || !WMo || !WC || !$("#user-tabs")) { + if (!Wa || !WLM || !WSM || !WM || !WMo || !WC || !WazeWrap || !$("#user-tabs")) { log("waiting for WME...") async(F_INIT, null, 1e3); return;