Skip to content

Commit 17f1909

Browse files
Merge pull request #122 from jonataswalker/v3
Rewrite to v3
2 parents cad6a46 + 36100f5 commit 17f1909

38 files changed

+12448
-7016
lines changed

.eslintrc.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = {
2+
extends: ['jwalker'],
3+
rules: {
4+
'no-console': 1
5+
},
6+
globals: {
7+
ContextMenu: true,
8+
ol: true,
9+
},
10+
};

.travis.yml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,30 @@ sudo: required
22
dist: trusty
33

44
language: node_js
5-
65
node_js:
7-
- "6"
6+
- "8"
87

98
cache:
109
bundler: true
1110
directories:
12-
- travis-phantomjs
1311
- node_modules
1412

13+
addons:
14+
chrome: stable
15+
1516
before_install:
16-
# PhantomJS
17-
- "if [ $(phantomjs --version) != '2.1.1' ]; then rm -rf $PWD/travis-phantomjs; mkdir -p $PWD/travis-phantomjs; fi"
18-
- "if [ $(phantomjs --version) != '2.1.1' ]; then wget https://github.com/BIGjuevos/phantomjs-builds/archive/v2.1.1.tar.gz -O $PWD/travis-phantomjs/v2.1.1.tar.gz; fi"
19-
- "if [ $(phantomjs --version) != '2.1.1' ]; then tar -xf $PWD/travis-phantomjs/v2.1.1.tar.gz -C $PWD/travis-phantomjs; fi"
20-
- "if [ $(phantomjs --version) != '2.1.1' ]; then sudo ln -sf $PWD/travis-phantomjs/phantomjs-builds-2.1.1/bin/phantomjs $(which phantomjs); fi"
21-
- "phantomjs --version"
17+
- stty cols 80
18+
- sudo apt-get -qq update
19+
- sudo apt-get install -y libcairo2-dev libjpeg8-dev libpango1.0-dev libgif-dev build-essential g++
20+
- sudo apt-get install -y fluxbox
21+
- npm i -g npm@5
2222

2323
before_script:
24-
25-
script:
26-
- xvfb-run -a npm run test
24+
- "export DISPLAY=:99.0"
25+
- "sh -e /etc/init.d/xvfb start"
26+
- sleep 3
27+
- fluxbox >/dev/null 2>&1 &
2728

2829
branches:
2930
only:
3031
- "master"
31-
- /^greenkeeper-.*$/

README.md

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,45 @@
11
# OpenLayers Custom Context Menu
22

33
<p align="center">
4-
<a href="https://travis-ci.org/jonataswalker/ol3-contextmenu">
5-
<img src="https://travis-ci.org/jonataswalker/ol3-contextmenu.svg?branch=master" alt="build status">
4+
<a href="https://travis-ci.org/jonataswalker/ol-contextmenu">
5+
<img src="https://travis-ci.org/jonataswalker/ol-contextmenu.svg?branch=master" alt="build status">
66
</a>
7-
<a href="https://www.npmjs.com/package/ol3-contextmenu">
8-
<img src="https://img.shields.io/npm/v/ol3-contextmenu.svg"
7+
<a href="https://www.npmjs.com/package/ol-contextmenu">
8+
<img src="https://img.shields.io/npm/v/ol-contextmenu.svg"
99
alt="npm version">
1010
</a>
11-
<a href="https://github.com/jonataswalker/ol3-contextmenu/blob/master/LICENSE">
12-
<img src="https://img.shields.io/npm/l/ol3-contextmenu.svg"
11+
<a href="https://github.com/jonataswalker/ol-contextmenu/blob/master/LICENSE">
12+
<img src="https://img.shields.io/npm/l/ol-contextmenu.svg"
1313
alt="license">
1414
</a>
15-
<a href="https://david-dm.org/jonataswalker/ol3-contextmenu">
16-
<img src="https://david-dm.org/jonataswalker/ol3-contextmenu/status.svg"
15+
<a href="https://david-dm.org/jonataswalker/ol-contextmenu">
16+
<img src="https://david-dm.org/jonataswalker/ol-contextmenu/status.svg"
1717
alt="dependency status">
1818
</a>
19-
<a href="https://david-dm.org/jonataswalker/ol3-contextmenu">
20-
<img src="https://david-dm.org/jonataswalker/ol3-contextmenu/dev-status.svg" alt="devDependency status">
19+
<a href="https://david-dm.org/jonataswalker/ol-contextmenu">
20+
<img src="https://david-dm.org/jonataswalker/ol-contextmenu/dev-status.svg" alt="devDependency status">
2121
</a>
2222
</p>
2323

2424
A `contextmenu` extension for [OpenLayers](http://openlayers.org/). **Requires** OpenLayers **v3.11.0** or higher.
2525

26-
![contextmenu anim](https://raw.githubusercontent.com/jonataswalker/ol3-contextmenu/screenshot/images/anim.gif)
26+
![contextmenu anim](https://raw.githubusercontent.com/jonataswalker/ol-contextmenu/screenshot/images/anim.gif)
2727

2828
## Demo
29-
You can see [here a demo](http://rawgit.com/jonataswalker/ol3-contextmenu/master/examples/contextmenu.html) or [JSFiddle](https://jsfiddle.net/jonataswalker/ooxs1w5d/).
29+
You can see [here a demo](http://rawgit.com/jonataswalker/ol-contextmenu/master/examples/contextmenu.html) or [JSFiddle](https://jsfiddle.net/jonataswalker/ooxs1w5d/).
3030

3131
## How to use it?
32-
##### CDN Hosted - [jsDelivr](http://www.jsdelivr.com/projects/openlayers.contextmenu)
33-
Load CSS and Javascript:
34-
```HTML
35-
<link href="//cdn.jsdelivr.net/openlayers.contextmenu/latest/ol3-contextmenu.min.css" rel="stylesheet">
36-
<script src="//cdn.jsdelivr.net/openlayers.contextmenu/latest/ol3-contextmenu.js"></script>
37-
```
32+
##### NPM
33+
`npm install ol-contextmenu`
34+
3835
##### CDN Hosted - UNPKG
3936
Load CSS and Javascript:
4037
```HTML
41-
<link href="https://unpkg.com/ol3-contextmenu/build/ol3-contextmenu.min.css" rel="stylesheet">
42-
<script src="https://unpkg.com/ol3-contextmenu/build/ol3-contextmenu.js"></script>
38+
<link href="https://unpkg.com/ol-contextmenu/dist/ol-contextmenu.min.css" rel="stylesheet">
39+
<script src="https://unpkg.com/ol-contextmenu"></script>
4340
```
4441
##### Self hosted
45-
Download [latest release](https://github.com/jonataswalker/ol3-contextmenu/releases/latest) and (obviously) load CSS and Javascript.
42+
Download [latest release](https://github.com/jonataswalker/ol-contextmenu/releases/latest) and (obviously) load CSS and Javascript.
4643

4744
##### Instantiate with some options and add the Control
4845
```javascript
@@ -98,7 +95,7 @@ var all_items = [
9895

9996
##### Would you like to propagate custom data to the callback handler?
10097
```javascript
101-
var removeMarker = function(obj){
98+
var removeMarker = function (obj) {
10299
vectorLayer.getSource().removeFeature(obj.data.marker);
103100
};
104101
var removeMarkerItem = {
@@ -108,15 +105,13 @@ var removeMarkerItem = {
108105
};
109106

110107
var restore = false;
111-
contextmenu.on('open', function(evt){
112-
var feature = map.forEachFeatureAtPixel(evt.pixel, function(ft, l){
108+
contextmenu.on('open', function (evt) {
109+
var feature = map.forEachFeatureAtPixel(evt.pixel, function (ft, l) {
113110
return ft;
114111
});
115112
if (feature) {
116113
contextmenu.clear();
117-
removeMarkerItem.data = {
118-
marker: feature
119-
};
114+
removeMarkerItem.data = { marker: feature };
120115
contextmenu.push(removeMarkerItem);
121116
restore = true;
122117
} else if (restore) {
@@ -206,8 +201,8 @@ Update menu's position.
206201
#### If you want to disable this plugin under certain circumstances, listen to `beforeopen`
207202

208203
```javascript
209-
contextmenu.on('beforeopen', function(evt){
210-
var feature = map.forEachFeatureAtPixel(evt.pixel, function(ft, l){
204+
contextmenu.on('beforeopen', function (evt) {
205+
var feature = map.forEachFeatureAtPixel(evt.pixel, function (ft, l) {
211206
return ft;
212207
});
213208

@@ -223,7 +218,7 @@ contextmenu.on('beforeopen', function(evt){
223218

224219
```javascript
225220
contextmenu.on('open', function(evt){
226-
var feature = map.forEachFeatureAtPixel(evt.pixel, function(ft, l){
221+
var feature = map.forEachFeatureAtPixel(evt.pixel, function (ft, l) {
227222
return ft;
228223
});
229224

@@ -236,7 +231,7 @@ contextmenu.on('open', function(evt){
236231
#### Any action when context menu gets closed?
237232

238233
```javascript
239-
contextmenu.on('close', function(evt){
234+
contextmenu.on('close', function (evt) {
240235
// it's upon you
241236
});
242237
```

build-css.js

Lines changed: 0 additions & 66 deletions
This file was deleted.

build-js.js

Lines changed: 0 additions & 70 deletions
This file was deleted.
File renamed without changes.

build/build-css.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
const { writeFileSync, readFileSync } = require('fs');
2+
const boxen = require('boxen');
3+
const chalk = require('chalk');
4+
const gzip = require('gzip-size');
5+
const bytes = require('bytes');
6+
const sass = require('node-sass');
7+
const jsonImporter = require('node-sass-json-importer');
8+
const autoprefixer = require('autoprefixer');
9+
const postcss = require('postcss');
10+
const postcssReport = require('postcss-reporter');
11+
const cssnano = require('cssnano');
12+
const pkg = require('../package.json');
13+
14+
var banner = readFileSync('./build/banner.js', 'utf-8')
15+
.replace('${name}', pkg.name)
16+
.replace('${description}', pkg.description)
17+
.replace('${homepage}', pkg.homepage)
18+
.replace('${version}', pkg.version)
19+
.replace('${time}', new Date());
20+
21+
22+
sass.render({
23+
file: './src/sass/main.scss',
24+
importer: jsonImporter
25+
}, (err, result) => {
26+
if (err) throw err.message;
27+
28+
const prefixer = postcss([
29+
autoprefixer({ browsers: ['> 5%'] }),
30+
postcssReport({ clearMessages: true })
31+
]);
32+
prefixer.process(result.css).then(res => {
33+
res.warnings().forEach((warn) => {
34+
console.warn(warn.toString());
35+
});
36+
37+
writeFileSync('./dist/ol-contextmenu.css', banner + res.css);
38+
39+
cssnano.process(res.css).then(min => {
40+
writeFileSync('./dist/ol-contextmenu.min.css', banner + min.css);
41+
42+
const cssSize = bytes(Buffer.byteLength(res.css));
43+
const cssMinSize = bytes(Buffer.byteLength(min.css));
44+
const cssGzip = bytes(gzip.sync(res.css));
45+
const cssMinGzip = bytes(gzip.sync(min.css));
46+
47+
// eslint-disable-next-line no-console
48+
console.log(boxen([
49+
chalk.green.bold('CSS: '),
50+
chalk.yellow.bold(cssSize), ', ',
51+
chalk.green.bold('Gzipped: '),
52+
chalk.yellow.bold(cssGzip), '\n',
53+
chalk.green.bold('Minified: '),
54+
chalk.yellow.bold(cssMinSize), ', ',
55+
chalk.green.bold('Gzipped: '),
56+
chalk.yellow.bold(cssMinGzip), '\n',
57+
chalk.green.bold('Now: '),
58+
chalk.yellow.bold(new Date())
59+
].join(''), { padding: 1 }));
60+
});
61+
});
62+
});

0 commit comments

Comments
 (0)