From 721d491d54028f43156108fe456f9b7f74aed15d Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 12 Dec 2017 06:56:50 +0530 Subject: [PATCH] Content server: Open links in the comments section from the book details page in new windows. Fixes #1737644 [links in comments served by calibre-server should have target="_blank"](https://bugs.launchpad.net/calibre/+bug/1737644) --- src/pyj/book_list/book_details.pyj | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/pyj/book_list/book_details.pyj b/src/pyj/book_list/book_details.pyj index 24ab44fa1f..05ca396716 100644 --- a/src/pyj/book_list/book_details.pyj +++ b/src/pyj/book_list/book_details.pyj @@ -100,6 +100,13 @@ def adjust_iframe_height(iframe): # scrollHeight is inaccurate on Firefox iframe.style.height = de.offsetHeight + 5 + 'px' iframe.dataset.last_window_width = window.innerWidth + '' + return de + + +def setup_iframe(iframe): + de = adjust_iframe_height(iframe) + for a in de.querySelectorAll('a[href]'): + a.setAttribute('target', '_blank') def adjust_all_iframes(ev): @@ -113,8 +120,10 @@ window.addEventListener('resize', debounce(adjust_all_iframes, 250)) def adjusting_sandboxed_html(html): css = 'html, body {{ overflow: hidden; color: {} }}'.format(get_color('window-foreground')) - ans = sandboxed_html(html, css, 'allow-same-origin') - ans.addEventListener('load', def(ev): adjust_iframe_height(ev.target);) + # allow-same-origin is needed for resizing and allow-popups is needed for + # target="_blank" + ans = sandboxed_html(html, css, 'allow-same-origin allow-popups') + ans.addEventListener('load', def(ev): setup_iframe(ev.target);) ans.style.height = '50vh' ans.dataset.last_window_width = '0' return ans