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.send_message('hide')
|
||||
self.reset()
|
||||
self.view.focus_iframe()
|
||||
|
||||
def show(self):
|
||||
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
|
||||
|
||||
|
||||
def hint_visible_links(link_attr):
|
||||
def hint_visible_links():
|
||||
i = 0
|
||||
hint_map = {}
|
||||
for a in document.body.querySelectorAll(f'a[{link_attr}]'):
|
||||
for a in document.body.querySelectorAll('a[href]'):
|
||||
if is_visible(a):
|
||||
i += 1
|
||||
h = i + ''
|
||||
a.dataset.calibreHintRender = i.toString(36)
|
||||
a.dataset.calibreHintValue = h
|
||||
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
|
||||
return hint_map
|
||||
|
||||
|
||||
def unhint_links(link_attr):
|
||||
for a in document.body.querySelectorAll(f'a[{link_attr}]'):
|
||||
def unhint_links():
|
||||
for a in document.body.querySelectorAll('a[href]'):
|
||||
a.classList.remove('calibre-hint-visible')
|
||||
v'delete a.dataset.calibreHintRender'
|
||||
v'delete a.dataset.calibreHintValue'
|
||||
|
@ -925,20 +925,23 @@ class IframeBoss:
|
||||
if data.type is 'show':
|
||||
# clear selection so that it does not confuse with the hints which use the same colors
|
||||
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)
|
||||
elif data.type is 'hide':
|
||||
unhint_links(self.link_attr)
|
||||
unhint_links()
|
||||
elif data.type is 'activate':
|
||||
hint = data.hint
|
||||
if hint.type is 'link':
|
||||
a = document.body.querySelector(f'[data-calibre-hint-value="{hint.value}"]')
|
||||
a.addEventListener("animationend", def (ev):
|
||||
a.classList.remove('calibre-animated-hint')
|
||||
self.activate_link(hint.data.name, hint.data.frag, a)
|
||||
, False)
|
||||
a.removeEventListener('animationend', self.hint_animation_ended)
|
||||
a.addEventListener('animationend', self.hint_animation_ended, False)
|
||||
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():
|
||||
main.boss = IframeBoss()
|
||||
|
Loading…
x
Reference in New Issue
Block a user