1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-12-25 05:44:57 +01:00
vichan/js/quick-post-controls.js

87 lines
2.7 KiB
JavaScript
Raw Normal View History

2012-03-15 08:14:54 +01:00
/*
* quick-posts-controls.js
2012-03-31 02:13:11 +02:00
* https://github.com/savetheinternet/Tinyboard/blob/master/js/quick-posts-controls.js
2012-03-15 08:14:54 +01:00
*
* Released under the MIT license
* Copyright (c) 2012 Michael Save <savetheinternet@tinyboard.org>
*
* Usage:
* $config['additional_javascript'][] = 'js/jquery.min.js';
* $config['additional_javascript'][] = 'js/quick-post-controls.js';
*
*/
$(document).ready(function(){
var open_form = function() {
var thread = $(this).parent().parent().hasClass('op');
var id = $(this).attr('name').match(/^delete_(\d+)$/)[1];
var submitButton;
if(this.checked) {
var post_form = $('<form class="post-actions" method="post" style="margin:10px 0 0 0">' +
2012-03-15 08:14:54 +01:00
'<div style="text-align:right">' +
(!thread ? '<hr>' : '') +
'<input type="hidden" name="delete_' + id + '">' +
2013-07-03 07:55:43 +02:00
'<label for="password_' + id + '">'+_("Password")+'</label>: ' +
2012-03-15 08:14:54 +01:00
'<input id="password_' + id + '" type="password" name="password" size="11" maxlength="18">' +
2013-07-03 07:55:43 +02:00
'<input title="'+_('Delete file only')+'" type="checkbox" name="file" id="delete_file_' + id + '">' +
'<label for="delete_file_' + id + '">'+_('File')+'</label>' +
' <input type="submit" name="delete" value="'+_('Delete')+'">' +
2012-03-15 08:14:54 +01:00
'<br>' +
2013-07-03 07:55:43 +02:00
'<label for="reason_' + id + '">'+_('Reason')+'</label>: ' +
2012-03-15 08:14:54 +01:00
'<input id="reason_' + id + '" type="text" name="reason" size="20" maxlength="100">' +
2013-07-03 07:55:43 +02:00
' <input type="submit" name="report" value="'+_('Report')+'">' +
2012-03-15 08:14:54 +01:00
'</div>' +
'</form>');
post_form
.attr('action', $('form:first').attr('action'))
.append($('input[name=board]:first').clone())
2012-03-15 08:14:54 +01:00
.find('input:not([type="checkbox"]):not([type="submit"]):not([type="hidden"])').keypress(function(e) {
if(e.which == 13) {
e.preventDefault();
if($(this).attr('name') == 'password') {
post_form.find('input[name=delete]').click();
} else if($(this).attr('name') == 'reason') {
post_form.find('input[name=report]').click();
}
return false;
}
return true;
});
post_form.find('input[type="password"]').val(localStorage.password);
2012-03-15 08:14:54 +01:00
if(thread) {
2012-08-27 15:01:08 +02:00
post_form.prependTo($(this).parent().parent().find('div.body'));
2012-03-15 08:14:54 +01:00
} else {
post_form.appendTo($(this).parent().parent());
//post_form.insertBefore($(this));
}
} else {
var elm = $(this).parent().parent().find('form');
if(elm.attr('class') == 'post-actions')
elm.remove();
}
};
var init_qpc = function() {
2012-03-15 08:14:54 +01:00
$(this).change(open_form);
if(this.checked)
$(this).trigger('change');
};
$('div.post input[type=checkbox].delete').each(init_qpc);
$(document).bind('new_post', function(e, post) {
$(post).find('input[type=checkbox].delete').each(init_qpc);
2012-03-15 08:14:54 +01:00
});
});