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

Disable feature based on attribute added #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
yarn.lock
dist/
dist/
.DS_Store
8 changes: 7 additions & 1 deletion example/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
{{ msg }}
<div
class="content"
:disabled="disable"
v-hammer:press="test2"
v-hammer:tap="test"
v-hammer:pan.left="test"
v-hammer:panstart="test2"
v-hammer:panend="test2"
>
</div>
<button @click="toggleDisableState">{{ disable ? 'Enable' : 'Disable' }} Tap</button>
</div>
</template>

Expand All @@ -37,7 +39,8 @@ export default {
name: 'app',
data() {
return {
msg: 'Welcome to Your Vue.js App'
msg: 'Welcome to Your Vue.js App',
disable: false
};
},
methods: {
Expand All @@ -46,6 +49,9 @@ export default {
},
test2(e) {
console.log('aaaa');
},
toggleDisableState() {
this.disable = !this.disable
}
}
};
Expand Down
9 changes: 8 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export const VueHammer = {
el.hammer = new Hammer.Manager(el)
}
const mc = el.hammer

// Disabled hammer
mc.set({ enable: el.getAttribute('disabled') !== 'disabled' });
// determine event type
const event = binding.arg
if (!event) {
Expand Down Expand Up @@ -90,6 +91,8 @@ export const VueHammer = {
},
inserted: (el, binding) => {
const mc = el.hammer
// Disabled hammer
mc.set({ enable: el.getAttribute('disabled') !== 'disabled' });
const event = binding.arg
const eventWithDir = subGestures.find(subGes => subGes === event) ? event : this.buildEventWithDirections(event, el.__hammerConfig[event].direction)
if (mc.handler) {
Expand All @@ -107,6 +110,8 @@ export const VueHammer = {
},
componentUpdated: (el, binding) => {
const mc = el.hammer
// Disabled hammer
mc.set({ enable: el.getAttribute('disabled') !== 'disabled' });
const event = binding.arg
const eventWithDir = subGestures.find(subGes => subGes === event) ? event : this.buildEventWithDirections(event, el.__hammerConfig[event].direction)
// teardown old handler
Expand All @@ -125,6 +130,8 @@ export const VueHammer = {
},
unbind: (el, binding) => {
const mc = el.hammer
// Disabled hammer
mc.set({ enable: el.getAttribute('disabled') !== 'disabled' });
const event = binding.arg
const eventWithDir = subGestures.find(subGes => subGes === event) ? event : this.buildEventWithDirections(event, el.__hammerConfig[event].direction)
if (mc.handler) {
Expand Down
2 changes: 1 addition & 1 deletion index.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.