Skip to content

Commit

Permalink
refactor: migrate longpress.js to longpress.ts (#619)
Browse files Browse the repository at this point in the history
  • Loading branch information
pataar authored Feb 8, 2022
1 parent a15cb3c commit c589a49
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/plugins/longpress.js → src/plugins/longpress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,44 @@ Vue.directive('longpress', {
// Make sure expression provided is a function
if (typeof binding.value !== 'function') {
// Fetch name of component
const compName = vNode.context.name
const compName = vNode.context?.$options.name
// pass warning to console
let warn = `[longpress:] provided expression '${binding.expression}' is not a function, but has to be`
if (compName) { warn += ` Found in component '${compName}' ` }

console.warn(warn)
}

const debounceTime = parseInt(binding.arg ?? 1000)
const debounceTime = Number(binding.arg ?? 1000)

// Run Function
const handler = (e) => {
binding.value(e)
}

// Define variable
let pressTimer = null
let pressTimer: number | null = null

// Define funtion handlers
// Create timeout ( run function after 1s )
let before = null
let start = (e) => {
if ((e.type === 'click' && e.button !== 0)) {
const before: string | null = null
const start = (e: TouchEvent) => {
if ((e.type === 'click')) {
return
}

if (!e.touches || e.touches.length < 1) {
return
}

document.querySelector('body').setAttribute('style', 'user-select: none; -webkit-user-select: none; -moz-user-select: none;')
document.querySelector('body')?.setAttribute('style', 'user-select: none; -webkit-user-select: none; -moz-user-select: none;')

setTimeout(() => {
document.querySelector('body').setAttribute('style', '')
document.querySelector('body')?.setAttribute('style', '')
}, debounceTime + 200)

if (pressTimer === null) {
pressTimer = setTimeout(() => {
pressTimer = window.setTimeout(() => {
e.preventDefault()
e.stopPropagation()
e.stopImmediatePropagation()
Expand All @@ -68,13 +68,13 @@ Vue.directive('longpress', {
}

// Cancel Timeout
let cancel = () => {
const cancel = () => {
// Check if timer has a value or not
if (pressTimer !== null) {
clearTimeout(pressTimer)
pressTimer = null
if (before) {
document.querySelector('body').setAttribute('style', before)
document.querySelector('body')?.setAttribute('style', before)
}
/*console.log(e.type);
if (e.type === "touchend" && vNode.data.on.click) {
Expand Down

0 comments on commit c589a49

Please sign in to comment.