Skip to content

Commit

Permalink
Review
Browse files Browse the repository at this point in the history
- Add stylelint
- Add prettier
- ESLint
  - switch to flat config
  - use recommended rules and define some exceptions
- Handle linter and format issues
- Add .gitignore to ignore node_modules directory
- Add license name to LICENSE file (like here https://choosealicense.com/licenses/mit/)
  • Loading branch information
KristjanESPERANTO authored and brunob committed Jan 22, 2024
1 parent 4c08f8e commit 51425fd
Show file tree
Hide file tree
Showing 13 changed files with 3,165 additions and 174 deletions.
33 changes: 0 additions & 33 deletions .eslintrc

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.js
package.json
package-lock.json
6 changes: 6 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"printWidth": 180,
"singleQuote": true,
"trailingComma": "none",
"useTabs": true
}
8 changes: 8 additions & 0 deletions .stylelintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": ["stylelint-config-standard"],
"plugins": ["stylelint-prettier"],
"root": true,
"rules": {
"prettier/prettier": true
}
}
49 changes: 39 additions & 10 deletions Control.FullScreen.css
Original file line number Diff line number Diff line change
@@ -1,10 +1,39 @@
.fullscreen-icon { background-image: url(icon-fullscreen.svg); background-size:26px 52px; }
.fullscreen-icon.leaflet-fullscreen-on { background-position:0 -26px; }
.leaflet-touch .fullscreen-icon { background-position: 2px 2px; }
.leaflet-touch .fullscreen-icon.leaflet-fullscreen-on { background-position: 2px -24px; }
/* one selector per rule as explained here : http://www.sitepoint.com/html5-full-screen-api/ */
.leaflet-container:-webkit-full-screen { width: 100% !important; height: 100% !important; z-index: 99999; }
.leaflet-container:-ms-fullscreen { width: 100% !important; height: 100% !important; z-index: 99999; }
.leaflet-container:full-screen { width: 100% !important; height: 100% !important; z-index: 99999; }
.leaflet-container:fullscreen { width: 100% !important; height: 100% !important; z-index: 99999; }
.leaflet-pseudo-fullscreen { position: fixed !important; width: 100% !important; height: 100% !important; top: 0px !important; left: 0px !important; z-index: 99999; }
.fullscreen-icon {
background-image: url('icon-fullscreen.svg');
background-size: 26px 52px;
}

.fullscreen-icon.leaflet-fullscreen-on {
background-position: 0 -26px;
}

.leaflet-touch .fullscreen-icon {
background-position: 2px 2px;
}

.leaflet-touch .fullscreen-icon.leaflet-fullscreen-on {
background-position: 2px -24px;
}

/* Safari still needs this vendor-prefix: https://caniuse.com/mdn-css_selectors_fullscreen */
/* stylelint-disable-next-line selector-no-vendor-prefix */
.leaflet-container:-webkit-full-screen {
width: 100% !important;
height: 100% !important;
z-index: 99999;
}

.leaflet-container:fullscreen {
width: 100% !important;
height: 100% !important;
z-index: 99999;
}

.leaflet-pseudo-fullscreen {
position: fixed !important;
width: 100% !important;
height: 100% !important;
top: 0 !important;
left: 0 !important;
z-index: 99999;
}
93 changes: 53 additions & 40 deletions Control.FullScreen.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
/*!_map
* leaflet.fullscreen
* (c) Bruno B.; MIT License
* Uses fragments from the package 'screenfull'
*/
/*
* leaflet.fullscreen
* (c) Bruno B.; MIT License
* Uses fragments from the package 'screenfull'
*/
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
if (typeof define === 'function' && define.amd) {
// define an AMD module that requires 'leaflet'
// and resolve to an object containing leaflet
define('leafletFullScreen', ['leaflet'], factory);
} else if (typeof module === 'object' && module.exports) {
} else if (typeof module === 'object' && module.exports) {
// define a CommonJS module that requires 'leaflet'
module.exports = factory(require('leaflet'));
} else {
} else {
// Assume 'leaflet' are loaded into global variable already
factory(root.L);
}
}(typeof self !== 'undefined' ? self : this, function (leaflet) {
}(typeof self !== 'undefined'
? self
: this, (leaflet) => {
'use strict';

if (typeof document === 'undefined') {
Expand Down Expand Up @@ -66,8 +68,8 @@
};

const fullscreenAPI = {
request: function (element, options) {
return new Promise(function (resolve, reject) {
request(element, options) {
return new Promise((resolve, reject) => {
const onFullScreenEntered = function () {
this.off('change', onFullScreenEntered);
resolve();
Expand All @@ -79,10 +81,10 @@
if (returnPromise instanceof Promise) {
returnPromise.then(onFullScreenEntered).catch(reject);
}
}.bind(this));
});
},
exit: function () {
return new Promise(function (resolve, reject) {
exit() {
return new Promise((resolve, reject) => {
if (!this.isFullscreen) {
resolve();
return;
Expand All @@ -98,32 +100,32 @@
if (returnPromise instanceof Promise) {
returnPromise.then(onFullScreenExit).catch(reject);
}
}.bind(this));
});
},
on: function (event, callback) {
var eventName = eventNameMap[event];
on(event, callback) {
const eventName = eventNameMap[event];
if (eventName) {
document.addEventListener(eventName, callback, false);
}
},
off: function (event, callback) {
var eventName = eventNameMap[event];
off(event, callback) {
const eventName = eventNameMap[event];
if (eventName) {
document.removeEventListener(eventName, callback, false);
}
},
nativeAPI: nativeAPI
};
};

Object.defineProperties(fullscreenAPI, {
isFullscreen: {
get: function () {
get() {
return Boolean(document[nativeAPI.fullscreenElement]);
}
},
isEnabled: {
enumerable: true,
get: function () {
get() {
// Coerce to boolean in case of old WebKit
return Boolean(document[nativeAPI.fullscreenEnabled]);
}
Expand All @@ -142,8 +144,10 @@

_screenfull: fullscreenAPI,

onAdd: function (map) {
var className = 'leaflet-control-zoom-fullscreen', container, content = '';
onAdd(map) {
let className = 'leaflet-control-zoom-fullscreen';
let container;
let content = '';

if (map.zoomControl && !this.options.forceSeparateButton) {
container = map.zoomControl._container;
Expand All @@ -165,7 +169,7 @@
return container;
},

onRemove: function () {
onRemove() {
leaflet.DomEvent
.off(this.link, 'click', leaflet.DomEvent.stop)
.off(this.link, 'click', this.toggleFullScreen, this);
Expand All @@ -181,7 +185,7 @@
}
},

_createButton: function (title, className, content, container, fn, context) {
_createButton(title, className, content, container, fn, context) {
this.link = leaflet.DomUtil.create('a', className, container);
this.link.href = '#';
this.link.title = title;
Expand Down Expand Up @@ -209,39 +213,48 @@
return this.link;
},

toggleFullScreen: function () {
var map = this._map;
toggleFullScreen() {
const map = this._map;
map._exitFired = false;
if (map._isFullscreen) {
if (this._screenfull.isEnabled && !this.options.forcePseudoFullscreen) {
this._screenfull.exit();
} else {
leaflet.DomUtil.removeClass(this.options.fullscreenElement ? this.options.fullscreenElement : map._container, 'leaflet-pseudo-fullscreen');
leaflet.DomUtil.removeClass(this.options.fullscreenElement
? this.options.fullscreenElement
: map._container, 'leaflet-pseudo-fullscreen');
map.invalidateSize();
}
map.fire('exitFullscreen');
map._exitFired = true;
map._isFullscreen = false;
}
else {
} else {
if (this._screenfull.isEnabled && !this.options.forcePseudoFullscreen) {
this._screenfull.request(this.options.fullscreenElement ? this.options.fullscreenElement : map._container);
this._screenfull.request(this.options.fullscreenElement
? this.options.fullscreenElement
: map._container);
} else {
leaflet.DomUtil.addClass(this.options.fullscreenElement ? this.options.fullscreenElement : map._container, 'leaflet-pseudo-fullscreen');
leaflet.DomUtil.addClass(this.options.fullscreenElement
? this.options.fullscreenElement
: map._container, 'leaflet-pseudo-fullscreen');
map.invalidateSize();
}
map.fire('enterFullscreen');
map._isFullscreen = true;
}
},

_toggleState: function () {
this.link.title = this._map._isFullscreen ? this.options.title : this.options.titleCancel;
this._map._isFullscreen ? L.DomUtil.removeClass(this.link, 'leaflet-fullscreen-on') : L.DomUtil.addClass(this.link, 'leaflet-fullscreen-on');
_toggleState() {
this.link.title = this._map._isFullscreen
? this.options.title
: this.options.titleCancel;
this._map._isFullscreen
? L.DomUtil.removeClass(this.link, 'leaflet-fullscreen-on')
: L.DomUtil.addClass(this.link, 'leaflet-fullscreen-on');
},

_handleFullscreenChange: function (ev) {
var map = this._map;
_handleFullscreenChange(ev) {
const map = this._map;
if (ev.target === map.getContainer() && !this._screenfull.isFullscreen && !map._exitFired) {
map.invalidateSize();
map.fire('exitFullscreen');
Expand All @@ -252,7 +265,7 @@
});

leaflet.Map.include({
toggleFullscreen: function () {
toggleFullscreen() {
this.fullscreenControl.toggleFullScreen();
}
});
Expand All @@ -267,5 +280,5 @@
return new leaflet.Control.FullScreen(options);
};

return {leaflet: leaflet};
return { leaflet };
}));
2 changes: 2 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
MIT License

Copyright (c) 2013, Bruno Bergot

Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down
Loading

0 comments on commit 51425fd

Please sign in to comment.