mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
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)
This commit is contained in:
parent
eb4e50df7c
commit
721d491d54
@ -100,6 +100,13 @@ def adjust_iframe_height(iframe):
|
|||||||
# scrollHeight is inaccurate on Firefox
|
# scrollHeight is inaccurate on Firefox
|
||||||
iframe.style.height = de.offsetHeight + 5 + 'px'
|
iframe.style.height = de.offsetHeight + 5 + 'px'
|
||||||
iframe.dataset.last_window_width = window.innerWidth + ''
|
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):
|
def adjust_all_iframes(ev):
|
||||||
@ -113,8 +120,10 @@ window.addEventListener('resize', debounce(adjust_all_iframes, 250))
|
|||||||
|
|
||||||
def adjusting_sandboxed_html(html):
|
def adjusting_sandboxed_html(html):
|
||||||
css = 'html, body {{ overflow: hidden; color: {} }}'.format(get_color('window-foreground'))
|
css = 'html, body {{ overflow: hidden; color: {} }}'.format(get_color('window-foreground'))
|
||||||
ans = sandboxed_html(html, css, 'allow-same-origin')
|
# allow-same-origin is needed for resizing and allow-popups is needed for
|
||||||
ans.addEventListener('load', def(ev): adjust_iframe_height(ev.target);)
|
# 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.style.height = '50vh'
|
||||||
ans.dataset.last_window_width = '0'
|
ans.dataset.last_window_width = '0'
|
||||||
return ans
|
return ans
|
||||||
|
Loading…
x
Reference in New Issue
Block a user