Skip to content

Commit fb3433b

Browse files
committed
Added and events
1 parent 880c604 commit fb3433b

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

src/internal.js

+23-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
(function(win, doc){
22
ContextMenu.Internal = function(menu){
33
this.map = undefined;
4+
this.contextmenu = menu;
45
this.container = menu.container;
56
this.$html = menu.$html;
67
this.coordinate_clicked = undefined;
@@ -16,7 +17,7 @@
1617
getCoordinateClicked: function() {
1718
return this.coordinate_clicked;
1819
},
19-
openMenu: function(pixel) {
20+
openMenu: function(pixel, coordinate) {
2021
var
2122
this_ = this,
2223
map_size = this.map.getSize(),
@@ -39,9 +40,17 @@
3940
utils.removeClass(this.container, 'hidden');
4041
this.container.style.left = left + 'px';
4142
this.container.style.top = top + 'px';
43+
this.contextmenu.dispatchEvent({
44+
type: ContextMenu.EventType.OPEN,
45+
pixel: pixel,
46+
coordinate: coordinate,
47+
});
4248
},
4349
closeMenu: function(){
4450
utils.addClass(this.container, 'hidden');
51+
this.contextmenu.dispatchEvent({
52+
type: ContextMenu.EventType.CLOSE
53+
});
4554
},
4655
getNextItemIndex: function(){
4756
return Object.keys(ContextMenu.items).length;
@@ -54,8 +63,8 @@
5463
menu = function(evt){
5564
evt.stopPropagation();
5665
evt.preventDefault();
57-
this_.openMenu(map.getEventPixel(evt));
5866
this_.coordinate_clicked = map.getEventCoordinate(evt);
67+
this_.openMenu(map.getEventPixel(evt), this_.coordinate_clicked);
5968

6069
//one-time fire
6170
canvas.addEventListener('mousedown', {
@@ -82,7 +91,7 @@
8291
li.addEventListener('click', function(evt){
8392
evt.preventDefault();
8493
var obj = {
85-
coordinate: this_.getCoordinateClicked()
94+
coordinate: this_.getCoordinateClicked(),
8695
data: ContextMenu.items[index].data || null
8796
};
8897
this_.closeMenu();
@@ -93,6 +102,17 @@
93102
}
94103
};
95104

105+
ContextMenu.EventType = {
106+
/**
107+
* Triggered when context menu is openned.
108+
*/
109+
OPEN: 'open',
110+
/**
111+
* Triggered when context menu is closed.
112+
*/
113+
CLOSE: 'close'
114+
};
115+
96116
ContextMenu.items = {};
97117

98118
ContextMenu.defaultItems = [

0 commit comments

Comments
 (0)