Consistent JavaScript style
This commit is contained in:
parent
f1a4669c95
commit
eebe1f1d3e
5 changed files with 112 additions and 138 deletions
|
@ -75,12 +75,12 @@ $(document).ready(function () {
|
||||||
uiPane: uiPane
|
uiPane: uiPane
|
||||||
}).addTo(map);
|
}).addTo(map);
|
||||||
|
|
||||||
L.control.note({
|
L.OSM.note({
|
||||||
position: 'topright',
|
position: 'topright',
|
||||||
uiPane: uiPane
|
uiPane: uiPane
|
||||||
}).addTo(map);
|
}).addTo(map);
|
||||||
|
|
||||||
L.control.share({
|
L.OSM.share({
|
||||||
getUrl: getShortUrl,
|
getUrl: getShortUrl,
|
||||||
uiPane: uiPane
|
uiPane: uiPane
|
||||||
}).addTo(map);
|
}).addTo(map);
|
||||||
|
|
|
@ -1,25 +1,19 @@
|
||||||
L.OSM.Key = L.Control.extend({
|
L.OSM.key = function(options) {
|
||||||
onAdd: function (map) {
|
var control = L.control(options);
|
||||||
this._map = map;
|
|
||||||
this._initLayout();
|
|
||||||
return this.$container[0];
|
|
||||||
},
|
|
||||||
|
|
||||||
_initLayout: function () {
|
control.onAdd = function (map) {
|
||||||
var map = this._map;
|
var $container = $('<div>')
|
||||||
|
|
||||||
this.$container = $('<div>')
|
|
||||||
.attr('class', 'control-key');
|
.attr('class', 'control-key');
|
||||||
|
|
||||||
var link = $('<a>')
|
$('<a>')
|
||||||
.attr('class', 'control-button')
|
.attr('class', 'control-button')
|
||||||
.attr('href', '#')
|
.attr('href', '#')
|
||||||
.attr('title', 'Map Key')
|
.attr('title', 'Map Key')
|
||||||
.html('<span class="icon key"></span>')
|
.html('<span class="icon key"></span>')
|
||||||
.appendTo(this.$container);
|
.appendTo($container);
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
L.OSM.key = function(options) {
|
return $container[0];
|
||||||
return new L.OSM.Key(options);
|
};
|
||||||
|
|
||||||
|
return control;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,15 +1,10 @@
|
||||||
L.OSM.Layers = L.Control.extend({
|
L.OSM.layers = function(options) {
|
||||||
onAdd: function (map) {
|
var control = L.control(options);
|
||||||
this._map = map;
|
|
||||||
this._initLayout();
|
|
||||||
return this.$container[0];
|
|
||||||
},
|
|
||||||
|
|
||||||
_initLayout: function () {
|
control.onAdd = function (map) {
|
||||||
var map = this._map,
|
var layers = options.layers;
|
||||||
layers = this.options.layers;
|
|
||||||
|
|
||||||
this.$container = $('<div>')
|
var $container = $('<div>')
|
||||||
.attr('class', 'control-layers');
|
.attr('class', 'control-layers');
|
||||||
|
|
||||||
var link = $('<a>')
|
var link = $('<a>')
|
||||||
|
@ -17,20 +12,21 @@ L.OSM.Layers = L.Control.extend({
|
||||||
.attr('href', '#')
|
.attr('href', '#')
|
||||||
.attr('title', 'Layers')
|
.attr('title', 'Layers')
|
||||||
.html('<span class="icon layers"></span>')
|
.html('<span class="icon layers"></span>')
|
||||||
.appendTo(this.$container);
|
.on('click', toggle)
|
||||||
|
.appendTo($container);
|
||||||
|
|
||||||
if (OSM.STATUS != 'api_offline' && OSM.STATUS != 'database_offline') {
|
var $ui = $('<div>')
|
||||||
this.$ui = $('<div>')
|
|
||||||
.attr('class', 'layers-ui')
|
.attr('class', 'layers-ui')
|
||||||
.appendTo(this.options.uiPane);
|
.appendTo(options.uiPane);
|
||||||
|
|
||||||
$('<h2>')
|
$('<h2>')
|
||||||
.text(I18n.t('javascripts.map.layers.header'))
|
.text(I18n.t('javascripts.map.layers.header'))
|
||||||
.appendTo(this.$ui);
|
.appendTo($ui);
|
||||||
|
|
||||||
|
if (OSM.STATUS != 'api_offline' && OSM.STATUS != 'database_offline') {
|
||||||
var overlaySection = $('<section>')
|
var overlaySection = $('<section>')
|
||||||
.addClass('overlay-layers')
|
.addClass('overlay-layers')
|
||||||
.appendTo(this.$ui);
|
.appendTo($ui);
|
||||||
|
|
||||||
$('<p>')
|
$('<p>')
|
||||||
.text(I18n.t('javascripts.map.layers.overlays'))
|
.text(I18n.t('javascripts.map.layers.overlays'))
|
||||||
|
@ -72,7 +68,7 @@ L.OSM.Layers = L.Control.extend({
|
||||||
|
|
||||||
var baseSection = $('<section>')
|
var baseSection = $('<section>')
|
||||||
.addClass('base-layers')
|
.addClass('base-layers')
|
||||||
.appendTo(this.$ui);
|
.appendTo($ui);
|
||||||
|
|
||||||
$('<p>')
|
$('<p>')
|
||||||
.text(I18n.t('javascripts.map.layers.base'))
|
.text(I18n.t('javascripts.map.layers.base'))
|
||||||
|
@ -128,29 +124,27 @@ L.OSM.Layers = L.Control.extend({
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
$(link).on('click', $.proxy(this.toggleLayers, this));
|
function toggle(e) {
|
||||||
},
|
|
||||||
|
|
||||||
toggleLayers: function (e) {
|
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
var controlContainer = $('.leaflet-control-container .leaflet-top.leaflet-right');
|
var controlContainer = $('.leaflet-control-container .leaflet-top.leaflet-right');
|
||||||
|
|
||||||
if (this.$ui.is(':visible')) {
|
if ($ui.is(':visible')) {
|
||||||
$(this.options.uiPane).hide();
|
$(control.options.uiPane).hide();
|
||||||
controlContainer.css({paddingRight: '0'});
|
controlContainer.css({paddingRight: '0'});
|
||||||
} else {
|
} else {
|
||||||
$(this.options.uiPane).show();
|
$(control.options.uiPane).show();
|
||||||
controlContainer.css({paddingRight: '230px'});
|
controlContainer.css({paddingRight: '230px'});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.$ui.find('.base-layers .leaflet-container').each(function() {
|
$ui.find('.base-layers .leaflet-container').each(function() {
|
||||||
$(this).data('map').invalidateSize();
|
$(this).data('map').invalidateSize();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
L.OSM.layers = function(options) {
|
return $container[0];
|
||||||
return new L.OSM.Layers(options);
|
};
|
||||||
|
|
||||||
|
return control;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,39 +1,31 @@
|
||||||
L.Control.Note = L.Control.extend({
|
L.OSM.note = function (options) {
|
||||||
options: {
|
var control = L.control(options);
|
||||||
position: 'topright',
|
|
||||||
title: 'Notes',
|
|
||||||
},
|
|
||||||
|
|
||||||
onAdd: function (map) {
|
control.onAdd = function (map) {
|
||||||
var className = 'control-note',
|
var $container = $('<div>')
|
||||||
container = L.DomUtil.create('div', className);
|
.attr('class', 'control-note');
|
||||||
|
|
||||||
var link = L.DomUtil.create('a', 'control-button', container);
|
$('<a>')
|
||||||
link.innerHTML = "<span class='icon note'></span>";
|
.attr('class', 'control-button')
|
||||||
link.href = '#';
|
.attr('href', '#')
|
||||||
link.title = this.options.title;
|
.attr('title', 'Notes')
|
||||||
|
.html('<span class="icon note"></span>')
|
||||||
|
.on('click', toggle)
|
||||||
|
.appendTo($container);
|
||||||
|
|
||||||
L.DomEvent
|
function toggle(e) {
|
||||||
.on(link, 'click', L.DomEvent.stopPropagation)
|
e.stopPropagation();
|
||||||
.on(link, 'click', L.DomEvent.preventDefault)
|
e.preventDefault();
|
||||||
.on(link, 'click', this._toggle, this)
|
|
||||||
.on(link, 'dblclick', L.DomEvent.stopPropagation);
|
|
||||||
|
|
||||||
this.map = map;
|
if (map.hasLayer(map.noteLayer)) {
|
||||||
|
map.removeLayer(map.noteLayer);
|
||||||
return container;
|
|
||||||
},
|
|
||||||
|
|
||||||
// TODO: this relies on notesLayer on the map
|
|
||||||
_toggle: function() {
|
|
||||||
if (this.map.hasLayer(this.map.noteLayer)) {
|
|
||||||
this.map.removeLayer(this.map.noteLayer);
|
|
||||||
} else {
|
} else {
|
||||||
this.map.addLayer(this.map.noteLayer);
|
map.addLayer(map.noteLayer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
L.control.note = function(options) {
|
return $container[0];
|
||||||
return new L.Control.Note(options);
|
};
|
||||||
|
|
||||||
|
return control;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,60 +1,54 @@
|
||||||
L.Control.Share = L.Control.extend({
|
L.OSM.share = function (options) {
|
||||||
options: {
|
var control = L.control(options);
|
||||||
position: 'topright',
|
|
||||||
title: 'Share',
|
|
||||||
url: function(map) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
onAdd: function (map) {
|
control.onAdd = function (map) {
|
||||||
var className = 'control-share',
|
var $container = $('<div>')
|
||||||
container = L.DomUtil.create('div', className);
|
.attr('class', 'control-share');
|
||||||
|
|
||||||
var link = L.DomUtil.create('a', 'control-button', container);
|
$('<a>')
|
||||||
link.innerHTML = "<span class='icon share'></span>";
|
.attr('class', 'control-button')
|
||||||
link.href = '#';
|
.attr('href', '#')
|
||||||
link.title = this.options.title;
|
.attr('title', 'Share')
|
||||||
|
.html('<span class="icon share"></span>')
|
||||||
|
.on('click', toggle)
|
||||||
|
.appendTo($container);
|
||||||
|
|
||||||
this._uiPane = this.options.uiPane;
|
var $ui = $('<div>')
|
||||||
|
.attr('class', 'share-ui')
|
||||||
|
.appendTo(options.uiPane);
|
||||||
|
|
||||||
this._map = map;
|
$('<h2>')
|
||||||
|
.text(I18n.t('javascripts.share.title'))
|
||||||
|
.appendTo($ui);
|
||||||
|
|
||||||
var h2 = L.DomUtil.create('h2', '', this._uiPane);
|
var $input = $('<input>')
|
||||||
h2.innerHTML = I18n.t('javascripts.share.title');
|
.appendTo($ui);
|
||||||
|
|
||||||
this._linkInput = L.DomUtil.create('input', '', this._uiPane);
|
map.on('moveend layeradd layerremove', update);
|
||||||
|
|
||||||
L.DomEvent
|
function toggle(e) {
|
||||||
.on(link, 'click', L.DomEvent.stopPropagation)
|
e.stopPropagation();
|
||||||
.on(link, 'click', L.DomEvent.preventDefault)
|
e.preventDefault();
|
||||||
.on(link, 'click', this._toggle, this)
|
|
||||||
.on(link, 'dblclick', L.DomEvent.stopPropagation);
|
|
||||||
|
|
||||||
map.on('moveend layeradd layerremove', this._update, this);
|
|
||||||
|
|
||||||
return container;
|
|
||||||
},
|
|
||||||
|
|
||||||
_update: function (e) {
|
|
||||||
var center = this._map.getCenter().wrap();
|
|
||||||
var layers = getMapLayers(this._map);
|
|
||||||
this._linkInput.value = this.options.getUrl(this._map);
|
|
||||||
},
|
|
||||||
|
|
||||||
_toggle: function() {
|
|
||||||
var controlContainer = $('.leaflet-control-container .leaflet-top.leaflet-right');
|
var controlContainer = $('.leaflet-control-container .leaflet-top.leaflet-right');
|
||||||
|
|
||||||
if ($(this._uiPane).is(':visible')) {
|
if ($ui.is(':visible')) {
|
||||||
$(this._uiPane).hide();
|
$(control.options.uiPane).hide();
|
||||||
controlContainer.css({paddingRight: '0'});
|
controlContainer.css({paddingRight: '0'});
|
||||||
} else {
|
} else {
|
||||||
$(this._uiPane).show();
|
$(control.options.uiPane).show();
|
||||||
controlContainer.css({paddingRight: '200px'});
|
controlContainer.css({paddingRight: '200px'});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
L.control.share = function(options) {
|
function update() {
|
||||||
return new L.Control.Share(options);
|
var center = map.getCenter().wrap();
|
||||||
|
var layers = getMapLayers(map);
|
||||||
|
$input.val(options.getUrl(map));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $container[0];
|
||||||
|
};
|
||||||
|
|
||||||
|
return control;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue