Remove top-level references to window and document

This commit is contained in:
Kovid Goyal 2021-05-16 05:43:02 +05:30
parent 5993017df9
commit 8988cbcf56
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
6 changed files with 19 additions and 13 deletions

View File

@ -143,7 +143,8 @@ def add_stars_to(stars, val, allow_half_stars):
stars.appendChild(svgicon('star-half'))
window.addEventListener('resize', debounce(adjust_all_iframes, 250))
if window?:
window.addEventListener('resize', debounce(adjust_all_iframes, 250))
def adjusting_sandboxed_html(html, extra_css):
color = get_color_as_rgba('window-foreground')

View File

@ -244,6 +244,7 @@ def handle_shortcut(sc_name, evt):
def layout(is_single_page):
add_visibility_listener()
line_height(True)
rem_size(True)
set_css(document.body, margin='0', border_width='0', padding='0')
@ -258,13 +259,17 @@ def auto_scroll_resume():
scroll_animator.sync()
# Pause auto-scroll while minimized
document.addEventListener("visibilitychange", def():
if (document.visibilityState is 'visible'):
scroll_animator.sync()
else:
scroll_animator.pause()
)
def add_visibility_listener():
if add_visibility_listener.done:
return
add_visibility_listener.done = True
# Pause auto-scroll while minimized
document.addEventListener("visibilitychange", def():
if (document.visibilityState is 'visible'):
scroll_animator.sync()
else:
scroll_animator.pause()
)
def cancel_scroll():

View File

@ -146,7 +146,7 @@ def commit_head_foot(onchange, container):
onchange()
if window.Intl?.DateTimeFormat:
if window?.Intl?.DateTimeFormat:
time_formatter = window.Intl.DateTimeFormat(undefined, {'hour':'numeric', 'minute':'numeric'})
else:
time_formatter = {'format': def(date):

View File

@ -20,7 +20,6 @@ def escaper():
return def(text):
el.nodeValue = text
return ser.serializeToString(el)
escape_for_xml = escaper()
class Client:
@ -29,6 +28,7 @@ class Client:
max_rate = 2
def __init__(self):
self.escape_for_xml = escaper()
self.stop_requested_at = None
self.status = {'synthesizing': False, 'paused': False}
self.queue = v'[]'
@ -134,7 +134,7 @@ class Client:
# buf.push('<mark name="' + x + '"/>')
buf.push('')
else:
buf.push(escape_for_xml(x))
buf.push(self.escape_for_xml(x))
size += buf[-1].length
if size > 24000:
buf = v'[]'

View File

@ -3,7 +3,7 @@
from __python__ import bound_methods, hash_literals
if document.caretPositionFromPoint:
if document?.caretPositionFromPoint:
caret_position_from_point = document.caretPositionFromPoint.bind(document)
else:
caret_position_from_point = def(x, y):

View File

@ -8,7 +8,7 @@ from book_list.theme import get_font_family
is_ios = v'!!navigator.platform && /iPad|iPhone|iPod/.test(navigator.platform)'
if !is_ios and window.navigator.platform is 'MacIntel' and window.navigator.maxTouchPoints > 1:
if !is_ios and v'!!navigator.platform' and window? and window.navigator.platform is 'MacIntel' and window.navigator.maxTouchPoints > 1:
# iPad Safari in desktop mode https://stackoverflow.com/questions/57765958/how-to-detect-ipad-and-ipad-os-version-in-ios-13-and-up
is_ios = True