123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- export default defineNuxtPlugin(nuxtApp => {
-
- nuxtApp.vueApp.directive('longPress', {
-
- inserted: function(el, binding, vnode) {
- let pressTimer = null;
-
- el.addEventListener("touchstart", e => {
-
- e.preventDefault();
-
- if (pressTimer !== null) {
- clearTimeout(pressTimer);
- }
-
- pressTimer = setTimeout(() => {
-
- if (typeof binding.value === "function") {
-
- binding.value(true, e);
- }
- }, 500);
- });
-
- el.addEventListener("touchend", e => {
-
- binding.value(false, e);
- clearTimeout(pressTimer);
- pressTimer = null;
- });
- el.addEventListener("touchcancel", e => {
- clearTimeout(pressTimer);
- pressTimer = null;
- });
- },
-
- unbind: function(el) {
- el.removeEventListener("touchstart");
- el.removeEventListener("touchend");
- el.removeEventListener("touchcancel");
- }
- })
- })
|