Applying PrettierJS against a small JS file

Mostly to demonstrate what it would look like with the current configuration.
This commit is contained in:
David Larlet 2023-05-09 14:26:34 -04:00
parent 40303e46c4
commit 1a24c8820f

View file

@ -1,189 +1,199 @@
L.U.Icon = L.DivIcon.extend({ L.U.Icon = L.DivIcon.extend({
initialize: function(map, options) { initialize: function (map, options) {
this.map = map; this.map = map
var default_options = { var default_options = {
iconSize: null, // Made in css iconSize: null, // Made in css
iconUrl: this.map.getDefaultOption('iconUrl'), iconUrl: this.map.getDefaultOption('iconUrl'),
feature: null feature: null,
}; }
options = L.Util.extend({}, default_options, options); options = L.Util.extend({}, default_options, options)
L.Icon.prototype.initialize.call(this, options); L.Icon.prototype.initialize.call(this, options)
this.feature = this.options.feature; this.feature = this.options.feature
if (this.feature && this.feature.isReadOnly()) { if (this.feature && this.feature.isReadOnly()) {
this.options.className += ' readonly'; this.options.className += ' readonly'
} }
}, },
_getIconUrl: function (name) { _getIconUrl: function (name) {
var url; var url
if(this.feature && this.feature._getIconUrl(name)) url = this.feature._getIconUrl(name); if (this.feature && this.feature._getIconUrl(name))
else url = this.options[name + 'Url']; url = this.feature._getIconUrl(name)
return this.formatUrl(url, this.feature); else url = this.options[name + 'Url']
return this.formatUrl(url, this.feature)
}, },
_getColor: function () { _getColor: function () {
var color; var color
if(this.feature) color = this.feature.getOption('color'); if (this.feature) color = this.feature.getOption('color')
else if (this.options.color) color = this.options.color; else if (this.options.color) color = this.options.color
else color = this.map.getDefaultOption('color'); else color = this.map.getDefaultOption('color')
return color; return color
}, },
formatUrl: function (url, feature) { formatUrl: function (url, feature) {
return L.Util.greedyTemplate(url || '', feature ? feature.extendedProperties() : {}); return L.Util.greedyTemplate(url || '', feature ? feature.extendedProperties() : {})
} },
})
});
L.U.Icon.Default = L.U.Icon.extend({ L.U.Icon.Default = L.U.Icon.extend({
default_options: { default_options: {
iconAnchor: new L.Point(16, 40), iconAnchor: new L.Point(16, 40),
popupAnchor: new L.Point(0, -40), popupAnchor: new L.Point(0, -40),
tooltipAnchor: new L.Point(16, -24), tooltipAnchor: new L.Point(16, -24),
className: 'umap-div-icon' className: 'umap-div-icon',
}, },
initialize: function(map, options) { initialize: function (map, options) {
options = L.Util.extend({}, this.default_options, options); options = L.Util.extend({}, this.default_options, options)
L.U.Icon.prototype.initialize.call(this, map, options); L.U.Icon.prototype.initialize.call(this, map, options)
}, },
_setColor: function() { _setColor: function () {
var color = this._getColor(); var color = this._getColor()
this.elements.container.style.backgroundColor = color; this.elements.container.style.backgroundColor = color
this.elements.arrow.style.borderTopColor = color; this.elements.arrow.style.borderTopColor = color
}, },
createIcon: function() { createIcon: function () {
this.elements = {}; this.elements = {}
this.elements.main = L.DomUtil.create('div'); this.elements.main = L.DomUtil.create('div')
this.elements.container = L.DomUtil.create('div', 'icon_container', this.elements.main); this.elements.container = L.DomUtil.create(
this.elements.arrow = L.DomUtil.create('div', 'icon_arrow', this.elements.main); 'div',
var src = this._getIconUrl('icon'); 'icon_container',
this.elements.main
)
this.elements.arrow = L.DomUtil.create('div', 'icon_arrow', this.elements.main)
var src = this._getIconUrl('icon')
if (src) { if (src) {
// An url. // An url.
if (src.indexOf('http') === 0 || src.indexOf('/') === 0 || src.indexOf('data:image') === 0) { if (
this.elements.img = L.DomUtil.create('img', null, this.elements.container); src.indexOf('http') === 0 ||
this.elements.img.src = src; src.indexOf('/') === 0 ||
src.indexOf('data:image') === 0
) {
this.elements.img = L.DomUtil.create('img', null, this.elements.container)
this.elements.img.src = src
} else { } else {
this.elements.span = L.DomUtil.create('span', null, this.elements.container) this.elements.span = L.DomUtil.create('span', null, this.elements.container)
this.elements.span.textContent = src; this.elements.span.textContent = src
} }
} }
this._setColor(); this._setColor()
this._setIconStyles(this.elements.main, 'icon'); this._setIconStyles(this.elements.main, 'icon')
return this.elements.main; return this.elements.main
} },
})
});
L.U.Icon.Circle = L.U.Icon.extend({ L.U.Icon.Circle = L.U.Icon.extend({
initialize: function(map, options) { initialize: function (map, options) {
var default_options = { var default_options = {
iconAnchor: new L.Point(6, 6), iconAnchor: new L.Point(6, 6),
popupAnchor: new L.Point(0, -6), popupAnchor: new L.Point(0, -6),
tooltipAnchor: new L.Point(6, 0), tooltipAnchor: new L.Point(6, 0),
className: 'umap-circle-icon' className: 'umap-circle-icon',
};
options = L.Util.extend({}, default_options, options);
L.U.Icon.prototype.initialize.call(this, map, options);
},
_setColor: function() {
this.elements.main.style.backgroundColor = this._getColor();
},
createIcon: function() {
this.elements = {};
this.elements.main = L.DomUtil.create('div');
this.elements.main.innerHTML = ' ';
this._setColor();
this._setIconStyles(this.elements.main, 'icon');
return this.elements.main;
} }
options = L.Util.extend({}, default_options, options)
L.U.Icon.prototype.initialize.call(this, map, options)
},
}); _setColor: function () {
this.elements.main.style.backgroundColor = this._getColor()
},
createIcon: function () {
this.elements = {}
this.elements.main = L.DomUtil.create('div')
this.elements.main.innerHTML = ' '
this._setColor()
this._setIconStyles(this.elements.main, 'icon')
return this.elements.main
},
})
L.U.Icon.Drop = L.U.Icon.Default.extend({ L.U.Icon.Drop = L.U.Icon.Default.extend({
default_options: { default_options: {
iconAnchor: new L.Point(16, 42), iconAnchor: new L.Point(16, 42),
popupAnchor: new L.Point(0, -42), popupAnchor: new L.Point(0, -42),
tooltipAnchor: new L.Point(16, -24), tooltipAnchor: new L.Point(16, -24),
className: 'umap-drop-icon' className: 'umap-drop-icon',
} },
}); })
L.U.Icon.Ball = L.U.Icon.Default.extend({ L.U.Icon.Ball = L.U.Icon.Default.extend({
default_options: { default_options: {
iconAnchor: new L.Point(8, 30), iconAnchor: new L.Point(8, 30),
popupAnchor: new L.Point(0, -28), popupAnchor: new L.Point(0, -28),
tooltipAnchor: new L.Point(8, -23), tooltipAnchor: new L.Point(8, -23),
className: 'umap-ball-icon' className: 'umap-ball-icon',
}, },
createIcon: function() { createIcon: function () {
this.elements = {}; this.elements = {}
this.elements.main = L.DomUtil.create('div'); this.elements.main = L.DomUtil.create('div')
this.elements.container = L.DomUtil.create('div', 'icon_container', this.elements.main); this.elements.container = L.DomUtil.create(
this.elements.arrow = L.DomUtil.create('div', 'icon_arrow', this.elements.main); 'div',
this._setColor(); 'icon_container',
this._setIconStyles(this.elements.main, 'icon'); this.elements.main
return this.elements.main; )
this.elements.arrow = L.DomUtil.create('div', 'icon_arrow', this.elements.main)
this._setColor()
this._setIconStyles(this.elements.main, 'icon')
return this.elements.main
}, },
_setColor: function() { _setColor: function () {
var color = this._getColor('color'), var color = this._getColor('color'),
background; background
if (L.Browser.ielt9) { if (L.Browser.ielt9) {
background = color; background = color
} } else if (L.Browser.webkit) {
else if (L.Browser.webkit) { background =
background = '-webkit-gradient( radial, 6 38%, 0, 6 38%, 8, from(white), to(' + color + ') )'; '-webkit-gradient( radial, 6 38%, 0, 6 38%, 8, from(white), to(' + color + ') )'
} } else {
else { background =
background = 'radial-gradient(circle at 6px 38% , white -4px, ' + color + ' 8px) repeat scroll 0 0 transparent'; 'radial-gradient(circle at 6px 38% , white -4px, ' +
} color +
this.elements.container.style.background = background; ' 8px) repeat scroll 0 0 transparent'
} }
this.elements.container.style.background = background
},
})
}); var _CACHE_COLOR = {}
var _CACHE_COLOR = {};
L.U.Icon.Cluster = L.DivIcon.extend({ L.U.Icon.Cluster = L.DivIcon.extend({
options: { options: {
iconSize: [40, 40] iconSize: [40, 40],
}, },
initialize: function (datalayer, cluster) { initialize: function (datalayer, cluster) {
this.datalayer = datalayer; this.datalayer = datalayer
this.cluster = cluster; this.cluster = cluster
}, },
createIcon: function () { createIcon: function () {
var container = L.DomUtil.create('div', 'leaflet-marker-icon marker-cluster'), var container = L.DomUtil.create('div', 'leaflet-marker-icon marker-cluster'),
div = L.DomUtil.create('div', '', container), div = L.DomUtil.create('div', '', container),
span = L.DomUtil.create('span', '', div), span = L.DomUtil.create('span', '', div),
backgroundColor = this.datalayer.getColor(); backgroundColor = this.datalayer.getColor()
span.textContent = this.cluster.getChildCount(); span.textContent = this.cluster.getChildCount()
div.style.backgroundColor = backgroundColor; div.style.backgroundColor = backgroundColor
return container; return container
}, },
computeTextColor: function (el) { computeTextColor: function (el) {
var color, var color,
backgroundColor = this.datalayer.getColor(); backgroundColor = this.datalayer.getColor()
if (this.datalayer.options.cluster && this.datalayer.options.cluster.textColor) { if (this.datalayer.options.cluster && this.datalayer.options.cluster.textColor) {
color = this.datalayer.options.cluster.textColor; color = this.datalayer.options.cluster.textColor
} }
if (!color) { if (!color) {
if (typeof _CACHE_COLOR[backgroundColor] === 'undefined') { if (typeof _CACHE_COLOR[backgroundColor] === 'undefined') {
color = L.DomUtil.TextColorFromBackgroundColor(el); color = L.DomUtil.TextColorFromBackgroundColor(el)
_CACHE_COLOR[backgroundColor] = color; _CACHE_COLOR[backgroundColor] = color
} else { } else {
color = _CACHE_COLOR[backgroundColor]; color = _CACHE_COLOR[backgroundColor]
} }
} }
return color; return color
} },
})
});