Add global contextmenu option
parent
624b2c69bd
commit
ff8a47c77c
|
@ -1,11 +1,11 @@
|
||||||
import Vue from 'vue';
|
import Vue from 'vue';
|
||||||
|
|
||||||
export declare class ContextMenu extends Vue {
|
export declare class ContextMenu extends Vue {
|
||||||
popup?: boolean;
|
|
||||||
model?: any[];
|
model?: any[];
|
||||||
appendTo?: string;
|
appendTo?: string;
|
||||||
autoZIndex?: boolean;
|
autoZIndex?: boolean;
|
||||||
baseZIndex?: number;
|
baseZIndex?: number;
|
||||||
|
global?: boolean;
|
||||||
toggle(event: Event): void;
|
toggle(event: Event): void;
|
||||||
show(event: Event, target?: any): void;
|
show(event: Event, target?: any): void;
|
||||||
hide(): void;
|
hide(): void;
|
||||||
|
|
|
@ -12,10 +12,6 @@ import ContextMenuSub from './ContextMenuSub';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
popup: {
|
|
||||||
type: Boolean,
|
|
||||||
default: false
|
|
||||||
},
|
|
||||||
model: {
|
model: {
|
||||||
type: Array,
|
type: Array,
|
||||||
default: null
|
default: null
|
||||||
|
@ -31,11 +27,16 @@ export default {
|
||||||
baseZIndex: {
|
baseZIndex: {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: 0
|
default: 0
|
||||||
|
},
|
||||||
|
global: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
target: null,
|
target: null,
|
||||||
outsideClickListener: null,
|
outsideClickListener: null,
|
||||||
resizeListener: null,
|
resizeListener: null,
|
||||||
|
documentContextMenuListener: null,
|
||||||
pageX: null,
|
pageX: null,
|
||||||
pageY: null,
|
pageY: null,
|
||||||
data() {
|
data() {
|
||||||
|
@ -47,6 +48,7 @@ export default {
|
||||||
this.restoreAppend();
|
this.restoreAppend();
|
||||||
this.unbindResizeListener();
|
this.unbindResizeListener();
|
||||||
this.unbindOutsideClickListener();
|
this.unbindOutsideClickListener();
|
||||||
|
this.unbindDocumentContextMenuListener();
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
itemClick(event) {
|
itemClick(event) {
|
||||||
|
@ -87,6 +89,10 @@ export default {
|
||||||
this.bindOutsideClickListener();
|
this.bindOutsideClickListener();
|
||||||
this.bindResizeListener();
|
this.bindResizeListener();
|
||||||
|
|
||||||
|
if (this.global) {
|
||||||
|
this.bindDocumentContextMenuListener();
|
||||||
|
}
|
||||||
|
|
||||||
if (this.autoZIndex) {
|
if (this.autoZIndex) {
|
||||||
this.$refs.container.style.zIndex = String(this.baseZIndex + DomHandler.generateZIndex());
|
this.$refs.container.style.zIndex = String(this.baseZIndex + DomHandler.generateZIndex());
|
||||||
}
|
}
|
||||||
|
@ -94,6 +100,10 @@ export default {
|
||||||
onLeave() {
|
onLeave() {
|
||||||
this.unbindOutsideClickListener();
|
this.unbindOutsideClickListener();
|
||||||
this.unbindResizeListener();
|
this.unbindResizeListener();
|
||||||
|
|
||||||
|
if (this.global) {
|
||||||
|
this.unbindDocumentContextMenuListener();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
position() {
|
position() {
|
||||||
let left = this.pageX + 1;
|
let left = this.pageX + 1;
|
||||||
|
@ -172,6 +182,21 @@ export default {
|
||||||
else
|
else
|
||||||
document.getElementById(this.appendTo).removeChild(this.$refs.container);
|
document.getElementById(this.appendTo).removeChild(this.$refs.container);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
bindDocumentContextMenuListener() {
|
||||||
|
if (!this.documentContextMenuListener) {
|
||||||
|
this.documentContextMenuListener = (event) => {
|
||||||
|
this.show(event);
|
||||||
|
};
|
||||||
|
|
||||||
|
document.addEventListener('contextmenu', this.documentContextMenuListener);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
unbindDocumentContextMenuListener() {
|
||||||
|
if(this.documentContextMenuListener) {
|
||||||
|
document.removeEventListener('contextmenu', this.documentContextMenuListener);
|
||||||
|
this.documentContextMenuListener = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
|
|
@ -12,9 +12,6 @@ import TieredMenu from 'primevue/tieredmenu';
|
||||||
|
|
||||||
<h3>Getting Started</h3>
|
<h3>Getting Started</h3>
|
||||||
<p>TieredMenu requires a collection of menuitems as its model.</p>
|
<p>TieredMenu requires a collection of menuitems as its model.</p>
|
||||||
<CodeHighlight>
|
|
||||||
<TieredMenu :model="items" />
|
|
||||||
</CodeHighlight>
|
|
||||||
|
|
||||||
<CodeHighlight lang="js">
|
<CodeHighlight lang="js">
|
||||||
export default {
|
export default {
|
||||||
|
@ -156,17 +153,32 @@ export default {
|
||||||
}
|
}
|
||||||
</CodeHighlight>
|
</CodeHighlight>
|
||||||
|
|
||||||
<h3>Popup Mode</h3>
|
<h3>Document Menu</h3>
|
||||||
<p>TieredMenu is inline by default whereas popup mode is supported by enabling popup property and calling toggle method with an event of the target.</p>
|
<p>Setting global property attaches the context menu to the document.</p>
|
||||||
|
<CodeHighlight>
|
||||||
|
<ContextMenu :global="true" :model="items" />
|
||||||
|
</CodeHighlight>
|
||||||
|
|
||||||
|
<h3>Element Menu</h3>
|
||||||
|
<p>ContextMenu is attached to a custom element manually using the reference and calling the <i>show(event)</i> method.</p>
|
||||||
|
|
||||||
<CodeHighlight>
|
<CodeHighlight>
|
||||||
<Button type="button" label="Toggle" @click="toggle" />
|
<img alt="logo" src="demo/images/nature/nature3.jpg" @contextmenu="onImageRightClick">
|
||||||
<TieredMenu ref="menu" :model="items" :popup="true" />
|
<ContextMenu ref="menu" :model="items" />
|
||||||
</CodeHighlight>
|
</CodeHighlight>
|
||||||
|
|
||||||
<CodeHighlight lang="js">
|
<CodeHighlight lang="js">
|
||||||
toggle(event) {
|
export default {
|
||||||
this.$refs.menu.toggle(event);
|
data() {
|
||||||
|
return {
|
||||||
|
items: //items
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
onImageRightClick(event) {
|
||||||
|
this.$refs.menu.show(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</CodeHighlight>
|
</CodeHighlight>
|
||||||
|
|
||||||
|
@ -189,12 +201,6 @@ toggle(event) {
|
||||||
<td>null</td>
|
<td>null</td>
|
||||||
<td>An array of menuitems.</td>
|
<td>An array of menuitems.</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
|
||||||
<td>popup</td>
|
|
||||||
<td>boolean</td>
|
|
||||||
<td>false</td>
|
|
||||||
<td>Defines if menu would displayed as a popup.</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>appendTo</td>
|
<td>appendTo</td>
|
||||||
<td>string</td>
|
<td>string</td>
|
||||||
|
@ -212,6 +218,12 @@ toggle(event) {
|
||||||
<td>boolean</td>
|
<td>boolean</td>
|
||||||
<td>true</td>
|
<td>true</td>
|
||||||
<td>Whether to automatically manage layering.</td>
|
<td>Whether to automatically manage layering.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>global</td>
|
||||||
|
<td>boolean</td>
|
||||||
|
<td>false</td>
|
||||||
|
<td>Attaches the menu to document instead of a particular item.</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
@ -231,18 +243,17 @@ toggle(event) {
|
||||||
<tr>
|
<tr>
|
||||||
<td>toggle</td>
|
<td>toggle</td>
|
||||||
<td>event: Browser event</td>
|
<td>event: Browser event</td>
|
||||||
<td>Toggles the visiblity of the overlay.</td>
|
<td>Toggles the visibility of the menu.</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>show</td>
|
<td>show</td>
|
||||||
<td>event: Browser event <br />
|
<td>event: Browser event</td>
|
||||||
target: Optional target if event.target would not be used</td>
|
<td>Shows the menu.</td>
|
||||||
<td>Shows the overlay.</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>hide</td>
|
<td>hide</td>
|
||||||
<td>-</td>
|
<td>-</td>
|
||||||
<td>Hides the overlay.</td>
|
<td>Hides the menu.</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
@ -260,7 +271,7 @@ toggle(event) {
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td>p-tieredmenu</td>
|
<td>p-contextmenu</td>
|
||||||
<td>Container element.</td>
|
<td>Container element.</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -292,17 +303,13 @@ toggle(event) {
|
||||||
</TabPanel>
|
</TabPanel>
|
||||||
|
|
||||||
<TabPanel header="Source">
|
<TabPanel header="Source">
|
||||||
<a href="https://github.com/primefaces/primevue/tree/master/src/views/tieredmenu" class="btn-viewsource" target="_blank" rel="noopener noreferrer">
|
<a href="https://github.com/primefaces/primevue/tree/master/src/views/contextmenu" class="btn-viewsource" target="_blank" rel="noopener noreferrer">
|
||||||
<span>View on GitHub</span>
|
<span>View on GitHub</span>
|
||||||
</a>
|
</a>
|
||||||
<CodeHighlight>
|
<CodeHighlight>
|
||||||
<template v-pre>
|
<template v-pre>
|
||||||
<h3>Inline</h3>
|
<img alt="logo" src="demo/images/nature/nature3.jpg" @contextmenu="onImageRightClick">
|
||||||
<TieredMenu :model="items" />
|
<ContextMenu ref="menu" :model="items" />
|
||||||
|
|
||||||
<h3>Overlay</h3>
|
|
||||||
<Button type="button" label="Toggle" @click="toggle" />
|
|
||||||
<TieredMenu ref="menu" :model="items" :popup="true" />
|
|
||||||
</template>
|
</template>
|
||||||
</CodeHighlight>
|
</CodeHighlight>
|
||||||
|
|
||||||
|
@ -444,8 +451,8 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
toggle(event) {
|
onImageRightClick(event) {
|
||||||
this.$refs.menu.toggle(event);
|
this.$refs.menu.show(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,7 +143,7 @@ toggle(event) {
|
||||||
<tr>
|
<tr>
|
||||||
<td>toggle</td>
|
<td>toggle</td>
|
||||||
<td>event: Browser event</td>
|
<td>event: Browser event</td>
|
||||||
<td>Toggles the visiblity of the overlay.</td>
|
<td>Toggles the visibility of the overlay.</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>show</td>
|
<td>show</td>
|
||||||
|
|
|
@ -224,7 +224,7 @@ export default {
|
||||||
</TabPanel>
|
</TabPanel>
|
||||||
|
|
||||||
<TabPanel header="Source">
|
<TabPanel header="Source">
|
||||||
<a href="https://github.com/primefaces/primevue/tree/master/src/views/tieredmenu" class="btn-viewsource" target="_blank" rel="noopener noreferrer">
|
<a href="https://github.com/primefaces/primevue/tree/master/src/views/menubar" class="btn-viewsource" target="_blank" rel="noopener noreferrer">
|
||||||
<span>View on GitHub</span>
|
<span>View on GitHub</span>
|
||||||
</a>
|
</a>
|
||||||
<CodeHighlight>
|
<CodeHighlight>
|
||||||
|
|
|
@ -92,7 +92,7 @@ toggle(event) {
|
||||||
<tr>
|
<tr>
|
||||||
<td>toggle</td>
|
<td>toggle</td>
|
||||||
<td>event: Browser event</td>
|
<td>event: Browser event</td>
|
||||||
<td>Toggles the visiblity of the overlay.</td>
|
<td>Toggles the visibility of the overlay.</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>show</td>
|
<td>show</td>
|
||||||
|
|
|
@ -231,7 +231,7 @@ toggle(event) {
|
||||||
<tr>
|
<tr>
|
||||||
<td>toggle</td>
|
<td>toggle</td>
|
||||||
<td>event: Browser event</td>
|
<td>event: Browser event</td>
|
||||||
<td>Toggles the visiblity of the overlay.</td>
|
<td>Toggles the visibility of the overlay.</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>show</td>
|
<td>show</td>
|
||||||
|
|
Loading…
Reference in New Issue