You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.3 KiB
42 lines
1.3 KiB
$(document).ready(function() { |
|
/* code highlight */ |
|
$('pre code').each(function(i, block) { |
|
hljs.highlightBlock(block); |
|
}); |
|
|
|
/* zerobin / radio 'source' autoswitch */ |
|
$('#paste').on('change', function() { |
|
$('input[name=source]').val(['form']); |
|
}); |
|
$('#upload').on('change', function() { |
|
$('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 |
|
});
|
|
|