|
|
|
@ -6,7 +6,21 @@
|
|
|
|
|
<script type="text/javascript" src="/static/ender.js"></script>
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
|
|
|
|
|
|
var form = '<div id="comment_form">' +
|
|
|
|
|
var createForm = function(id, func) {
|
|
|
|
|
/*
|
|
|
|
|
Returns HTML for form and registers submit call.
|
|
|
|
|
|
|
|
|
|
Synopsis: `isso_N` is the comment with the id N. `issoform` is a new
|
|
|
|
|
form to write an answer to the article or answer to a comment using
|
|
|
|
|
`issoform_N` where N is the id to respond to.
|
|
|
|
|
|
|
|
|
|
:param id: comment id
|
|
|
|
|
:param func: function, that takes one argument (the HTML to display the form)
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
var formid = 'issoform' + (id ? ('_' + id) : '');
|
|
|
|
|
var form =
|
|
|
|
|
'<div class="issoform" id="' + formid + '">' +
|
|
|
|
|
'<div>' +
|
|
|
|
|
' <input type="text" name="name" id="author" value="" placeholder="Name">' +
|
|
|
|
|
'</div>' +
|
|
|
|
@ -22,133 +36,142 @@
|
|
|
|
|
'<div>' +
|
|
|
|
|
'<input type="submit" name="submit" value="Add Comment">' +
|
|
|
|
|
'</div>' +
|
|
|
|
|
'</div>';
|
|
|
|
|
'</div>'
|
|
|
|
|
|
|
|
|
|
var initialize = function(thread) {
|
|
|
|
|
func(form);
|
|
|
|
|
|
|
|
|
|
var comments = '<ul id="comments"></ul>';
|
|
|
|
|
// register submit event
|
|
|
|
|
$('#' + formid + ' ' + 'input[type="submit"]').on('click', function() {
|
|
|
|
|
|
|
|
|
|
// load our css
|
|
|
|
|
$('head').append('<link rel="stylesheet" href="/static/style.css" />');
|
|
|
|
|
var text = $('textarea[id="comment"]').val() || null;
|
|
|
|
|
|
|
|
|
|
// append our HTML
|
|
|
|
|
thread.append(comments)
|
|
|
|
|
thread.append(form);
|
|
|
|
|
|
|
|
|
|
// register events
|
|
|
|
|
$('input[type="submit"]').on('click', function() {
|
|
|
|
|
if (text == null) {
|
|
|
|
|
// alert("You must write a comment!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var text = $('textarea[id="comment"]').val() || null;
|
|
|
|
|
$.ajax({
|
|
|
|
|
url: '/comment/' + encodeURIComponent(window.location.pathname) + '/new',
|
|
|
|
|
method: 'POST',
|
|
|
|
|
type: 'json',
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
},
|
|
|
|
|
data: JSON.stringify({
|
|
|
|
|
text: text,
|
|
|
|
|
author: $('input[id="author"]').val() || null,
|
|
|
|
|
email: $('input[id="email"]').val() || null,
|
|
|
|
|
website: $('input[id="website"]').val() || null
|
|
|
|
|
}),
|
|
|
|
|
error: function(resp) {
|
|
|
|
|
alert("Mööp.");
|
|
|
|
|
},
|
|
|
|
|
success: function(rv) {
|
|
|
|
|
insert($('#isso_thread'), rv)
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (text == null) {
|
|
|
|
|
// alert("You must write a comment!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var initialize = function(thread) {
|
|
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
|
url: '/comment/' + encodeURIComponent(window.location.pathname) + '/new',
|
|
|
|
|
method: 'POST',
|
|
|
|
|
type: 'json',
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
},
|
|
|
|
|
data: JSON.stringify({
|
|
|
|
|
text: text,
|
|
|
|
|
author: $('input[id="author"]').val() || null,
|
|
|
|
|
email: $('input[id="email"]').val() || null,
|
|
|
|
|
website: $('input[id="website"]').val() || null
|
|
|
|
|
}),
|
|
|
|
|
error: function(resp) {
|
|
|
|
|
alert("Mööp.");
|
|
|
|
|
},
|
|
|
|
|
success: function(rv) {
|
|
|
|
|
//$('#isso_thread').html(resp.content);
|
|
|
|
|
insert(thread, rv)
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
// that with an unordered list
|
|
|
|
|
thread.append('<ul id="comments"></ul>');
|
|
|
|
|
|
|
|
|
|
var insert = function(thread, post) {
|
|
|
|
|
// load our css
|
|
|
|
|
$('head').append('<link rel="stylesheet" href="/static/style.css" />');
|
|
|
|
|
|
|
|
|
|
// pythonic strftime
|
|
|
|
|
var format = function(date, lang, fmt) {
|
|
|
|
|
// append form
|
|
|
|
|
createForm(null, function(html) {thread.append(html)});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var months = {'de': [
|
|
|
|
|
'Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli',
|
|
|
|
|
'August', 'September', 'Oktober', 'November', 'Dezember'],
|
|
|
|
|
'en': [
|
|
|
|
|
'January', 'February', 'March', 'April', 'May', 'June', 'July',
|
|
|
|
|
'August', 'September', 'October', 'November', 'December'],
|
|
|
|
|
};
|
|
|
|
|
var insert = function(thread, post) {
|
|
|
|
|
|
|
|
|
|
var conversions = [
|
|
|
|
|
['%Y', date.getFullYear()], ['%m', date.getMonth()],
|
|
|
|
|
['%B', months[lang][date.getMonth() - 1]],
|
|
|
|
|
['%d', date.getDate()], ['%H', date.getHours()],
|
|
|
|
|
['%H', date.getHours()], ['%M', date.getMinutes()],
|
|
|
|
|
];
|
|
|
|
|
// pythonic strftime
|
|
|
|
|
var format = function(date, lang, fmt) {
|
|
|
|
|
|
|
|
|
|
conversions.map(function(item) { fmt = fmt.replace(item[0], item[1]) });
|
|
|
|
|
return fmt;
|
|
|
|
|
var months = {'de': [
|
|
|
|
|
'Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli',
|
|
|
|
|
'August', 'September', 'Oktober', 'November', 'Dezember'],
|
|
|
|
|
'en': [
|
|
|
|
|
'January', 'February', 'March', 'April', 'May', 'June', 'July',
|
|
|
|
|
'August', 'September', 'October', 'November', 'December'],
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var author = post['author'] || 'Anonymous';
|
|
|
|
|
if (post['website']) {
|
|
|
|
|
author = '<a href="' + post['website'] + '" rel="nofollow">' + author + '</a>';
|
|
|
|
|
}
|
|
|
|
|
var conversions = [
|
|
|
|
|
['%Y', date.getFullYear()], ['%m', date.getMonth()],
|
|
|
|
|
['%B', months[lang][date.getMonth() - 1]],
|
|
|
|
|
['%d', date.getDate()], ['%H', date.getHours()],
|
|
|
|
|
['%H', date.getHours()], ['%M', date.getMinutes()],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
conversions.map(function(item) { fmt = fmt.replace(item[0], item[1]) });
|
|
|
|
|
return fmt;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var date = new Date(parseInt(post['created']) * 1000);
|
|
|
|
|
var author = post['author'] || 'Anonymous';
|
|
|
|
|
if (post['website']) {
|
|
|
|
|
author = '<a href="' + post['website'] + '" rel="nofollow">' + author + '</a>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$('ul', thread).append(
|
|
|
|
|
'<article class="comment">' +
|
|
|
|
|
' <header><span class="author">' + author + '</span> schrieb am' +
|
|
|
|
|
' <span class="date">' + format(date, 'de', '%d. %B %Y um %H:%M') + ':' +
|
|
|
|
|
' </span>' +
|
|
|
|
|
' </header>' + post['text'] +
|
|
|
|
|
' <footer>' +
|
|
|
|
|
' <a href="#" id="comment_' + post['id'] + '">Antworten</a>' +
|
|
|
|
|
' </footer>' +
|
|
|
|
|
'</article>');
|
|
|
|
|
|
|
|
|
|
$('#comment_' + post['id']).on('click', function() {
|
|
|
|
|
var date = new Date(parseInt(post['created']) * 1000);
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
};
|
|
|
|
|
$('#isso_thread ul').append(
|
|
|
|
|
'<article class="isso">' +
|
|
|
|
|
' <header><span class="author">' + author + '</span> schrieb am' +
|
|
|
|
|
' <span class="date">' + format(date, 'de', '%d. %B %Y um %H:%M') + ':' +
|
|
|
|
|
' </span>' +
|
|
|
|
|
' </header>' + post['text'] +
|
|
|
|
|
' <footer>' +
|
|
|
|
|
' <a href="#" id="isso_' + post['id'] + '">Antworten</a>' +
|
|
|
|
|
' </footer>' +
|
|
|
|
|
'</article>');
|
|
|
|
|
|
|
|
|
|
var fetch = function(thread) {
|
|
|
|
|
var rv = $.ajax({
|
|
|
|
|
url: '/comment/' + encodeURIComponent(window.location.pathname) + '/',
|
|
|
|
|
method: 'GET',
|
|
|
|
|
type: 'json',
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
},
|
|
|
|
|
error: function(resp) {
|
|
|
|
|
return;
|
|
|
|
|
},
|
|
|
|
|
success: function(resp) {
|
|
|
|
|
for (var item in resp) {
|
|
|
|
|
insert(thread, resp[item]);
|
|
|
|
|
}
|
|
|
|
|
// ability to answer directly to a comment
|
|
|
|
|
$('#isso_' + post['id']).on('click', function(event) {
|
|
|
|
|
|
|
|
|
|
if ($('#issoform_' + post['id']).length == 0) {
|
|
|
|
|
createForm(post['id'], function(html) {$('#isso_' + post['id']).after(html)});
|
|
|
|
|
} else {
|
|
|
|
|
$('#issoform_' + post['id']).remove();
|
|
|
|
|
};
|
|
|
|
|
event.stop();
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var fetch = function(thread) {
|
|
|
|
|
var rv = $.ajax({
|
|
|
|
|
url: '/comment/' + encodeURIComponent(window.location.pathname) + '/',
|
|
|
|
|
method: 'GET',
|
|
|
|
|
type: 'json',
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
},
|
|
|
|
|
error: function(resp) {
|
|
|
|
|
return;
|
|
|
|
|
},
|
|
|
|
|
success: function(resp) {
|
|
|
|
|
for (var item in resp) {
|
|
|
|
|
insert(thread, resp[item]);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$.domReady(function() {
|
|
|
|
|
$.domReady(function() {
|
|
|
|
|
|
|
|
|
|
// initialize comment form and css
|
|
|
|
|
initialize($('#isso_thread'));
|
|
|
|
|
// initialize comment form and css
|
|
|
|
|
initialize($('#isso_thread'));
|
|
|
|
|
|
|
|
|
|
// fetch comments for path
|
|
|
|
|
fetch($('#isso_thread'));
|
|
|
|
|
// fetch comments for path
|
|
|
|
|
fetch($('#isso_thread'));
|
|
|
|
|
|
|
|
|
|
// REMOVE ME
|
|
|
|
|
$('input[id="author"]').val("Peter");
|
|
|
|
|
$('textarea[id="comment"]').val("Lorem ipsum ...");
|
|
|
|
|
// REMOVE ME
|
|
|
|
|
$('input[id="author"]').val("Peter");
|
|
|
|
|
$('textarea[id="comment"]').val("Lorem ipsum ...");
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
<style type="text/css">
|
|
|
|
|