-
Notifications
You must be signed in to change notification settings - Fork 206
/
Copy pathmaps.js
97 lines (81 loc) · 3.44 KB
/
maps.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//= require jquery-ui/jquery-ui.min.js
//= require knitter
//= require exif-js/exif.js
//= require mapknitter
//= require ion-rangeslider/js/ion.rangeSlider.js
/* Move navbar links into dropdown if nav is inside the sidebar. */
// = require jquery/dist/jquery.js
jQuery(document).ready(function($) {
window.toggle_sidebar = function() {
var icon = $('.sidebar-toggle-icon');
$('#knitter-map-pane').toggleClass('fullscreen');
$('.sidebar .sidebar-wrap').toggleClass('fullscreen-only');
icon.toggleClass('fa-chevron-left');
icon.toggleClass('fa-chevron-right');
/* trigger a resize event */
window.mapknitter._map._onResize();
}
window.toggle_sidebar_and_fit_bounds = function() {
window.mapknitter._map.once('resize', function(e) {
if (e.bounds) { window.mapknitter._map.fitBounds(e.bounds); }
})
window.toggle_sidebar();
}
$('.sidebar-toggle').click(window.toggle_sidebar_and_fit_bounds);
haschat = false
$('.chat-btn').click(function(){
if (!haschat) {
$('#chat').append('<iframe width="100%" height="300px" style="border:none;" src="https://webchat.oftc.net/?channels=publiclab&nick='+login+'"></iframe>')
}
haschat = true
})
var edit_comment = function(event) {
var id = $(event.target).data("comment-id");
/* Hide comment body. */
$(".comment-body[data-comment-id=" + id + "]").toggle();
/* Show comment editing form. */
$(".comment-edit-form[data-comment-id=" + id + "]").toggle();
}
var delete_comment = function(event) {
var id = $(event.target).data("comment-id");
$(".comment[data-comment-id=" + id + "]").remove();
$("#comments-number").text(function(i, str) { return str - 1; });
}
/* Enable dynamic comment editing. */
$(".edit-comment-btn").click(edit_comment);
/* Remove comment from the page when it is deleted from the database via AJAX. */
$(".delete-comment-btn").click(delete_comment);
/* on comment submission */
$("#new_comment").on("ajax:success", function(e, data, status, xhr) {
$("#new_comment button.btn-primary").html("Post comment").removeClass('disabled')
$("#new_comment textarea").attr('disabled',false)
$("#new_comment textarea").val('')
$("#comments").append(xhr.responseText)
$("#comments-number").text(function(i, str) { return (parseInt(str) + 1); });
$('.comment:last').click(edit_comment).click(delete_comment)
}).on("ajax:error", function(e, xhr, status, error) {
if (xhr.responseText == "Login required.") {
window.location = "/login?back_to="+window.location
} else {
$("#new_comment button.btn-primary").html("Post comment").removeClass('disabled')
$("#new_comment textarea").attr('disabled',false)
$("#comments").append("<p class='alert alert-error'>There was an error.</p>")
}
})
/* just before comment submission */
$("#new_comment").on("ajax:beforeSend",function() {
$("#new_comment button.btn-primary").html("<i class='fa fa-spinner fa-spin'></i>").addClass('disabled')
$("#new_comment textarea").attr('disabled',true)
})
// display upload modal on drag-dropped image:
$('#knitter-map-pane').on('dragenter',function(){
$('#knitter-map-pane').addClass('dragover')
})
$('#knitter-map-pane').on('dragleave',function(){
$('#knitter-map-pane').removeClass('dragover')
})
$('#knitter-map-pane').on('drop',function(){
$('#uploadModal').modal('show')
$('#knitter-map-pane').removeClass('dragover')
})
});