|
1 | 1 | (function(win, doc){
|
2 | 2 | ContextMenu.Internal = function(menu){
|
3 | 3 | this.map = undefined;
|
| 4 | + this.contextmenu = menu; |
4 | 5 | this.container = menu.container;
|
5 | 6 | this.$html = menu.$html;
|
6 | 7 | this.coordinate_clicked = undefined;
|
|
16 | 17 | getCoordinateClicked: function() {
|
17 | 18 | return this.coordinate_clicked;
|
18 | 19 | },
|
19 |
| - openMenu: function(pixel) { |
| 20 | + openMenu: function(pixel, coordinate) { |
20 | 21 | var
|
21 | 22 | this_ = this,
|
22 | 23 | map_size = this.map.getSize(),
|
|
39 | 40 | utils.removeClass(this.container, 'hidden');
|
40 | 41 | this.container.style.left = left + 'px';
|
41 | 42 | this.container.style.top = top + 'px';
|
| 43 | + this.contextmenu.dispatchEvent({ |
| 44 | + type: ContextMenu.EventType.OPEN, |
| 45 | + pixel: pixel, |
| 46 | + coordinate: coordinate, |
| 47 | + }); |
42 | 48 | },
|
43 | 49 | closeMenu: function(){
|
44 | 50 | utils.addClass(this.container, 'hidden');
|
| 51 | + this.contextmenu.dispatchEvent({ |
| 52 | + type: ContextMenu.EventType.CLOSE |
| 53 | + }); |
45 | 54 | },
|
46 | 55 | getNextItemIndex: function(){
|
47 | 56 | return Object.keys(ContextMenu.items).length;
|
|
54 | 63 | menu = function(evt){
|
55 | 64 | evt.stopPropagation();
|
56 | 65 | evt.preventDefault();
|
57 |
| - this_.openMenu(map.getEventPixel(evt)); |
58 | 66 | this_.coordinate_clicked = map.getEventCoordinate(evt);
|
| 67 | + this_.openMenu(map.getEventPixel(evt), this_.coordinate_clicked); |
59 | 68 |
|
60 | 69 | //one-time fire
|
61 | 70 | canvas.addEventListener('mousedown', {
|
|
82 | 91 | li.addEventListener('click', function(evt){
|
83 | 92 | evt.preventDefault();
|
84 | 93 | var obj = {
|
85 |
| - coordinate: this_.getCoordinateClicked() |
| 94 | + coordinate: this_.getCoordinateClicked(), |
86 | 95 | data: ContextMenu.items[index].data || null
|
87 | 96 | };
|
88 | 97 | this_.closeMenu();
|
|
93 | 102 | }
|
94 | 103 | };
|
95 | 104 |
|
| 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 | + |
96 | 116 | ContextMenu.items = {};
|
97 | 117 |
|
98 | 118 | ContextMenu.defaultItems = [
|
|
0 commit comments