Add v-contextmenu directive

This commit is contained in:
Samuel Elliott 2018-08-22 20:58:00 +01:00
parent c2ccfd02da
commit 697df8a7fe
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6
3 changed files with 16 additions and 3 deletions

View File

@ -39,11 +39,11 @@
this.top = window.innerHeight - this.mouseY - height < 0 ? this.mouseY - height : this.mouseY;
this.left = window.innerWidth - this.mouseX - 170 < 0 ? this.mouseX - 170 : this.mouseX;
this.renderLeft = (this.left + 170 * 2) > window.innerWidth;
window.addEventListener('mouseup', this.clickHide);
window.addEventListener('mousedown', this.clickHide);
return { top: `${this.top}px`, left: `${this.left}px` };
},
hide() {
window.removeEventListener('mouseup', this.clickHide);
window.removeEventListener('mousedown', this.clickHide);
this.activeMenu.menu = null;
},
clickHide(e) {

View File

@ -8,7 +8,7 @@
* LICENSE file in the root directory of this source tree.
*/
import { Utils } from 'common';
import { Utils, ClientLogger as Logger } from 'common';
import { ReactComponents, WebpackModules, MonkeyPatch } from 'modules';
import { VueInjector, Toasts } from 'ui';
import CMGroup from './components/contextmenu/Group.vue';
@ -30,6 +30,17 @@ export class BdContextMenu {
return this._activeMenu || (this._activeMenu = { menu: null });
}
static install(Vue) {
Vue.directive('contextmenu', {
bind(el, binding) {
el.addEventListener('contextmenu', event => {
Logger.log('BdContextMenu', ['Showing context menu', event, el, binding]);
BdContextMenu.show(event, binding.value);
});
}
});
}
}
export class DiscordContextMenu {

View File

@ -12,6 +12,7 @@ import Vue from 'vue';
import VTooltip from 'v-tooltip';
import DOM from './dom';
import VueInjector from './vueinjector';
import { BdContextMenu } from './contextmenus';
Vue.use(VTooltip, {
defaultContainer: 'bd-tooltips',
@ -46,5 +47,6 @@ Vue.use(VTooltip, {
});
Vue.use(VueInjector);
Vue.use(BdContextMenu);
export default Vue;