Fix add note

This commit is contained in:
John Firebaugh 2013-06-13 14:56:42 -07:00
parent 761a441e1f
commit 9d5b81094c
5 changed files with 21 additions and 33 deletions

View file

@ -75,11 +75,6 @@ $(document).ready(function () {
sidebar: sidebar
}).addTo(map);
L.OSM.note({
position: 'topright',
sidebar: sidebar
}).addTo(map);
L.OSM.share({
getShortUrl: getShortUrl,
getUrl: getUrl,
@ -87,6 +82,11 @@ $(document).ready(function () {
short: true
}).addTo(map);
L.OSM.note({
position: 'topright',
sidebar: sidebar
}).addTo(map);
L.control.scale()
.addTo(map);

View file

@ -160,6 +160,8 @@ function initializeNotes(map) {
return content[0];
}
var addNoteButton = $(".control-note .control-button");
function createNote(marker, form, url) {
var location = marker.getLatLng();
@ -186,7 +188,7 @@ function initializeNotes(map) {
notes[feature.properties.id] = updateMarker(marker, feature);
newNote = null;
$("#createnoteanchor").removeClass("disabled").addClass("geolink");
addNoteButton.removeClass("disabled");
}
}
@ -215,12 +217,13 @@ function initializeNotes(map) {
});
}
$(".leaflet-control-attribution").on("click", "#createnoteanchor", function (e) {
addNoteButton.on("click", function (e) {
e.preventDefault();
e.stopPropagation();
if ($(e.target).hasClass("disabled")) return;
if (addNoteButton.hasClass("disabled")) return;
$(e.target).removeClass("geolink").addClass("disabled");
addNoteButton.addClass("disabled");
map.addLayer(noteLayer);
@ -241,25 +244,23 @@ function initializeNotes(map) {
draggable: true
});
var popupContent = $(JST["templates/notes/new"]({
create_url: $(e.target).attr("href")
}));
var popupContent = $(JST["templates/notes/new"]());
popupContent.find("textarea").on("input", disableWhenBlank);
function disableWhenBlank(e) {
$(e.target.form).prop("disabled", $(e.target).val() === "");
$(e.target.form.add).prop("disabled", $(e.target).val() === "");
}
popupContent.find("input[type=submit]").on("click", function (e) {
e.preventDefault();
createNote(newNote, e.target.form, $(e.target).data("url"));
createNote(newNote, e.target.form, '/api/0.6/notes.json');
});
newNote.addTo(noteLayer).bindPopup(popupContent[0], popupOptions()).openPopup();
newNote.on("remove", function (e) {
$("#createnoteanchor").removeClass("disabled").addClass("geolink");
addNoteButton.removeClass("disabled");
}).on("dragstart", function (e) {
$(newNote).stopTime("removenote");
}).on("dragend", function (e) {

View file

@ -8,22 +8,10 @@ L.OSM.note = function (options) {
$('<a>')
.attr('class', 'control-button')
.attr('href', '#')
.attr('title', 'Notes')
.attr('title', I18n.t('javascripts.notes.new.add'))
.html('<span class="icon note"></span>')
.on('click', toggle)
.appendTo($container);
function toggle(e) {
e.stopPropagation();
e.preventDefault();
if (map.hasLayer(map.noteLayer)) {
map.removeLayer(map.noteLayer);
} else {
map.addLayer(map.noteLayer);
}
}
return $container[0];
};

View file

@ -6,7 +6,7 @@
<textarea class="comment" name="text" cols="40" rows="10"></textarea>
<br/>
<div class="buttons clearfix">
<input type="submit" name="add" value="<%- I18n.t('javascripts.notes.new.add') %>" data-url="<%- create_url %>" disabled="1">
<input type="submit" name="add" value="<%- I18n.t('javascripts.notes.new.add') %>" disabled="1">
</div>
</form>
</div>

View file

@ -556,19 +556,18 @@ a.donate {
}
.leaflet-control .zoomin,
.control-layers .control-button,
.control-note .control-button {
.control-layers .control-button {
margin-bottom: 0px;
border-radius: 4px 4px 0px 0px;
}
.leaflet-control .zoomout {
.leaflet-control .zoomout,
.control-key .control-button {
margin-bottom: 0px;
border-radius: 0px;
}
.control-locate .control-button,
.control-key .control-button,
.control-share .control-button {
border-radius: 0px 0px 4px 4px;
}