Initial favouriting and horrible toggle code fix it Zere

This commit is contained in:
Jiiks 2018-08-22 17:17:37 +03:00
parent 1ab52cb174
commit c4f28a6ac5
2 changed files with 14 additions and 4 deletions

View File

@ -60,8 +60,18 @@ export default new class EmoteModule extends BuiltinModule {
{ {
text: 'Favourite', text: 'Favourite',
type: 'toggle', type: 'toggle',
checked: (target) => { console.log(target); if (target.alt && target.alt === ';cirThree;') { console.log('yes'); return true; } else return false; }, checked: (target) => {
onChange: (checked, target) => { if (target.alt && target.alt === ';cirThree;') { console.log('yes'); return true; } else return false; } const { alt } = target;
if (!alt) return false;
return this.favourites.find(e => e.alt === alt);
},
onChange: (checked, target) => {
const { alt } = target;
if (!alt) return false;
const fav = this.favourites.find(e => e.alt === alt);
if (fav) return this._favourites = this._favourites.filter(e => e.alt !== target.alt);
this.favourites.push({ alt: target.alt });
}
} }
], filter => filter.closest('.bd-emote')); ], filter => filter.closest('.bd-emote'));

View File

@ -12,14 +12,14 @@
<div class="bd-cmGroup" ref="test"> <div class="bd-cmGroup" ref="test">
<template v-for="(item, index) in items"> <template v-for="(item, index) in items">
<CMButton v-if="!item.type || item.type === 'button'" :item="item" :onClick="() => { item.onClick(); closeMenu(); }" /> <CMButton v-if="!item.type || item.type === 'button'" :item="item" :onClick="() => { item.onClick(); closeMenu(); }" />
<CMToggle v-else-if="item.type === 'toggle'" :item="item" :checked="typeof item.checked === 'function' ? item.checked(target) : item.checked" :onClick="() => { }" /> <CMToggle v-else-if="item.type === 'toggle'" :item="item" :checked="typeof item.checked === 'function' ? item.checked(target) : item.checked" :onClick="() => { typeof item.checked === 'function' ? (item.onChange(!item.checked(target), target), $forceUpdate()) : item.onChange(!item.checked) }" />
<div v-else-if="item.type === 'sub'" class="bd-cmItem bd-cmSub" @mouseenter="e => subMenuMouseEnter(e, index, item)" @mouseleave="e => subMenuMouseLeave(e, index, item)"> <div v-else-if="item.type === 'sub'" class="bd-cmItem bd-cmSub" @mouseenter="e => subMenuMouseEnter(e, index, item)" @mouseleave="e => subMenuMouseLeave(e, index, item)">
{{item.text}} {{item.text}}
<MiChevronDown /> <MiChevronDown />
<div ref="test2" class="bd-cm" v-if="index === visibleSub" :style="subStyle"> <div ref="test2" class="bd-cm" v-if="index === visibleSub" :style="subStyle">
<template v-for="(item, index) in item.items"> <template v-for="(item, index) in item.items">
<CMButton v-if="!item.type || item.type === 'button'" :item="item" :onClick="() => { item.onClick(); closeMenu(); }" /> <CMButton v-if="!item.type || item.type === 'button'" :item="item" :onClick="() => { item.onClick(); closeMenu(); }" />
<CMToggle v-else-if="item.type === 'toggle'" :item="item" :checked="typeof item.checked === 'function' ? item.checked(target) : item.checked" :onClick="() => { }" /> <CMToggle v-else-if="item.type === 'toggle'" :item="item" :checked="typeof item.checked === 'function' ? item.checked(target) : item.checked" :onClick="() => { typeof item.checked === 'function' ? item.onChange(!item.checked(target), target) && $forceUpdate() : item.onChange(!item.checked) }" />
</template> </template>
</div> </div>
</div> </div>