parsley/app/javascript/lib/GlobalMixins.js

63 lines
1.2 KiB
JavaScript
Raw Normal View History

2018-03-30 14:31:09 -05:00
import Vue from 'vue';
2018-03-30 17:08:09 -05:00
import { mapGetters, mapMutations, mapState } from 'vuex';
2018-03-30 14:31:09 -05:00
Vue.mixin({
computed: {
2018-03-30 17:08:09 -05:00
...mapGetters([
"isLoading",
2018-04-01 12:17:54 -05:00
"isLoggedIn",
"isAdmin"
2018-03-30 17:08:09 -05:00
]),
...mapState([
"user"
])
2018-03-30 14:31:09 -05:00
},
methods: {
...mapMutations([
'setError',
'setLoading'
]),
2018-04-01 21:43:23 -05:00
loadResource(promise) {
2018-03-30 14:31:09 -05:00
this.setLoading(true);
return promise
.catch(err => this.setError(err))
.then(() => this.setLoading(false));
}
}
2018-04-17 09:59:38 -05:00
});
function clickStrikeClick(evt) {
const isStrikable = el => el && el.tagName === "LI";
const strikeClass = "is-strikethrough";
let t = evt.target;
while (t !== null && t !== this && !isStrikable(t)) {
t = t.parentElement;
}
if (isStrikable(t)) {
const classList = t.className.split(" ");
const strIdx = classList.findIndex(c => c === strikeClass);
if (strIdx >= 0) {
classList.splice(strIdx, 1);
} else {
classList.push(strikeClass);
}
t.className = classList.join(" ");
}
}
Vue.directive('click-strike', {
bind(el) {
el.addEventListener("click", clickStrikeClick);
},
unbind(el) {
el.removeEventListener("click", clickStrikeClick);
}
2018-03-30 14:31:09 -05:00
});