Browse Source

* add a lot of js for comments

master
Alex 'AdUser' Z 9 years ago
parent
commit
7f13a60655
  1. 30
      public/theme/js/main.js

30
public/theme/js/main.js

@ -1,12 +1,42 @@
$(document).ready(function() { $(document).ready(function() {
/* code highlight */
$('pre code').each(function(i, block) { $('pre code').each(function(i, block) {
hljs.highlightBlock(block); hljs.highlightBlock(block);
}); });
/* zerobin / radio 'source' autoswitch */
$('#paste').on('change', function() { $('#paste').on('change', function() {
$('input[name=source]').val(['form']); $('input[name=source]').val(['form']);
}); });
$('#upload').on('change', function() { $('#upload').on('change', function() {
$('input[name=source]').val(['file']); $('input[name=source]').val(['file']);
}); });
/* comments */
$('#comments').load('/comments/get', function() {
// handle 'add comment' button click
$('a#cadd').click(function(e) {
e.preventDefault();
var url = document.createElement('a');
url.href = window.location;
$(this).remove();
var form = $('<form method="POST" action="/comments/add" id="cadd">');
$(form).append('<hr />');
$(form).append('<textarea /><br />');
$(form).append('<input type="submit" value="Add">');
$(form).append('<input type="hidden" value="' + escape(url.pathname) + '" name="pageid">');
$(form).appendTo('#comments');
// form submit with ajax
$('#comments form').submit(function(e) {
e.preventDefault();
var text = $('#comments textarea').val();
$.post('/comments/add', {
'pageid': escape(url.pathname),
'text': text,
}, function() {
location.reload();
});
}); // form submit
}); // #cadd click
}); // #comments
}); });

Loading…
Cancel
Save