From e83253af45f4795fde694043742ee760ec4dff4b Mon Sep 17 00:00:00 2001 From: ezsh <ezsh.junk@gmail.com> Date: Thu, 30 May 2019 20:08:34 +0200 Subject: [PATCH] Teach link generation function to show tooltips --- src/js/utilJS.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/js/utilJS.js b/src/js/utilJS.js index faeb5246ea1..56f606f4625 100644 --- a/src/js/utilJS.js +++ b/src/js/utilJS.js @@ -2319,7 +2319,8 @@ App.Utils.escapeHtml = function(text) { * @see https://www.motoslave.net/sugarcube/2/docs/#markup-html-attribute * @param {string} linkText link text * @param {string} passage the passage name to link to - * @param {string} [setter=''] setter tet (optional) + * @param {string} [setter=''] setter text (optional) + * @param {string} [tooltip=''] tooltip text (optional) * @param {string} [elementType='a'] element type (optional) default is 'a'. * Could be any of 'a', 'audio', img', 'source', 'video' * @returns {string} element text @@ -2328,11 +2329,14 @@ App.Utils.escapeHtml = function(text) { * // equal to [[Go to town|Town]] * App.UI.passageLink("Go to town", "Town") */ -App.UI.passageLink = function(linkText, passage, setter, elementType = 'a') { +App.UI.passageLink = function(linkText, passage, setter, tooltip = '', elementType = 'a') { let res = `<${elementType} data-passage="${passage}"`; if (setter) { res += ` data-setter="${App.Utils.escapeHtml(setter)}"`; } + if (tooltip) { + res += ` title="${tooltip}"`; + } res += `>${linkText}</${elementType}>`; return res; }; @@ -2356,7 +2360,7 @@ App.UI.link = function() { * @param {string} [passage] the passage name to link to * @returns {string} link in SC markup */ - function makeLink(linkText, handler, args = [], passage = '') { + function makeLink(linkText, handler, args = [], passage = '', tooltip = '') { // pack handler and data State.temporary.linkHandlers[counter] = { f: handler, @@ -2369,8 +2373,11 @@ App.UI.link = function() { ++counter; if (passage) { - return App.UI.passageLink(linkText, passage, SCHandlerText); + return App.UI.passageLink(linkText, passage, SCHandlerText, tooltip); } else { + if (tooltip) { + throw "Tooltips are not supported by the <<link>> markup."; + } // data-passage scheme does not work with empty passage name return `<<link "${linkText}">><<run ${SCHandlerText}>><</link>>`; } -- GitLab