Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: migrate longpress.js to longpress.ts #619

Merged
merged 1 commit into from
Feb 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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