Skip to content

Commit

Permalink
修正不能用 Enter 键触发「发送」按钮提交表单的问题 (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
riophae authored and LitoMore committed Apr 29, 2019
1 parent 91b3a90 commit e7b78e9
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/features/keyboard-shortcuts/script(page).js
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,35 @@ export default context => {

for (const [ hotkeyOpts, handler ] of hotkeyHandlers) {
if (isHotkey(event, hotkeyOpts)) {
event.preventDefault()
handler()
handler(event)

break
}
}
}

function goPrevPage() {
function goPrevPage(event) {
const prevPageButton = (
getPagerButtonsByText('上一页') ||
getPhotoPagerButtonByText('上一张')
)

if (prevPageButton) prevPageButton.click()
if (prevPageButton) {
event.preventDefault()
prevPageButton.click()
}
}

function goNextPage() {
function goNextPage(event) {
const nextPageButton = (
getPagerButtonsByText('下一页') ||
getPhotoPagerButtonByText('下一张')
)

if (nextPageButton) nextPageButton.click()
if (nextPageButton) {
event.preventDefault()
nextPageButton.click()
}
}

function getPagerButtonsByText(text) {
Expand All @@ -66,10 +71,14 @@ export default context => {
}
}

function focusTextarea() {
function focusTextarea(event) {
const form = select('#phupdate form')
const textarea = select('#phupdate textarea')
const isTriggeredOutsideTheForm = form && !form.contains(event.target)
const isTextareaVisible = textarea && isElementInViewport(textarea)

if (textarea && isElementInViewport(textarea)) {
if (isTriggeredOutsideTheForm && isTextareaVisible) {
event.preventDefault()
textarea.focus()
}
}
Expand Down

0 comments on commit e7b78e9

Please sign in to comment.