ol-contextmenu
Advanced tools
Comparing version 3.3.0 to 3.3.1
@@ -1,59 +0,39 @@ | ||
/*! | ||
* ol-contextmenu - v3.3.0 | ||
* Custom Context Menu for Openlayers | ||
* https://github.com/jonataswalker/ol-contextmenu | ||
* Built: Sat Jul 28 2018 12:30:39 GMT-0300 (Brasilia Standard Time) | ||
*/ | ||
/*! | ||
* ol-contextmenu - v3.3.1 | ||
* https://github.com/jonataswalker/ol-contextmenu | ||
* Built: Wed Feb 27 2019 14:10:47 GMT-0300 (Brasilia Standard Time) | ||
*/ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('ol/control/Control')) : | ||
typeof define === 'function' && define.amd ? define(['ol/control/Control'], factory) : | ||
(global.ContextMenu = factory(global.ol.control.Control)); | ||
}(this, (function (Control) { 'use strict'; | ||
(global = global || self, global.ContextMenu = factory(global.ol.control.Control)); | ||
}(this, function (Control) { 'use strict'; | ||
Control = Control && Control.hasOwnProperty('default') ? Control['default'] : Control; | ||
var namespace = "ol-ctx-menu"; | ||
var container_class = "-container"; | ||
var separator_class = "-separator"; | ||
var submenu_class = "-submenu"; | ||
var hidden_class = "-hidden"; | ||
var icon_class = "-icon"; | ||
var zoom_in_class = "-zoom-in"; | ||
var zoom_out_class = "-zoom-out"; | ||
var ol_unselectable_class = "ol-unselectable"; | ||
var vars = { | ||
namespace: namespace, | ||
container_class: container_class, | ||
separator_class: separator_class, | ||
submenu_class: submenu_class, | ||
hidden_class: hidden_class, | ||
icon_class: icon_class, | ||
zoom_in_class: zoom_in_class, | ||
zoom_out_class: zoom_out_class, | ||
ol_unselectable_class: ol_unselectable_class | ||
}; | ||
var namespace = 'ol-ctx-menu'; | ||
var _VARS_ = /*#__PURE__*/Object.freeze({ | ||
var cssVars = { | ||
namespace: namespace, | ||
container_class: container_class, | ||
separator_class: separator_class, | ||
submenu_class: submenu_class, | ||
hidden_class: hidden_class, | ||
icon_class: icon_class, | ||
zoom_in_class: zoom_in_class, | ||
zoom_out_class: zoom_out_class, | ||
ol_unselectable_class: ol_unselectable_class, | ||
default: vars | ||
}); | ||
container: (namespace + "-container"), | ||
separator: (namespace + "-separator"), | ||
submenu: (namespace + "-submenu"), | ||
hidden: (namespace + "-hidden"), | ||
icon: (namespace + "-icon"), | ||
zoomIn: (namespace + "-zoom-in"), | ||
zoomOut: (namespace + "-zoom-out"), | ||
unselectable: 'ol-unselectable', | ||
}; | ||
const VARS = _VARS_; | ||
var CSS_VARS = cssVars; | ||
const EVENT_TYPE = { | ||
var EVENT_TYPE = { | ||
/** | ||
* Triggered before context menu is openned. | ||
* Triggered before context menu is open. | ||
*/ | ||
BEFOREOPEN: 'beforeopen', | ||
/** | ||
* Triggered when context menu is openned. | ||
* Triggered when context menu is open. | ||
*/ | ||
@@ -76,53 +56,37 @@ OPEN: 'open', | ||
*/ | ||
HOVER: 'mouseover' | ||
HOVER: 'mouseover', | ||
}; | ||
/** | ||
* DOM Elements classname | ||
*/ | ||
const CLASSNAME = { | ||
container : VARS.namespace + VARS.container_class, | ||
separator : VARS.namespace + VARS.separator_class, | ||
submenu : VARS.namespace + VARS.submenu_class, | ||
hidden : VARS.namespace + VARS.hidden_class, | ||
icon : VARS.namespace + VARS.icon_class, | ||
zoomIn : VARS.namespace + VARS.zoom_in_class, | ||
zoomOut : VARS.namespace + VARS.zoom_out_class, | ||
OL_unselectable : VARS.ol_unselectable_class | ||
}; | ||
const DEFAULT_OPTIONS = { | ||
var DEFAULT_OPTIONS = { | ||
width: 150, | ||
scrollAt: 4, | ||
eventType: EVENT_TYPE.CONTEXTMENU, | ||
defaultItems: true | ||
defaultItems: true, | ||
}; | ||
const DEFAULT_ITEMS = [ | ||
var DEFAULT_ITEMS = [ | ||
{ | ||
text: 'Zoom In', | ||
classname: ((CLASSNAME.zoomIn) + " " + (CLASSNAME.icon)), | ||
classname: ((cssVars.zoomIn) + " " + (cssVars.icon)), | ||
callback: function (obj, map) { | ||
const view = map.getView(); | ||
var view = map.getView(); | ||
view.animate({ | ||
zoom: +view.getZoom() + 1, | ||
duration: 700, | ||
center: obj.coordinate | ||
center: obj.coordinate, | ||
}); | ||
} | ||
}, | ||
}, | ||
{ | ||
text: 'Zoom Out', | ||
classname: ((CLASSNAME.zoomOut) + " " + (CLASSNAME.icon)), | ||
classname: ((cssVars.zoomOut) + " " + (cssVars.icon)), | ||
callback: function (obj, map) { | ||
const view = map.getView(); | ||
var view = map.getView(); | ||
view.animate({ | ||
zoom: +view.getZoom() - 1, | ||
duration: 700, | ||
center: obj.coordinate | ||
center: obj.coordinate, | ||
}); | ||
} | ||
} | ||
]; | ||
}, | ||
} ]; | ||
@@ -135,5 +99,5 @@ /** | ||
function mergeOptions(obj1, obj2) { | ||
let obj3 = {}; | ||
for (let attr1 in obj1) { obj3[attr1] = obj1[attr1]; } | ||
for (let attr2 in obj2) { obj3[attr2] = obj2[attr2]; } | ||
var obj3 = {}; | ||
for (var attr1 in obj1) { obj3[attr1] = obj1[attr1]; } | ||
for (var attr2 in obj2) { obj3[attr2] = obj2[attr2]; } | ||
return obj3; | ||
@@ -191,4 +155,4 @@ } | ||
const array = Array.isArray(classname) ? classname : classname.split(/\s+/); | ||
let i = array.length; | ||
var array = Array.isArray(classname) ? classname : classname.split(/\s+/); | ||
var i = array.length; | ||
@@ -214,4 +178,4 @@ while (i--) { | ||
const array = Array.isArray(classname) ? classname : classname.split(/\s+/); | ||
let i = array.length; | ||
var array = Array.isArray(classname) ? classname : classname.split(/\s+/); | ||
var i = array.length; | ||
@@ -248,3 +212,3 @@ while (i--) { | ||
let simpleRe = /^(#?[\w-]+|\.[\w-.]+)$/, | ||
var simpleRe = /^(#?[\w-]+|\.[\w-.]+)$/, | ||
periodRe = /\./g, | ||
@@ -287,4 +251,4 @@ slice = Array.prototype.slice, | ||
function offset(element) { | ||
const rect = element.getBoundingClientRect(); | ||
const docEl = document.documentElement; | ||
var rect = element.getBoundingClientRect(); | ||
var docEl = document.documentElement; | ||
return { | ||
@@ -306,3 +270,3 @@ left: rect.left + window.pageXOffset - docEl.clientLeft, | ||
function createFragment(html) { | ||
let frag = document.createDocumentFragment(), | ||
var frag = document.createDocumentFragment(), | ||
temp = document.createElement('div'); | ||
@@ -409,3 +373,3 @@ temp.innerHTML = html; | ||
let count = 0; | ||
var count = 0; | ||
Object.keys(this.items).forEach(function (k) { | ||
@@ -429,10 +393,10 @@ if (this$1.items[k].submenu || this$1.items[k].separator) { return; } | ||
const container = this.Base.container; | ||
const mapSize = this.map.getSize(); | ||
var container = this.Base.container; | ||
var mapSize = this.map.getSize(); | ||
// how much (width) space left over | ||
const space_left_h = mapSize[1] - pixel[1]; | ||
var space_left_h = mapSize[1] - pixel[1]; | ||
// how much (height) space left over | ||
const space_left_w = mapSize[0] - pixel[0]; | ||
var space_left_w = mapSize[0] - pixel[0]; | ||
const menuSize = { | ||
var menuSize = { | ||
w: container.offsetWidth, | ||
@@ -444,3 +408,3 @@ // a cheap way to recalculate container height | ||
// submenus | ||
const subs = find(("li." + (CLASSNAME.submenu) + ">div"), container, true); | ||
var subs = find(("li." + (CSS_VARS.submenu) + ">div"), container, true); | ||
@@ -463,3 +427,3 @@ if (space_left_w >= menuSize.w) { | ||
removeClass(container, CLASSNAME.hidden); | ||
removeClass(container, CSS_VARS.hidden); | ||
@@ -476,6 +440,6 @@ if (subs.length) { | ||
// is there enough space for submenu height? | ||
const viewport = getViewportSize(); | ||
const sub_offset = offset(sub); | ||
const sub_height = sub_offset.height; | ||
let sub_top = space_left_h - sub_height; | ||
var viewport = getViewportSize(); | ||
var sub_offset = offset(sub); | ||
var sub_height = sub_offset.height; | ||
var sub_top = space_left_h - sub_height; | ||
@@ -503,3 +467,3 @@ if (sub_top < 0) { | ||
this.opened = false; | ||
addClass(this.Base.container, CLASSNAME.hidden); | ||
addClass(this.Base.container, CSS_VARS.hidden); | ||
this.Base.dispatchEvent({ | ||
@@ -527,3 +491,3 @@ type: EVENT_TYPE.CLOSE, | ||
Internal.prototype.handleEvent = function handleEvent (evt) { | ||
const this_ = this; | ||
var this_ = this; | ||
@@ -551,3 +515,3 @@ this.coordinateClicked = this.map.getEventCoordinate(evt); | ||
evt.target.addEventListener( | ||
'mousedown', | ||
'click', | ||
{ | ||
@@ -564,3 +528,4 @@ handleEvent: function (e) { | ||
Internal.prototype.setItemListener = function setItemListener (li, index) { | ||
const this_ = this; | ||
var this_ = this; | ||
var statusClick = true; | ||
if (li && typeof this.items[index].callback === 'function') { | ||
@@ -572,8 +537,11 @@ (function (callback) { | ||
evt.preventDefault(); | ||
const obj = { | ||
coordinate: this_.getCoordinateClicked(), | ||
data: this_.items[index].data || null, | ||
}; | ||
this_.closeMenu(); | ||
callback(obj, this_.map); | ||
if (statusClick) { | ||
statusClick = false; | ||
var obj = { | ||
coordinate: this_.getCoordinateClicked(), | ||
data: this_.items[index].data || null, | ||
}; | ||
this_.closeMenu(); | ||
callback(obj, this_.map); | ||
} | ||
}, | ||
@@ -596,7 +564,7 @@ false | ||
Html.prototype.createContainer = function createContainer (hidden) { | ||
const container = document.createElement('div'); | ||
const ul = document.createElement('ul'); | ||
const klasses = [CLASSNAME.container, CLASSNAME.OL_unselectable]; | ||
var container = document.createElement('div'); | ||
var ul = document.createElement('ul'); | ||
var klasses = [CSS_VARS.container, CSS_VARS.unselectable]; | ||
hidden && klasses.push(CLASSNAME.hidden); | ||
hidden && klasses.push(CSS_VARS.hidden); | ||
container.className = klasses.join(' '); | ||
@@ -609,3 +577,3 @@ container.style.width = parseInt(this.Base.options.width, 10) + 'px'; | ||
Html.prototype.createMenu = function createMenu () { | ||
let items = []; | ||
var items = []; | ||
@@ -631,10 +599,10 @@ if ('items' in this.Base.options) { | ||
item.classname = item.classname || ''; | ||
if (!contains(CLASSNAME.submenu, item.classname)) { | ||
if (!contains(CSS_VARS.submenu, item.classname)) { | ||
item.classname = item.classname.length | ||
? ' ' + CLASSNAME.submenu | ||
: CLASSNAME.submenu; | ||
? ' ' + CSS_VARS.submenu | ||
: CSS_VARS.submenu; | ||
} | ||
let li = this.generateHtmlAndPublish(this.container, item); | ||
let sub = this.createContainer(); | ||
var li = this.generateHtmlAndPublish(this.container, item); | ||
var sub = this.createContainer(); | ||
sub.style.left = | ||
@@ -653,17 +621,11 @@ this.Base.Internal.submenu.lastLeft || this.Base.Internal.submenu.left; | ||
Html.prototype.generateHtmlAndPublish = function generateHtmlAndPublish (parent, item, submenu) { | ||
let html, | ||
var index = getUniqueId(); | ||
var html, | ||
frag, | ||
element, | ||
separator = false; | ||
const index = getUniqueId(); | ||
// separator | ||
if (typeof item === 'string' && item.trim() === '-') { | ||
html = [ | ||
'<li id="', | ||
index, | ||
'" class="', | ||
CLASSNAME.separator, | ||
'">', | ||
'<hr></li>' ].join(''); | ||
html = "<li id=\"" + index + "\" class=\"" + (CSS_VARS.separator) + "\"><hr></li>"; | ||
frag = createFragment(html); | ||
@@ -677,3 +639,3 @@ // http://stackoverflow.com/a/13347298/4640499 | ||
item.classname = item.classname || ''; | ||
html = '<span>' + item.text + '</span>'; | ||
html = "<span>" + (item.text) + "</span>"; | ||
frag = createFragment(html); | ||
@@ -684,5 +646,5 @@ element = document.createElement('li'); | ||
if (item.classname === '') { | ||
item.classname = CLASSNAME.icon; | ||
} else if (item.classname.indexOf(CLASSNAME.icon) === -1) { | ||
item.classname += ' ' + CLASSNAME.icon; | ||
item.classname = CSS_VARS.icon; | ||
} else if (item.classname.indexOf(CSS_VARS.icon) === -1) { | ||
item.classname += " " + (CSS_VARS.icon); | ||
} | ||
@@ -710,3 +672,3 @@ element.setAttribute('style', ("background-image:url(" + (item.icon) + ")")); | ||
Html.prototype.removeMenuEntry = function removeMenuEntry (index) { | ||
const element = find('#' + index, this.container.firstChild); | ||
var element = find('#' + index, this.container.firstChild); | ||
element && this.container.firstChild.removeChild(element); | ||
@@ -718,7 +680,7 @@ delete this.Base.Internal.items[index]; | ||
// for some reason I have to calculate with 2 items | ||
const cloned = this.container.cloneNode(); | ||
const frag = createFragment('<span>Foo</span>'); | ||
const frag2 = createFragment('<span>Foo</span>'); | ||
const element = document.createElement('li'); | ||
const element2 = document.createElement('li'); | ||
var cloned = this.container.cloneNode(); | ||
var frag = createFragment('<span>Foo</span>'); | ||
var frag2 = createFragment('<span>Foo</span>'); | ||
var element = document.createElement('li'); | ||
var element2 = document.createElement('li'); | ||
@@ -731,3 +693,3 @@ element.appendChild(frag); | ||
this.container.parentNode.appendChild(cloned); | ||
const height = cloned.offsetHeight / 2; | ||
var height = cloned.offsetHeight / 2; | ||
this.container.parentNode.removeChild(cloned); | ||
@@ -741,3 +703,3 @@ return height; | ||
*/ | ||
var Base = (function (Control$$1) { | ||
var Base = /*@__PURE__*/(function (Control) { | ||
function Base(opt_options) { | ||
@@ -757,7 +719,7 @@ if ( opt_options === void 0 ) opt_options = {}; | ||
Control$$1.call(this, { element: this.container }); | ||
Control.call(this, { element: this.container }); | ||
} | ||
if ( Control$$1 ) Base.__proto__ = Control$$1; | ||
Base.prototype = Object.create( Control$$1 && Control$$1.prototype ); | ||
if ( Control ) Base.__proto__ = Control; | ||
Base.prototype = Object.create( Control && Control.prototype ); | ||
Base.prototype.constructor = Base; | ||
@@ -839,3 +801,3 @@ | ||
Base.prototype.pop = function pop () { | ||
const keys = Object.keys(this.Internal.items); | ||
var keys = Object.keys(this.Internal.items); | ||
this.Html.removeMenuEntry(keys[keys.length - 1]); | ||
@@ -864,3 +826,3 @@ }; | ||
Base.prototype.setMap = function setMap (map) { | ||
Control$$1.prototype.setMap.call(this, map); | ||
Control.prototype.setMap.call(this, map); | ||
@@ -881,2 +843,2 @@ if (map) { | ||
}))); | ||
})); |
/*! | ||
* ol-contextmenu - v3.3.0 | ||
* Custom Context Menu for Openlayers | ||
* https://github.com/jonataswalker/ol-contextmenu | ||
* Built: Sat Jul 28 2018 12:30:39 GMT-0300 (Brasilia Standard Time) | ||
*/ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("ol/control/Control")):"function"==typeof define&&define.amd?define(["ol/control/Control"],e):t.ContextMenu=e(t.ol.control.Control)}(this,function(t){"use strict";t=t&&t.hasOwnProperty("default")?t.default:t;var e={namespace:"ol-ctx-menu",container_class:"-container",separator_class:"-separator",submenu_class:"-submenu",hidden_class:"-hidden",icon_class:"-icon",zoom_in_class:"-zoom-in",zoom_out_class:"-zoom-out",ol_unselectable_class:"ol-unselectable"};const n=Object.freeze({namespace:"ol-ctx-menu",container_class:"-container",separator_class:"-separator",submenu_class:"-submenu",hidden_class:"-hidden",icon_class:"-icon",zoom_in_class:"-zoom-in",zoom_out_class:"-zoom-out",ol_unselectable_class:"ol-unselectable",default:e}),s="beforeopen",i="open",o="close",a="contextmenu",r={container:n.namespace+n.container_class,separator:n.namespace+n.separator_class,submenu:n.namespace+n.submenu_class,hidden:n.namespace+n.hidden_class,icon:n.namespace+n.icon_class,zoomIn:n.namespace+n.zoom_in_class,zoomOut:n.namespace+n.zoom_out_class,OL_unselectable:n.ol_unselectable_class},l={width:150,scrollAt:4,eventType:a,defaultItems:!0},c=[{text:"Zoom In",classname:r.zoomIn+" "+r.icon,callback:function(t,e){const n=e.getView();n.animate({zoom:+n.getZoom()+1,duration:700,center:t.coordinate})}},{text:"Zoom Out",classname:r.zoomOut+" "+r.icon,callback:function(t,e){const n=e.getView();n.animate({zoom:+n.getZoom()-1,duration:700,center:t.coordinate})}}];function u(t,e){if(void 0===e&&(e="Assertion failed"),!t){if("undefined"!=typeof Error)throw new Error(e);throw e}}function p(t){return/^\d+$/.test(t)}function h(t,e){return t.classList?t.classList.contains(e):f(e).test(t.className)}function d(t,e,n){void 0===e&&(e=window.document);let s=/\./g,i=Array.prototype.slice,o=[];if(/^(#?[\w-]+|\.[\w-.]+)$/.test(t))switch(t[0]){case"#":o=[(a=t.substr(1),a="#"===a[0]?a.substr(1,a.length):a,document.getElementById(a))];break;case".":o=i.call(e.getElementsByClassName(t.substr(1).replace(s," ")));break;default:o=i.call(e.getElementsByTagName(t))}else o=i.call(e.querySelectorAll(t));var a;return n?o:o[0]}function m(t){let e=document.createDocumentFragment(),n=document.createElement("div");for(n.innerHTML=t;n.firstChild;)e.appendChild(n.firstChild);return e}function f(t){return new RegExp("(^|\\s+) "+t+" (\\s+|$)")}function y(t,e,n){t.classList?t.classList.add(e):t.className=(t.className+" "+e).trim(),n&&p(n)&&window.setTimeout(function(){return b(t,e)},n)}function b(t,e,n){t.classList?t.classList.remove(e):t.className=t.className.replace(f(e)," ").trim(),n&&p(n)&&window.setTimeout(function(){return y(t,e)},n)}var g=function(t){return this.Base=t,this.map=void 0,this.viewport=void 0,this.coordinateClicked=void 0,this.pixelClicked=void 0,this.lineHeight=0,this.items={},this.opened=!1,this.submenu={left:t.options.width-15+"px",lastLeft:""},this.eventHandler=this.handleEvent.bind(this),this};g.prototype.init=function(t){this.map=t,this.viewport=t.getViewport(),this.setListeners(),this.Base.Html.createMenu(),this.lineHeight=this.getItemsLength()>0?this.Base.container.offsetHeight/this.getItemsLength():this.Base.Html.cloneAndGetLineHeight()},g.prototype.getItemsLength=function(){var t=this;let e=0;return Object.keys(this.items).forEach(function(n){t.items[n].submenu||t.items[n].separator||e++}),e},g.prototype.getPixelClicked=function(){return this.pixelClicked},g.prototype.getCoordinateClicked=function(){return this.coordinateClicked},g.prototype.positionContainer=function(t){var e=this;const n=this.Base.container,s=this.map.getSize(),i=s[1]-t[1],o=s[0]-t[0],a=n.offsetWidth,l=Math.round(this.lineHeight*this.getItemsLength()),c=d("li."+r.submenu+">div",n,!0);o>=a?(n.style.right="auto",n.style.left=t[0]+5+"px"):(n.style.left="auto",n.style.right="15px"),i>=l?(n.style.bottom="auto",n.style.top=t[1]-10+"px"):(n.style.top="auto",n.style.bottom=0),function t(e,n,s){if(Array.isArray(e))return void e.forEach(function(e){return t(e,n,s)});const i=Array.isArray(n)?n:n.split(/\s+/);let o=i.length;for(;o--;)h(e,i[o])&&b(e,i[o],s)}(n,r.hidden),c.length&&(this.submenu.lastLeft=o<2*a?"-"+a+"px":this.submenu.left,c.forEach(function(t){const n={w:window.innerWidth||document.documentElement.clientWidth,h:window.innerHeight||document.documentElement.clientHeight},s=function(t){const e=t.getBoundingClientRect(),n=document.documentElement;return{left:e.left+window.pageXOffset-n.clientLeft,top:e.top+window.pageYOffset-n.clientTop,width:t.offsetWidth,height:t.offsetHeight}}(t),o=s.height;let a=i-o;a<0&&(a=o-(n.h-s.top),t.style.top="-"+a+"px"),t.style.left=e.submenu.lastLeft}))},g.prototype.openMenu=function(t,e){this.Base.dispatchEvent({type:i,pixel:t,coordinate:e}),this.opened=!0,this.positionContainer(t)},g.prototype.closeMenu=function(){this.opened=!1,function t(e,n,s){if(Array.isArray(e))return void e.forEach(function(e){return t(e,n)});const i=Array.isArray(n)?n:n.split(/\s+/);let o=i.length;for(;o--;)h(e,i[o])||y(e,i[o],s)}(this.Base.container,r.hidden),this.Base.dispatchEvent({type:o})},g.prototype.setListeners=function(){this.viewport.addEventListener(this.Base.options.eventType,this.eventHandler,!1)},g.prototype.removeListeners=function(){this.viewport.removeEventListener(this.Base.options.eventType,this.eventHandler,!1)},g.prototype.handleEvent=function(t){const e=this;this.coordinateClicked=this.map.getEventCoordinate(t),this.pixelClicked=this.map.getEventPixel(t),this.Base.dispatchEvent({type:s,pixel:this.pixelClicked,coordinate:this.coordinateClicked}),this.Base.disabled||(this.Base.options.eventType===a&&(t.stopPropagation(),t.preventDefault()),this.openMenu(this.pixelClicked,this.coordinateClicked),t.target.addEventListener("mousedown",{handleEvent:function(n){e.closeMenu(),t.target.removeEventListener(n.type,this,!1)}},!1))},g.prototype.setItemListener=function(t,e){const n=this;var s;t&&"function"==typeof this.items[e].callback&&(s=this.items[e].callback,t.addEventListener("click",function(t){t.preventDefault();const i={coordinate:n.getCoordinateClicked(),data:n.items[e].data||null};n.closeMenu(),s(i,n.map)},!1))};var v=function(t){return this.Base=t,this.Base.container=this.container=this.createContainer(),this};return v.prototype.createContainer=function(t){const e=document.createElement("div"),n=document.createElement("ul"),s=[r.container,r.OL_unselectable];return t&&s.push(r.hidden),e.className=s.join(" "),e.style.width=parseInt(this.Base.options.width,10)+"px",e.appendChild(n),e},v.prototype.createMenu=function(){let t=[];if("items"in this.Base.options?t=this.Base.options.defaultItems?this.Base.options.items.concat(c):this.Base.options.items:this.Base.options.defaultItems&&(t=c),0===t.length)return!1;t.forEach(this.addMenuEntry,this)},v.prototype.addMenuEntry=function(t){var e,n=this;if(t.items&&Array.isArray(t.items)){t.classname=t.classname||"",e=r.submenu,~t.classname.indexOf(e)||(t.classname=t.classname.length?" "+r.submenu:r.submenu);let s=this.generateHtmlAndPublish(this.container,t),i=this.createContainer();i.style.left=this.Base.Internal.submenu.lastLeft||this.Base.Internal.submenu.left,s.appendChild(i),t.items.forEach(function(t){n.generateHtmlAndPublish(i,t,!0)})}else this.generateHtmlAndPublish(this.container,t)},v.prototype.generateHtmlAndPublish=function(t,e,n){let s,i,o,a=!1;const l="_"+Math.random().toString(36).substr(2,9);return"string"==typeof e&&"-"===e.trim()?(i=m(s=['<li id="',l,'" class="',r.separator,'">',"<hr></li>"].join("")),o=[].slice.call(i.childNodes,0)[0],t.firstChild.appendChild(i),a=!0):(e.classname=e.classname||"",i=m(s="<span>"+e.text+"</span>"),o=document.createElement("li"),e.icon&&(""===e.classname?e.classname=r.icon:-1===e.classname.indexOf(r.icon)&&(e.classname+=" "+r.icon),o.setAttribute("style","background-image:url("+e.icon+")")),o.id=l,o.className=e.classname,o.appendChild(i),t.firstChild.appendChild(o)),this.Base.Internal.items[l]={id:l,submenu:n||0,separator:a,callback:e.callback,data:e.data||null},this.Base.Internal.setItemListener(o,l),o},v.prototype.removeMenuEntry=function(t){const e=d("#"+t,this.container.firstChild);e&&this.container.firstChild.removeChild(e),delete this.Base.Internal.items[t]},v.prototype.cloneAndGetLineHeight=function(){const t=this.container.cloneNode(),e=m("<span>Foo</span>"),n=m("<span>Foo</span>"),s=document.createElement("li"),i=document.createElement("li");s.appendChild(e),i.appendChild(n),t.appendChild(s),t.appendChild(i),this.container.parentNode.appendChild(t);const o=t.offsetHeight/2;return this.container.parentNode.removeChild(t),o},function(t){function e(e){void 0===e&&(e={}),u("object"==typeof e,"@param `opt_options` should be object type!"),this.options=function(t,e){let n={};for(let e in t)n[e]=t[e];for(let t in e)n[t]=e[t];return n}(l,e),this.disabled=!1,this.Internal=new g(this),this.Html=new v(this),t.call(this,{element:this.container})}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.clear=function(){Object.keys(this.Internal.items).forEach(this.Html.removeMenuEntry,this.Html)},e.prototype.close=function(){this.Internal.closeMenu()},e.prototype.enable=function(){this.disabled=!1},e.prototype.disable=function(){this.disabled=!0},e.prototype.getDefaultItems=function(){return c},e.prototype.countItems=function(){return Object.keys(this.Internal.items).length},e.prototype.extend=function(t){u(Array.isArray(t),"@param `arr` should be an Array."),t.forEach(this.push,this)},e.prototype.isOpen=function(){return this.Internal.opened},e.prototype.updatePosition=function(t){u(Array.isArray(t),"@param `pixel` should be an Array."),this.isOpen()&&this.Internal.positionContainer(t)},e.prototype.pop=function(){const t=Object.keys(this.Internal.items);this.Html.removeMenuEntry(t[t.length-1])},e.prototype.push=function(t){u(null!=t,"@param `item` must be informed."),this.Html.addMenuEntry(t)},e.prototype.shift=function(){this.Html.removeMenuEntry(Object.keys(this.Internal.items)[0])},e.prototype.setMap=function(e){t.prototype.setMap.call(this,e),e?this.Internal.init(e,this):this.Internal.removeListeners()},e}(t)}); | ||
* ol-contextmenu - v3.3.1 | ||
* https://github.com/jonataswalker/ol-contextmenu | ||
* Built: Wed Feb 27 2019 14:10:47 GMT-0300 (Brasilia Standard Time) | ||
*/ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("ol/control/Control")):"function"==typeof define&&define.amd?define(["ol/control/Control"],e):(t=t||self).ContextMenu=e(t.ol.control.Control)}(this,function(t){"use strict";t=t&&t.hasOwnProperty("default")?t.default:t;var e="ol-ctx-menu",n={namespace:e,container:e+"-container",separator:e+"-separator",submenu:e+"-submenu",hidden:e+"-hidden",icon:e+"-icon",zoomIn:e+"-zoom-in",zoomOut:e+"-zoom-out",unselectable:"ol-unselectable"},i=n,o="beforeopen",s="open",r="close",a="contextmenu",l={width:150,scrollAt:4,eventType:a,defaultItems:!0},c=[{text:"Zoom In",classname:n.zoomIn+" "+n.icon,callback:function(t,e){var n=e.getView();n.animate({zoom:+n.getZoom()+1,duration:700,center:t.coordinate})}},{text:"Zoom Out",classname:n.zoomOut+" "+n.icon,callback:function(t,e){var n=e.getView();n.animate({zoom:+n.getZoom()-1,duration:700,center:t.coordinate})}}];function h(t,e){if(void 0===e&&(e="Assertion failed"),!t){if("undefined"!=typeof Error)throw new Error(e);throw e}}function p(t){return/^\d+$/.test(t)}function u(t,e){return t.classList?t.classList.contains(e):y(e).test(t.className)}function d(t,e,n){void 0===e&&(e=window.document);var i=Array.prototype.slice,o=[];if(/^(#?[\w-]+|\.[\w-.]+)$/.test(t))switch(t[0]){case"#":o=[m(t.substr(1))];break;case".":o=i.call(e.getElementsByClassName(t.substr(1).replace(/\./g," ")));break;default:o=i.call(e.getElementsByTagName(t))}else o=i.call(e.querySelectorAll(t));return n?o:o[0]}function m(t){return t="#"===t[0]?t.substr(1,t.length):t,document.getElementById(t)}function f(t){var e=document.createDocumentFragment(),n=document.createElement("div");for(n.innerHTML=t;n.firstChild;)e.appendChild(n.firstChild);return e}function y(t){return new RegExp("(^|\\s+) "+t+" (\\s+|$)")}function v(t,e,n){t.classList?t.classList.add(e):t.className=(t.className+" "+e).trim(),n&&p(n)&&window.setTimeout(function(){return g(t,e)},n)}function g(t,e,n){t.classList?t.classList.remove(e):t.className=t.className.replace(y(e)," ").trim(),n&&p(n)&&window.setTimeout(function(){return v(t,e)},n)}var b=function(t){return this.Base=t,this.map=void 0,this.viewport=void 0,this.coordinateClicked=void 0,this.pixelClicked=void 0,this.lineHeight=0,this.items={},this.opened=!1,this.submenu={left:t.options.width-15+"px",lastLeft:""},this.eventHandler=this.handleEvent.bind(this),this};b.prototype.init=function(t){this.map=t,this.viewport=t.getViewport(),this.setListeners(),this.Base.Html.createMenu(),this.lineHeight=this.getItemsLength()>0?this.Base.container.offsetHeight/this.getItemsLength():this.Base.Html.cloneAndGetLineHeight()},b.prototype.getItemsLength=function(){var t=this,e=0;return Object.keys(this.items).forEach(function(n){t.items[n].submenu||t.items[n].separator||e++}),e},b.prototype.getPixelClicked=function(){return this.pixelClicked},b.prototype.getCoordinateClicked=function(){return this.coordinateClicked},b.prototype.positionContainer=function(t){var e=this,n=this.Base.container,o=this.map.getSize(),s=o[1]-t[1],r=o[0]-t[0],a=n.offsetWidth,l=Math.round(this.lineHeight*this.getItemsLength()),c=d("li."+i.submenu+">div",n,!0);r>=a?(n.style.right="auto",n.style.left=t[0]+5+"px"):(n.style.left="auto",n.style.right="15px"),s>=l?(n.style.bottom="auto",n.style.top=t[1]-10+"px"):(n.style.top="auto",n.style.bottom=0),function t(e,n,i){if(Array.isArray(e))e.forEach(function(e){return t(e,n,i)});else for(var o=Array.isArray(n)?n:n.split(/\s+/),s=o.length;s--;)u(e,o[s])&&g(e,o[s],i)}(n,i.hidden),c.length&&(this.submenu.lastLeft=r<2*a?"-"+a+"px":this.submenu.left,c.forEach(function(t){var n,i,o,r={w:window.innerWidth||document.documentElement.clientWidth,h:window.innerHeight||document.documentElement.clientHeight},a=(i=(n=t).getBoundingClientRect(),o=document.documentElement,{left:i.left+window.pageXOffset-o.clientLeft,top:i.top+window.pageYOffset-o.clientTop,width:n.offsetWidth,height:n.offsetHeight}),l=a.height,c=s-l;c<0&&(c=l-(r.h-a.top),t.style.top="-"+c+"px"),t.style.left=e.submenu.lastLeft}))},b.prototype.openMenu=function(t,e){this.Base.dispatchEvent({type:s,pixel:t,coordinate:e}),this.opened=!0,this.positionContainer(t)},b.prototype.closeMenu=function(){this.opened=!1,function t(e,n,i){if(Array.isArray(e))e.forEach(function(e){return t(e,n)});else for(var o=Array.isArray(n)?n:n.split(/\s+/),s=o.length;s--;)u(e,o[s])||v(e,o[s],i)}(this.Base.container,i.hidden),this.Base.dispatchEvent({type:r})},b.prototype.setListeners=function(){this.viewport.addEventListener(this.Base.options.eventType,this.eventHandler,!1)},b.prototype.removeListeners=function(){this.viewport.removeEventListener(this.Base.options.eventType,this.eventHandler,!1)},b.prototype.handleEvent=function(t){var e=this;this.coordinateClicked=this.map.getEventCoordinate(t),this.pixelClicked=this.map.getEventPixel(t),this.Base.dispatchEvent({type:o,pixel:this.pixelClicked,coordinate:this.coordinateClicked}),this.Base.disabled||(this.Base.options.eventType===a&&(t.stopPropagation(),t.preventDefault()),this.openMenu(this.pixelClicked,this.coordinateClicked),t.target.addEventListener("click",{handleEvent:function(n){e.closeMenu(),t.target.removeEventListener(n.type,this,!1)}},!1))},b.prototype.setItemListener=function(t,e){var n,i=this,o=!0;t&&"function"==typeof this.items[e].callback&&(n=this.items[e].callback,t.addEventListener("click",function(t){if(t.preventDefault(),o){o=!1;var s={coordinate:i.getCoordinateClicked(),data:i.items[e].data||null};i.closeMenu(),n(s,i.map)}},!1))};var C=function(t){return this.Base=t,this.Base.container=this.container=this.createContainer(),this};return C.prototype.createContainer=function(t){var e=document.createElement("div"),n=document.createElement("ul"),o=[i.container,i.unselectable];return t&&o.push(i.hidden),e.className=o.join(" "),e.style.width=parseInt(this.Base.options.width,10)+"px",e.appendChild(n),e},C.prototype.createMenu=function(){var t=[];if("items"in this.Base.options?t=this.Base.options.defaultItems?this.Base.options.items.concat(c):this.Base.options.items:this.Base.options.defaultItems&&(t=c),0===t.length)return!1;t.forEach(this.addMenuEntry,this)},C.prototype.addMenuEntry=function(t){var e,n=this;if(t.items&&Array.isArray(t.items)){t.classname=t.classname||"",e=i.submenu,~t.classname.indexOf(e)||(t.classname=t.classname.length?" "+i.submenu:i.submenu);var o=this.generateHtmlAndPublish(this.container,t),s=this.createContainer();s.style.left=this.Base.Internal.submenu.lastLeft||this.Base.Internal.submenu.left,o.appendChild(s),t.items.forEach(function(t){n.generateHtmlAndPublish(s,t,!0)})}else this.generateHtmlAndPublish(this.container,t)},C.prototype.generateHtmlAndPublish=function(t,e,n){var o,s,r="_"+Math.random().toString(36).substr(2,9),a=!1;return"string"==typeof e&&"-"===e.trim()?(o=f('<li id="'+r+'" class="'+i.separator+'"><hr></li>'),s=[].slice.call(o.childNodes,0)[0],t.firstChild.appendChild(o),a=!0):(e.classname=e.classname||"",o=f("<span>"+e.text+"</span>"),s=document.createElement("li"),e.icon&&(""===e.classname?e.classname=i.icon:-1===e.classname.indexOf(i.icon)&&(e.classname+=" "+i.icon),s.setAttribute("style","background-image:url("+e.icon+")")),s.id=r,s.className=e.classname,s.appendChild(o),t.firstChild.appendChild(s)),this.Base.Internal.items[r]={id:r,submenu:n||0,separator:a,callback:e.callback,data:e.data||null},this.Base.Internal.setItemListener(s,r),s},C.prototype.removeMenuEntry=function(t){var e=d("#"+t,this.container.firstChild);e&&this.container.firstChild.removeChild(e),delete this.Base.Internal.items[t]},C.prototype.cloneAndGetLineHeight=function(){var t=this.container.cloneNode(),e=f("<span>Foo</span>"),n=f("<span>Foo</span>"),i=document.createElement("li"),o=document.createElement("li");i.appendChild(e),o.appendChild(n),t.appendChild(i),t.appendChild(o),this.container.parentNode.appendChild(t);var s=t.offsetHeight/2;return this.container.parentNode.removeChild(t),s},function(t){function e(e){void 0===e&&(e={}),h("object"==typeof e,"@param `opt_options` should be object type!"),this.options=function(t,e){var n={};for(var i in t)n[i]=t[i];for(var o in e)n[o]=e[o];return n}(l,e),this.disabled=!1,this.Internal=new b(this),this.Html=new C(this),t.call(this,{element:this.container})}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.clear=function(){Object.keys(this.Internal.items).forEach(this.Html.removeMenuEntry,this.Html)},e.prototype.close=function(){this.Internal.closeMenu()},e.prototype.enable=function(){this.disabled=!1},e.prototype.disable=function(){this.disabled=!0},e.prototype.getDefaultItems=function(){return c},e.prototype.countItems=function(){return Object.keys(this.Internal.items).length},e.prototype.extend=function(t){h(Array.isArray(t),"@param `arr` should be an Array."),t.forEach(this.push,this)},e.prototype.isOpen=function(){return this.Internal.opened},e.prototype.updatePosition=function(t){h(Array.isArray(t),"@param `pixel` should be an Array."),this.isOpen()&&this.Internal.positionContainer(t)},e.prototype.pop=function(){var t=Object.keys(this.Internal.items);this.Html.removeMenuEntry(t[t.length-1])},e.prototype.push=function(t){h(null!=t,"@param `item` must be informed."),this.Html.addMenuEntry(t)},e.prototype.shift=function(){this.Html.removeMenuEntry(Object.keys(this.Internal.items)[0])},e.prototype.setMap=function(e){t.prototype.setMap.call(this,e),e?this.Internal.init(e,this):this.Internal.removeListeners()},e}(t)}); |
{ | ||
"name": "ol-contextmenu", | ||
"version": "3.3.0", | ||
"version": "3.3.1", | ||
"description": "Custom Context Menu for Openlayers", | ||
@@ -20,61 +20,32 @@ "main": "dist/ol-contextmenu.js", | ||
"scripts": { | ||
"dev": "run-s lint build:css rollup:dev", | ||
"build": "run-s lint rollup build:css", | ||
"build:css": "node build/build-css", | ||
"rollup": "rollup -c build/config.js", | ||
"rollup:dev": "rollup -w -c build/config.js", | ||
"lint": "eslint build test src examples --cache", | ||
"test": "run-s build test:unit", | ||
"dev": "rollup -w -c", | ||
"build": "rollup -c", | ||
"test": "npm run build && npm run test:unit", | ||
"test:unit": "jest", | ||
"test:unit:watch": "jest --watch" | ||
}, | ||
"jest": { | ||
"testURL": "http://localhost/", | ||
"setupFiles": [ | ||
"<rootDir>/test/env-setup.js" | ||
], | ||
"testRegex": "/test/unit/.*\\.test\\.js$", | ||
"transformIgnorePatterns": [ | ||
"node_modules/(?!(ol)/)" | ||
] | ||
}, | ||
"babel": { | ||
"presets": [ | ||
"env" | ||
] | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"autoprefixer": "^9.0.1", | ||
"babel-jest": "^23.4.2", | ||
"babel-preset-env": "^1.7.0", | ||
"boxen": "^1.3.0", | ||
"bytes": "^3.0.0", | ||
"canvas": "^1.6.11", | ||
"chalk": "^2.4.1", | ||
"cssnano": "^4.0.4", | ||
"eslint": "^5.2.0", | ||
"eslint-config-jwalker": "^5.1.1", | ||
"eslint-plugin-jest": "^21.18.0", | ||
"gzip-size": "^5.0.0", | ||
"jest": "^23.4.2", | ||
"node-sass": "^4.9.2", | ||
"node-sass-json-importer": "^3.3.1", | ||
"npm-run-all": "^4.1.3", | ||
"ol": "^5.1.3", | ||
"postcss": "^7.0.1", | ||
"postcss-import": "^11.1.0", | ||
"postcss-reporter": "^5.0.0", | ||
"rollup": "^0.63.4", | ||
"rollup-plugin-buble": "^0.19.2", | ||
"rollup-plugin-commonjs": "^9.1.4", | ||
"@babel/core": "^7.3.4", | ||
"@babel/preset-env": "^7.3.4", | ||
"autoprefixer": "^9.4.9", | ||
"babel-jest": "^24.1.0", | ||
"canvas": "^2.3.1", | ||
"eslint": "^5.14.1", | ||
"eslint-config-jwalker": "^5.2.0", | ||
"eslint-plugin-jest": "^22.3.0", | ||
"jest": "^24.1.0", | ||
"ol": "^5.3.1", | ||
"postcss": "^7.0.14", | ||
"rollup": "^1.3.1", | ||
"rollup-plugin-buble": "^0.19.6", | ||
"rollup-plugin-commonjs": "^9.2.1", | ||
"rollup-plugin-eslint": "^5.0.0", | ||
"rollup-plugin-filesize": "^4.0.1", | ||
"rollup-plugin-filesize": "^6.0.1", | ||
"rollup-plugin-includepaths": "^0.2.3", | ||
"rollup-plugin-json": "^3.0.0", | ||
"rollup-plugin-node-resolve": "^3.3.0", | ||
"rollup-plugin-uglify": "^4.0.0", | ||
"should": "^13.2.2", | ||
"uglify-es": "^3.3.9" | ||
"rollup-plugin-node-resolve": "^4.0.1", | ||
"rollup-plugin-sass": "^1.1.0", | ||
"rollup-plugin-terser": "^4.0.4", | ||
"should": "^13.2.3" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
21
50066
868