Skip to content

Commit

Permalink
fix: edge case of Safari
Browse files Browse the repository at this point in the history
  • Loading branch information
Dragon-Fish committed Jan 4, 2024
1 parent a365b31 commit 1b191dd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/module/loadQuickDiff.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { _analytics } from './_analytics'
import { quickDiff } from './quickDiff'
import { quickEdit } from './quickEdit'
import { mwConfig } from '../utils/mw'
import { isAlternativeClick } from '../utils/alternativeClick'
import { isPureLMBClick } from '../utils/mouseEvent'
const { getParamValue } = mw.util

function injectLinks(container) {
Expand Down Expand Up @@ -88,7 +88,7 @@ function injectLinks(container) {

// 点击事件
$this.on('click', function (e) {
if (isAlternativeClick(e)) return
if (!isPureLMBClick(e)) return
e.preventDefault()
_analytics('quick_diff_recentchanges')
return quickDiff(params)
Expand All @@ -110,7 +110,7 @@ export function loadQuickDiff(container) {
$('<button>')
.text(_msg('quick-diff'))
.on('click', function (e) {
if (isAlternativeClick(e)) return
if (!isPureLMBClick(e)) return

e.preventDefault()
_analytics('quick_diff_history_page')
Expand Down
9 changes: 9 additions & 0 deletions src/utils/alternativeClick.js → src/utils/mouseEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,12 @@ export const isAlternativeClick = (e) => {
const event = e.originalEvent || e
return event.altKey || event.ctrlKey || event.metaKey || event.shiftKey
}

/**
* @param {MouseEvent} e
* @returns {boolean}
*/
export const isPureLMBClick = (e) => {
const event = e.originalEvent || e
return event.button === 0 && !isAlternativeClick(e)
}

0 comments on commit 1b191dd

Please sign in to comment.