From dc7db074e87cee4171bc0ff54239d4da1a03da41 Mon Sep 17 00:00:00 2001 From: ansuz Date: Thu, 3 Aug 2017 11:04:38 +0200 Subject: [PATCH] open pad links when clicking in readOnly mode --- www/pad/main.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/www/pad/main.js b/www/pad/main.js index 58c48b699..712edc9bf 100644 --- a/www/pad/main.js +++ b/www/pad/main.js @@ -299,6 +299,13 @@ define([ var DD = new DiffDom(diffOptions); + var openLink = function (e) { + var el = e.currentTarget; + if (!el || el.nodeName !== 'A') { return; } + var href = el.getAttribute('href'); + if (href) { window.open(href, '_blank'); } + }; + // apply patches, and try not to lose the cursor in the process! var applyHjson = function (shjson) { var userDocStateDom = hjsonToDom(JSON.parse(shjson)); @@ -308,6 +315,11 @@ define([ } var patch = (DD).diff(inner, userDocStateDom); (DD).apply(inner, patch); + if (readOnly) { + var $links = $(inner).find('a'); + // off so that we don't end up with multiple identical handlers + $links.off('click', openLink).on('click', openLink); + } }; var stringifyDOM = module.stringifyDOM = function (dom) {