mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Also hint external links
This commit is contained in:
parent
be884acaf4
commit
e7cb72029c
@ -40,6 +40,7 @@ class Hints:
|
|||||||
self.container.style.display = 'none'
|
self.container.style.display = 'none'
|
||||||
self.send_message('hide')
|
self.send_message('hide')
|
||||||
self.reset()
|
self.reset()
|
||||||
|
self.view.focus_iframe()
|
||||||
|
|
||||||
def show(self):
|
def show(self):
|
||||||
if not self.is_visible:
|
if not self.is_visible:
|
||||||
@ -110,23 +111,23 @@ def is_visible(a):
|
|||||||
return rect.left >= 0 and rect.top >= 0 and rect.left < window.innerWidth and rect.top < window.innerHeight
|
return rect.left >= 0 and rect.top >= 0 and rect.left < window.innerWidth and rect.top < window.innerHeight
|
||||||
|
|
||||||
|
|
||||||
def hint_visible_links(link_attr):
|
def hint_visible_links():
|
||||||
i = 0
|
i = 0
|
||||||
hint_map = {}
|
hint_map = {}
|
||||||
for a in document.body.querySelectorAll(f'a[{link_attr}]'):
|
for a in document.body.querySelectorAll('a[href]'):
|
||||||
if is_visible(a):
|
if is_visible(a):
|
||||||
i += 1
|
i += 1
|
||||||
h = i + ''
|
h = i + ''
|
||||||
a.dataset.calibreHintRender = i.toString(36)
|
a.dataset.calibreHintRender = i.toString(36)
|
||||||
a.dataset.calibreHintValue = h
|
a.dataset.calibreHintValue = h
|
||||||
a.classList.add('calibre-hint-visible')
|
a.classList.add('calibre-hint-visible')
|
||||||
hint_map[h] = {'type': 'link', 'data':JSON.parse(a.getAttribute(link_attr)), 'value': i}
|
hint_map[h] = {'type': 'link', 'value': i}
|
||||||
hint_map._length = i
|
hint_map._length = i
|
||||||
return hint_map
|
return hint_map
|
||||||
|
|
||||||
|
|
||||||
def unhint_links(link_attr):
|
def unhint_links():
|
||||||
for a in document.body.querySelectorAll(f'a[{link_attr}]'):
|
for a in document.body.querySelectorAll('a[href]'):
|
||||||
a.classList.remove('calibre-hint-visible')
|
a.classList.remove('calibre-hint-visible')
|
||||||
v'delete a.dataset.calibreHintRender'
|
v'delete a.dataset.calibreHintRender'
|
||||||
v'delete a.dataset.calibreHintValue'
|
v'delete a.dataset.calibreHintValue'
|
||||||
|
@ -925,20 +925,23 @@ class IframeBoss:
|
|||||||
if data.type is 'show':
|
if data.type is 'show':
|
||||||
# clear selection so that it does not confuse with the hints which use the same colors
|
# clear selection so that it does not confuse with the hints which use the same colors
|
||||||
window.getSelection().removeAllRanges()
|
window.getSelection().removeAllRanges()
|
||||||
hints_map = hint_visible_links(self.link_attr)
|
hints_map = hint_visible_links()
|
||||||
self.send_message('hints', type='shown', hints_map=hints_map)
|
self.send_message('hints', type='shown', hints_map=hints_map)
|
||||||
elif data.type is 'hide':
|
elif data.type is 'hide':
|
||||||
unhint_links(self.link_attr)
|
unhint_links()
|
||||||
elif data.type is 'activate':
|
elif data.type is 'activate':
|
||||||
hint = data.hint
|
hint = data.hint
|
||||||
if hint.type is 'link':
|
if hint.type is 'link':
|
||||||
a = document.body.querySelector(f'[data-calibre-hint-value="{hint.value}"]')
|
a = document.body.querySelector(f'[data-calibre-hint-value="{hint.value}"]')
|
||||||
a.addEventListener("animationend", def (ev):
|
a.removeEventListener('animationend', self.hint_animation_ended)
|
||||||
a.classList.remove('calibre-animated-hint')
|
a.addEventListener('animationend', self.hint_animation_ended, False)
|
||||||
self.activate_link(hint.data.name, hint.data.frag, a)
|
|
||||||
, False)
|
|
||||||
a.classList.add('calibre-animated-hint')
|
a.classList.add('calibre-animated-hint')
|
||||||
|
|
||||||
|
def hint_animation_ended(self, ev):
|
||||||
|
a = ev.target
|
||||||
|
a.classList.remove('calibre-animated-hint')
|
||||||
|
a.click()
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
main.boss = IframeBoss()
|
main.boss = IframeBoss()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user