Skip to content

Commit

Permalink
chore: use licia pointerEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
surunzi committed Sep 20, 2024
1 parent ce3f6ae commit 27b85b4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 40 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"karma-jquery": "^0.2.4",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^5.0.0",
"licia": "^1.41.0",
"licia": "^1.42.0",
"luna-box-model": "^1.0.0",
"luna-console": "^1.3.4",
"luna-data-grid": "^0.6.0",
Expand Down
12 changes: 6 additions & 6 deletions src/DevTools/DevTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import extend from 'licia/extend'
import isStr from 'licia/isStr'
import startWith from 'licia/startWith'
import ready from 'licia/ready'
import pointerEvent from 'licia/pointerEvent'
import evalCss from '../lib/evalCss'
import emitter from '../lib/emitter'
import { isDarkTheme } from '../lib/themes'
Expand All @@ -23,7 +24,6 @@ import LunaModal from 'luna-modal'
import LunaTab from 'luna-tab'
import {
classPrefix as c,
drag,
eventClient,
hasSafeArea,
safeStorage,
Expand Down Expand Up @@ -358,8 +358,8 @@ export default class DevTools extends Emitter {

$resizer.css('height', '100%')

$document.on(drag('move'), moveListener)
$document.on(drag('end'), endListener)
$document.on(pointerEvent('move'), moveListener)
$document.on(pointerEvent('up'), endListener)
}
const moveListener = (e) => {
if (!this._isResizing) {
Expand All @@ -385,11 +385,11 @@ export default class DevTools extends Emitter {

$resizer.css('height', 10)

$document.off(drag('move'), moveListener)
$document.off(drag('end'), endListener)
$document.off(pointerEvent('move'), moveListener)
$document.off(pointerEvent('up'), endListener)
}
$resizer.css('height', 10)
$resizer.on(drag('start'), startListener)
$resizer.on(pointerEvent('down'), startListener)

$navBar.on('contextmenu', (e) => e.preventDefault())
this.$container.on('click', (e) => e.stopPropagation())
Expand Down
13 changes: 7 additions & 6 deletions src/EntryBtn/EntryBtn.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import Emitter from 'licia/Emitter'
import $ from 'licia/$'
import nextTick from 'licia/nextTick'
import orientation from 'licia/orientation'
import { pxToNum, classPrefix as c, drag, eventClient } from '../lib/util'
import pointerEvent from 'licia/pointerEvent'
import { pxToNum, classPrefix as c, eventClient } from '../lib/util'
import evalCss from '../lib/evalCss'

const $document = $(document)
Expand Down Expand Up @@ -93,8 +94,8 @@ export default class EntryBtn extends Emitter {
this._oldX = pxToNum($el.css('left'))
this._oldY = pxToNum($el.css('top'))
this._startY = eventClient('y', e)
$document.on(drag('move'), this._onDragMove)
$document.on(drag('end'), this._onDragEnd)
$document.on(pointerEvent('move'), this._onDragMove)
$document.on(pointerEvent('up'), this._onDragEnd)
}
_onDragMove = (e) => {
const btnSize = this._$el.get(0).offsetWidth
Expand Down Expand Up @@ -132,8 +133,8 @@ export default class EntryBtn extends Emitter {
}

this._onDragMove(e)
$document.off(drag('move'), this._onDragMove)
$document.off(drag('end'), this._onDragEnd)
$document.off(pointerEvent('move'), this._onDragMove)
$document.off(pointerEvent('up'), this._onDragEnd)

const cfg = this.config

Expand All @@ -149,7 +150,7 @@ export default class EntryBtn extends Emitter {
_bindEvent() {
const $el = this._$el

$el.on(drag('start'), this._onDragStart)
$el.on(pointerEvent('down'), this._onDragStart)

orientation.on('change', () => this._resetPos(true))
window.addEventListener('resize', () => this._resetPos())
Expand Down
27 changes: 0 additions & 27 deletions src/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import isUndef from 'licia/isUndef'
import last from 'licia/last'
import map from 'licia/map'
import memStorage from 'licia/memStorage'
import root from 'licia/root'
import toNum from 'licia/toNum'
import trim from 'licia/trim'
import html from 'licia/html'
Expand Down Expand Up @@ -147,32 +146,6 @@ function processClass(str) {
}).join(' ')
}

const hasTouchSupport = 'ontouchstart' in root
const hasPointerSupport = 'PointerEvent' in root
const touchEvents = {
start: 'touchstart',
move: 'touchmove',
end: 'touchend',
}
const mouseEvents = {
start: 'mousedown',
move: 'mousemove',
end: 'mouseup',
}
const pointerEvents = {
start: 'pointerdown',
move: 'pointermove',
end: 'pointerup',
}

export function drag(name) {
if (hasPointerSupport) {
return pointerEvents[name]
}

return hasTouchSupport ? touchEvents[name] : mouseEvents[name]
}

export function eventClient(type, e) {
const name = type === 'x' ? 'clientX' : 'clientY'

Expand Down

0 comments on commit 27b85b4

Please sign in to comment.