ForgeComponents
en

Components

j-ContextMenu

jComponent 20 · jcomponent@20 component Example loaded with jComponent 20
  • supports 3 orientations left, center and right
  • singleton
  • works with Bootstrap Grid System
  • works with touches

Methods:

Method: component.show(orientation, targetElement, [items], clickCallback, [offsetX], [offsetY])

  • orientation {String} can be left, center or right
  • targetElement {Selector/jQuery/Element} a target where the component will be visible
  • items {Array} optional and must have this structure: [{ name: String, value: String, icon: String }] otherwise will be items read from the target's data-options attribute.
  • callback(selectedValue) {Function} is triggered when the user clicks on the item
  • offsetX {Number} optional can change offset X
  • offsetY {Number} optional can change offset Y

Method: component.hide()

Attributes:

targetElement can contain data-options="Name 1|fa-building|Value 1;Name 2|fa-github|Value 2;" attribut with all items of the context menu.

If the value isn't defined then the component uses name as value.

Global events:

ON('contextmenu', function(visible, component, target) {
    console.log('ContextMenu is', visible ? 'visible' : 'hidden');
});

Use it with <ui-component name="contextmenu">. When the component is not loaded yet, jComponent downloads it on first use from the address in DEF.fallback (the Componentator CDN by default). Author: Peter Širka. Source: the Componentator components repository, MIT license.

example.html
<style>
	body { background-color: #F0F0F0; }
</style>

<ui-component name="contextmenu"></ui-component>

<div class="container">
	<a href="javascript:void(0)">Edit</a>
</div>

<script>
	$(document).on('click', 'a', function() {
		SETTER('contextmenu/show', 'left', this, [{ name: 'Print', icon: 'ti-print', value: 'print' }, { name: 'Copy', icon: 'ti-copy', value: 'copy' }, { name: 'Remove', icon: 'ti-times-circle', value: 'remove' }], function(item) {
			console.log('CLICK', item);
		});
	});
</script>