Fix #1849958 [[Enhancement] Go back to book library by clicking Esc on server](https://bugs.launchpad.net/calibre/+bug/1849958)

This commit is contained in:
Kovid Goyal 2019-11-04 15:55:37 +05:30
parent 89d5c1de22
commit 8723d0ee27
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 14 additions and 3 deletions

View File

@ -605,7 +605,7 @@ def check_for_books_loaded():
create_book_details(container)
def onkeydown(container_id, ev):
def onkeydown(container_id, close_action, ev):
if render_book.book_id:
if not ev.altKey and not ev.ctrlKey and not ev.metaKey and not ev.shiftKey:
if ev.key is 'ArrowLeft':
@ -614,6 +614,9 @@ def onkeydown(container_id, ev):
elif ev.key is 'ArrowRight':
next_book(render_book.book_id, 1)
ev.preventDefault(), ev.stopPropagation()
elif ev.key is 'Escape':
ev.preventDefault(), ev.stopPropagation()
close_action()
def init(container_id):
@ -629,7 +632,7 @@ def init(container_id):
create_top_bar(container, title=_('Book details'), action=close_action, icon=close_icon)
window.scrollTo(0, 0) # Ensure we are at the top of the window
container.appendChild(E.div(class_=CLASS_NAME, tabindex='0'))
container.lastChild.addEventListener('keydown', onkeydown.bind(None, container_id), {'passive': False, 'capture': True})
container.lastChild.addEventListener('keydown', onkeydown.bind(None, container_id, close_action), {'passive': False, 'capture': True})
container.lastChild.focus()
container.lastChild.appendChild(E.div(_('Loading books from the calibre library, please wait...'), style='margin: 1ex 1em'))
conditional_timeout(container_id, 5, check_for_books_loaded)

View File

@ -1040,10 +1040,18 @@ def check_for_books_loaded():
create_edit_metadata(container)
def handle_keypress(container_id, ev):
if not ev.altKey and not ev.ctrlKey and not ev.metaKey and not ev.shiftKey:
if ev.key is 'Escape':
ev.preventDefault(), ev.stopPropagation()
on_close(container_id)
def init(container_id):
container = document.getElementById(container_id)
create_top_bar(container, title=_('Edit metadata'), action=on_close.bind(None, container_id), icon='close')
container.appendChild(E.div(class_=CLASS_NAME))
container.appendChild(E.div(class_=CLASS_NAME, tabindex='0', onkeydown=handle_keypress.bind(None, container_id)))
container.lastChild.focus()
container.lastChild.appendChild(E.div(_('Loading books from the calibre library, please wait...'), style='margin: 1ex 1em'))
conditional_timeout(container_id, 5, check_for_books_loaded)