components-context-menu.js
1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
var ComponentsContextMenu = function () {
var demo2 = function() {
$('#main').contextmenu({
target: '#context-menu2',
before: function (e) {
// This function is optional.
// Here we use it to stop the event if the user clicks a span
e.preventDefault();
if (e.target.tagName == 'SPAN') {
e.preventDefault();
this.closemenu();
return false;
}
//this.getMenu().find("li").eq(2).find('a').html("Dynamically changed!");
return true;
}
});
}
var demo3 = function() {
// Demo 3
$('#context2').contextmenu({
target: '#context-menu2',
onItem: function (context, e) {
if ($(e.target).data('url')) {
this.closemenu();
} else {
alert($(e.target).text());
}
}
});
$('#context-menu2').on('show.bs.context', function (e) {
console.log('before show event');
});
$('#context-menu2').on('shown.bs.context', function (e) {
console.log('after show event');
});
$('#context-menu2').on('hide.bs.context', function (e) {
console.log('before hide event');
});
$('#context-menu2').on('hidden.bs.context', function (e) {
console.log('after hide event');
});
}
return {
//main function to initiate the module
init: function () {
demo2();
demo3();
}
};
}();
jQuery(document).ready(function() {
ComponentsContextMenu.init();
});