##// END OF EJS Templates
Add a random number of spaces to spoiler (BB-71)
Add a random number of spaces to spoiler (BB-71)

File last commit:

r1451:99d5a663 default
r1458:fd15aa6f default
Show More
form.js
95 lines | 2.6 KiB | application/javascript | JavascriptLexer
neko259
Updated form to a new style. Fixed mark manel
r680 $('input[name=image]').wrap($('<div class="file_wrap"></div>'));
neko259
Added a compact form to the thread.
r676
$('body').on('change', 'input[name=image]', function(event) {
neko259
Added image preview in the forms
r673 var file = event.target.files[0];
if(file.type.match('image.*')) {
var fileReader = new FileReader();
fileReader.addEventListener("load", function(event) {
neko259
Updated form to a new style. Fixed mark manel
r680 var wrapper = $('.file_wrap');
wrapper.find('.file-thumb').remove();
wrapper.append(
$('<div class="file-thumb" style="background-image: url('+event.target.result+')"></div>')
neko259
Added image preview in the forms
r673 );
});
fileReader.readAsDataURL(file);
}
neko259
Post message by ctrl-enter on the text field
r1005 });
var form = $('#form');
$('textarea').keypress(function(event) {
neko259
Submit form only on ctrl-enter, not every enter
r1007 if (event.which == 13 && event.ctrlKey) {
neko259
Added PoW instead of 30-second captcha
r1428 form.find('input[type=submit]').click();
neko259
Post message by ctrl-enter on the text field
r1005 }
neko259
Added AJAX text preview to the form.
r1217 });
$('#preview-button').click(function() {
var data = {
raw_text: $('textarea').val()
}
var diffUrl = '/api/preview/';
$.post(diffUrl,
data,
function(data) {
var previewTextBlock = $('#preview-text');
previewTextBlock.html(data);
previewTextBlock.show();
})
neko259
Added PoW instead of 30-second captcha
r1428 });
/**
* Show text in the errors row of the form.
* @param form
* @param text
*/
function showAsErrors(form, text) {
form.children('.form-errors').remove();
if (text.length > 0) {
var errorList = $('<div class="form-errors">' + text + '<div>');
errorList.appendTo(form);
}
}
function addHiddenInput(form, name, value) {
form.find('input[name=' + name + ']').val(value);
}
$(document).ready(function() {
var powDifficulty = parseInt($('body').attr('data-pow-difficulty'));
if (powDifficulty > 0) {
var worker = new Worker($('#powScript').attr('src'));
worker.onmessage = function(e) {
var form = $('#form');
addHiddenInput(form, 'timestamp', e.data.timestamp);
addHiddenInput(form, 'iteration', e.data.iteration);
addHiddenInput(form, 'guess', e.data.guess);
form.submit();
neko259
Block the form while computing PoW.
r1451 $('.post-form-w').unblock();
neko259
Added PoW instead of 30-second captcha
r1428 };
var form = $('#form');
var submitButton = form.find('input[type=submit]');
submitButton.click(function() {
showAsErrors(form, gettext('Computing PoW...'));
neko259
Block the form while computing PoW.
r1451 $('.post-form-w').block({ message: gettext('Computing PoW...') })
neko259
Added PoW instead of 30-second captcha
r1428
var msg = $('textarea').val().trim();
var data = {
msg: msg,
difficulty: parseInt($('body').attr('data-pow-difficulty')),
hasher: $('#sha256Script').attr('src')
};
worker.postMessage(data);
return false;
});
}
});