1/** 2 * Open links in diagrams in the browser window instead of SVG frame 3 */ 4window.addEventListener('load', function () { 5 /** 6 * Sets _top target for links within SVG 7 */ 8 function manipulateLinkTarget() { 9 jQuery('object.diagrams-svg').each(function () { 10 jQuery(this.contentDocument).find('svg a').not('[target]').attr('target', '_top'); 11 }); 12 } 13 14 /* template agnostic selector */ 15 const observable = document.querySelector('body'); 16 17 const bodyObserver = new MutationObserver((mutationsList, observer) => { 18 for (const mutation of mutationsList) { 19 if (mutation.type !== 'childList') continue; 20 21 const nodes = mutation.addedNodes; 22 23 nodes.forEach(node => { 24 jQuery(node).find('object.diagrams-svg').each(function () { 25 // SVG clicks do not bubble up, so we use an available event 26 jQuery(this).on('load', manipulateLinkTarget); 27 }); 28 }); 29 } 30 }); 31 32 /* rewrite link targets when document is initially loaded */ 33 manipulateLinkTarget(); 34 35 /** 36 * Observe DOM changes 37 * 38 * FIXME this should no longer be necessary after Jack 39 * @see https://github.com/dokuwiki/dokuwiki/pull/3957 40 */ 41 bodyObserver.observe(observable, { 42 attributes: true, 43 childList: true, 44 subtree: true } 45 ); 46}); 47