From 9bbd770cc2001942ff1b4c8e1a25607881ff94db Mon Sep 17 00:00:00 2001 From: Akron Date: Thu, 21 Nov 2024 13:01:51 +0100 Subject: [PATCH] Set path for cookies and change window access from iframe, so access from tutorials don't become a cross-origin access Change-Id: I49b9c401b3de20cb2ba7fb8c6fc5649d6b105891 --- Changes | 1 + dev/js/src/init.js | 7 +++++-- dev/js/src/tutorial.js | 23 +++++++++++------------ 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/Changes b/Changes index 4dc11988..7bf542ef 100644 --- a/Changes +++ b/Changes @@ -22,6 +22,7 @@ - Keep plugin state in statemanager (fixes #201; diewald) - Fix alerts in hint helper (diewald) - Don't send empty pipes and states via query param (diewald) + - Fix access of iframe location in tutorials. (diewald) 0.58 2024-11-15 - Cookie path is settable now (hebasta) diff --git a/dev/js/src/init.js b/dev/js/src/init.js index 1796c6ac..7f6dce66 100644 --- a/dev/js/src/init.js +++ b/dev/js/src/init.js @@ -82,10 +82,13 @@ define([ // Set base URL KorAP.URL = d.body.getAttribute('data-korap-url') || ""; - + + + // Create suffix if KorAP is run in a subfolder KorAP.session = sessionClass.create( - KorAP.URL.length > 0 ? 'kalamarJS-' + KorAP.URL.slugify() : 'kalamarJS' + (KorAP.URL.length > 0 ? 'kalamarJS-' + KorAP.URL.slugify() : 'kalamarJS'), + KorAP.URL ); // Get koralQuery response diff --git a/dev/js/src/tutorial.js b/dev/js/src/tutorial.js index ae42badf..9fe132d2 100644 --- a/dev/js/src/tutorial.js +++ b/dev/js/src/tutorial.js @@ -197,23 +197,22 @@ define(['session','buttongroup','util'], function (sessionClass, buttonGroupClas let page = obj; if (typeof page != 'string') { - const l = this._iframe !== null ? window.frames[0].location : window.location; + const l = this._iframe !== null ? this._iframe.contentWindow.location : window.location; - page = l.pathname + l.search; + page = l.pathname + l.search; - for (let i = 1; i < 5; i++) { - if ((obj.nodeName === 'SECTION' || obj.nodeName === 'PRE') && obj.hasAttribute('id')) { - page += '#' + obj.getAttribute('id'); - break; - } - else { - obj = obj.parentNode; + for (let i = 1; i < 5; i++) { + if ((obj.nodeName === 'SECTION' || obj.nodeName === 'PRE') && obj.hasAttribute('id')) { + page += '#' + obj.getAttribute('id'); + break; + } + else { + obj = obj.parentNode; if (obj === null) break; - }; - }; + }; + }; }; - this._session.set('tutpage', page); },