L.OSM.share = function (options) {
- var control = L.OSM.sidebarPane(options),
+ var control = L.OSM.sidebarPane(options, "share", "javascripts.share.title", "javascripts.share.title"),
marker = L.marker([0, 0], { draggable: true }),
locationFilter = new L.LocationFilter({
enableButton: false,
adjustButton: false
});
- control.onAdd = function (map) {
- var $container = $("<div>")
- .attr("class", "control-share");
-
- var button = this.makeButton("share", "javascripts.share.title", toggle)
- .appendTo($container);
-
- var $ui = this.makeUI("share-ui", "javascripts.share.title", toggle);
-
+ control.onAddPane = function (map, button, $ui) {
// Link / Embed
var $linkSection = $("<div>")
.bind("change", toggleMarker))
.append(I18n.t("javascripts.share.include_marker")));
- $("<div>")
- .attr("class", "share-tabs")
+ $("<div class='btn-group btn-group-sm mb-2'>")
.appendTo($form)
- .append($("<a>")
- .attr("class", "active")
+ .append($("<a class='btn btn-primary'>")
+ .addClass("active")
.attr("for", "long_input")
.attr("id", "long_link")
.text(I18n.t("javascripts.share.long_link")))
- .append($("<a>")
+ .append($("<a class='btn btn-primary'>")
.attr("for", "short_input")
.attr("id", "short_link")
.text(I18n.t("javascripts.share.short_link")))
- .append($("<a>")
+ .append($("<a class='btn btn-primary'>")
.attr("for", "embed_html")
.attr("href", "#")
.text(I18n.t("javascripts.share.embed")))
.on("click", "a", function (e) {
e.preventDefault();
var id = "#" + $(this).attr("for");
- $linkSection.find(".share-tabs a")
+ $(this).siblings("a")
.removeClass("active");
$(this).addClass("active");
$linkSection.find(".share-tab")
$("<div>")
.attr("class", "share-tab")
- .css("display", "block")
.appendTo($form)
.append($("<input>")
.attr("id", "long_input")
$("<div>")
.attr("class", "share-tab")
+ .hide()
.appendTo($form)
.append($("<input>")
.attr("id", "short_input")
$("<div>")
.attr("class", "share-tab")
+ .hide()
.appendTo($form)
.append(
$("<textarea>")
.append(
$("<p>")
.attr("class", "text-muted")
- .text(I18n.t("javascripts.share.paste_html"))
- .appendTo($linkSection));
+ .text(I18n.t("javascripts.share.paste_html")));
// Geo URI
map.on("move", movedMap);
map.on("moveend layeradd layerremove", update);
- options.sidebar.addPane($ui);
-
$ui
+ .on("show", shown)
.on("hide", hidden);
+ function shown() {
+ $("#mapnik_scale").val(getScale());
+ update();
+ }
+
function hidden() {
map.removeLayer(marker);
map.options.scrollWheelZoom = map.options.doubleClickZoom = true;
update();
}
- function toggle(e) {
- e.stopPropagation();
- e.preventDefault();
-
- $("#mapnik_scale").val(getScale());
- marker.setLatLng(map.getCenter());
-
- update();
- options.sidebar.togglePane($ui, button);
- $(".leaflet-control .control-button").tooltip("hide");
- }
-
function toggleMarker() {
if ($(this).is(":checked")) {
marker.setLatLng(map.getCenter());
}
$("#embed_html").val(
- "<iframe width=\"425\" height=\"350\" frameborder=\"0\" scrolling=\"no\" marginheight=\"0\" marginwidth=\"0\" src=\"" +
+ "<iframe width=\"425\" height=\"350\" src=\"" +
escapeHTML(OSM.SERVER_PROTOCOL + "://" + OSM.SERVER_URL + "/export/embed.html?" + $.param(params)) +
"\" style=\"border: 1px solid black\"></iframe><br/>" +
"<small><a href=\"" + escapeHTML(map.getUrl(marker)) + "\">" +
var precision = 5 * Math.pow(10, Math.floor(Math.LOG10E * Math.log(scale)) - 2);
return precision * Math.ceil(scale / precision);
}
-
- return $container[0];
};
return control;