mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
Convenience method to get reference to DOM node
This commit is contained in:
parent
e730b0a65e
commit
b97992bb0f
@ -78,3 +78,9 @@ def svgicon(name, height, width):
|
|||||||
u.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', '#icon-' + name)
|
u.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', '#icon-' + name)
|
||||||
ans.appendChild(u)
|
ans.appendChild(u)
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
|
def element(elem_id, child_selector):
|
||||||
|
ans = document.getElementById(elem_id) if elem_id else document.body
|
||||||
|
if child_selector:
|
||||||
|
ans = ans.querySelector(child_selector)
|
||||||
|
return ans
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
# License: GPL v3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPL v3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
from __python__ import hash_literals, bound_methods
|
from __python__ import hash_literals, bound_methods
|
||||||
|
|
||||||
from dom import clear, set_css
|
from dom import clear, set_css, element
|
||||||
from elementmaker import E
|
from elementmaker import E
|
||||||
from book_list.theme import get_color
|
from book_list.theme import get_color
|
||||||
from widgets import create_spinner
|
from widgets import create_spinner
|
||||||
@ -44,13 +44,13 @@ class MainOverlay: # {{{
|
|||||||
set_css(E.div(
|
set_css(E.div(
|
||||||
onclick=def (evt):evt.stopPropagation();,
|
onclick=def (evt):evt.stopPropagation();,
|
||||||
E.div(self.overlay.view.book.metadata.title, style='max-width: 90%; text-overflow: ellipsis'),
|
E.div(self.overlay.view.book.metadata.title, style='max-width: 90%; text-overflow: ellipsis'),
|
||||||
E.div(self.date_formatter.format(Date()), style='max-width: 9%; text-overflow: ellipsis'),
|
E.div(self.date_formatter.format(Date()), data_time='1', style='max-width: 9%; text-overflow: ellipsis'),
|
||||||
), display='flex', justify_content='space-between', align_items='baseline', font_size='smaller', padding='0.5ex 1rem', border_bottom='solid 1px currentColor')
|
), display='flex', justify_content='space-between', align_items='baseline', font_size='smaller', padding='0.5ex 1rem', border_bottom='solid 1px currentColor')
|
||||||
), background_color=get_color('window-background')))
|
), background_color=get_color('window-background')))
|
||||||
self.timer = setInterval(self.update_time, 1000)
|
self.timer = setInterval(self.update_time, 1000)
|
||||||
|
|
||||||
def update_time(self):
|
def update_time(self):
|
||||||
document.getElementById(self.container_id).firstChild.firstChild.lastChild.textContent = self.date_formatter.format(Date())
|
element(self.container_id, '[data-time]').textContent = self.date_formatter.format(Date())
|
||||||
|
|
||||||
def on_hide(self):
|
def on_hide(self):
|
||||||
clearInterval(self.timer)
|
clearInterval(self.timer)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user