var bindFunctions = function()
{
// the following block of code deals with drag and drop of images for MD5 hashing
var search_dropdown = jQuery('#search_form_image');
if (isEventSupported('dragstart') && isEventSupported('drop') && !!window.FileReader)
{
search_dropdown.on('dragover', function(e) {
e.preventDefault();
e.stopPropagation();
e.originalEvent.dataTransfer.dropEffect = 'copy';
});
search_dropdown.on('dragenter', function(e) {
e.preventDefault();
e.stopPropagation();
});
search_dropdown.on('drop', function(event) {
if (event.originalEvent.dataTransfer){
if (event.originalEvent.dataTransfer.files.length) {
event.preventDefault();
event.stopPropagation();
findSameImageFromFile(event.originalEvent.dataTransfer);
}
}
});
}
var is_posting = false;
var clickCallbacks = {
checkAll: function(el, post, event)
{
var checkboxes = el.parent().parent().find('input[type=checkbox]');
checkboxes.each(function(id, element) {
jQuery(element).attr('checked', 'checked');
});
el.parent().find('.uncheck').show();
el.hide();
},
uncheckAll: function(el, post, event)
{
var checkboxes = el.parent().parent().find('input[type=checkbox]');
checkboxes.each(function(id, element) {
jQuery(element).attr('checked', false);
});
el.parent().find('.check').show();
el.hide();
},
hideThread: function(el, post, event)
{
var hiddenBoardThreads = JSON.parse(localStorage.getItem("hiddenBoardThreads/" + el.data("board"))) || {};
var num = el.data("doc-id");
hiddenBoardThreads[num] = true;
localStorage.setItem("hiddenBoardThreads/" + el.data("board"), JSON.stringify(hiddenBoardThreads));
jQuery(".doc_id_" + num).hide();
jQuery(".stub_doc_id_" + num).show();
},
showThread: function(el, post, event)
{
var hiddenBoardThreads = JSON.parse(localStorage.getItem("hiddenBoardThreads/" + el.data("board"))) || {};
var num = el.data("doc-id");
delete hiddenBoardThreads[num];
localStorage.setItem("hiddenBoardThreads/" + el.data("board"), JSON.stringify(hiddenBoardThreads));
jQuery(".doc_id_" + num).show();
jQuery(".stub_doc_id_" + num).hide();
},
hidePost: function(el, post, event)
{
var hiddenBoardPosts = JSON.parse(localStorage.getItem("hiddenBoardPosts/" + el.data("board"))) || {};
var num = el.data("doc-id");
hiddenBoardPosts[num] = true;
localStorage.setItem("hiddenBoardPosts/" + el.data("board"), JSON.stringify(hiddenBoardPosts));
jQuery(".doc_id_" + num).hide();
jQuery(".stub_doc_id_" + num).show();
},
showPost: function(el, post, event)
{
var hiddenBoardPosts = JSON.parse(localStorage.getItem("hiddenBoardPosts/" + el.data("board"))) || {};
var num = el.data("doc-id");
delete hiddenBoardPosts[num];
localStorage.setItem("hiddenBoardPosts/" + el.data("board"), JSON.stringify(hiddenBoardPosts));
jQuery(".doc_id_" + num).show();
jQuery(".stub_doc_id_" + num).hide();
},
highlight: function(el, post, event)
{
if (post)
{
toggleHighlight(post);
}
},
quote: function(el, post, event)
{
jQuery("#reply_chennodiscursus").insertAtCaret(">>" + post + "\n");
},
comment: function(el, post, event)
{
var file_el = jQuery("#file_image");
var progress_pos = 0;
var progress_el = jQuery("#reply .progress .bar");
// if there's an image and the browser doesn't support FormData, use a normal upload process
if (file_el.val() && window.FormData === undefined)
{
return true;
}
if (is_posting)
{
return false;
}
is_posting = true;
var originalText = el.attr('value');
var el_parent = el.parent();
el.attr({'value': backend_vars.gettext['submit_state']});
el_parent.find('[name=reply_gattai]').attr({disabled:'disabled'});
el_parent.find('[name=reply_gattai_spoilered]').attr({disabled:'disabled'});
//el.parent().find('[name=reply_gattai], [name=reply_gattai_spoilered]')
// to make sure nobody gets pissed off with a blocked button
var buttonTimeout = setTimeout(function(){
el.attr({'value': originalText});
el.removeAttr('disabled');
}, 10000);
var reply_alert = jQuery('#reply_ajax_notices');
reply_alert.removeClass('error').removeClass('success');
var data_obj = {
reply_numero: jQuery("#reply_numero").val(),
reply_bokunonome: jQuery("#reply_bokunonome").val(),
reply_elitterae: jQuery("#reply_elitterae").val(),
reply_talkingde: jQuery("#reply_talkingde").val(),
reply_chennodiscursus: jQuery("#reply_chennodiscursus").val(),
reply_nymphassword: jQuery("#reply_nymphassword").val(),
reply_postas: jQuery("#reply_postas").val() === undefined ? 'N' : jQuery("#reply_postas").val(),
reply_gattai: 'Submit',
reply_last_limit: typeof backend_vars.last_limit === "undefined" ? null : backend_vars.last_limit,
latest_doc_id: backend_vars.latest_doc_id,
theme: backend_vars.selected_theme
};
if(typeof jQuery("#recaptcha_challenge_field").val() !== 'undefined' && typeof jQuery("#recaptcha_response_field").val() !== 'undefined') {
data_obj['recaptcha_challenge_field'] = jQuery("#recaptcha_challenge_field").val();
data_obj['recaptcha_response_field'] = jQuery("#recaptcha_response_field").val();
} else if(typeof jQuery("#g-recaptcha-response").val() !== 'undefined') {
data_obj['recaptcha2_response_field'] = jQuery("#g-recaptcha-response").val();
}
// sets the type of submit (reply_gattai, reply_gattai_spoilered)
data_obj[el.attr('name')] = true;
// support for checkbox spoiler
if (el_parent.find('[name=reply_spoiler]:checked').length)
{
data_obj.reply_spoiler = true;
}
data_obj[backend_vars.csrf_token_key] = getCookie(backend_vars.csrf_token_key);
progress_el.parent().animate({'opacity': '1.0'}, 300);
var ajax_object = {
url: backend_vars.site_url + backend_vars.board_shortname + '/submit/' ,
dataType: 'json',
type: 'POST',
data: data_obj,
cache: false,
xhr: function() {
var xhr = jQuery.ajaxSettings.xhr();
if (xhr instanceof window.XMLHttpRequest) {
xhr.upload.addEventListener('progress', function(evt){
var progress_local = Math.ceil(evt.loaded / evt.total * 100);
if (evt.lengthComputable && progress_pos !== progress_local)
{
progress_pos = progress_local;
progress_el.css('width', (progress_pos) + '%');
}
}, false);
}
return xhr;
},
success: function(data, textStatus, jqXHR) {
if (typeof window.Recaptcha !== "undefined")
{
window.Recaptcha.reload();
}
if (typeof window.grecaptcha !== "undefined") {
grecaptcha.reset();
}
jQuery("#recaptcha_response_field").val('');
if (typeof data.captcha !== "undefined")
{
if(recaptcha2.enabled && typeof window.grecaptcha === "undefined") {
jQuery('.recaptcha_widget').html('
You might be a bot! Enter a reCAPTCHA to continue.
\
\
')
}
jQuery('.recaptcha_widget').show();
jQuery('.rules_box').hide();
return false;
}
if (typeof data.error !== "undefined")
{
reply_alert.html(data.error);
reply_alert.addClass('error'); // deals with showing the alert
return false;
}
jQuery('.rules_box').show();
jQuery('.recaptcha_widget').hide();
reply_alert.html(data.success);
reply_alert.addClass('success'); // deals with showing the alert
jQuery("#reply_chennodiscursus").val("");
jQuery("#reply_nymphassword").val(getCookie('reply_password'));
file_el.replaceWith('');
// redirect in case of new threads
if (data_obj.reply_numero < 1)
{
window.location = backend_vars.site_url + backend_vars.board_shortname + '/thread/'
+ data.thread_num + '/';
return false;
}
insertPost(data, textStatus, jqXHR);
},
error: function(jqXHR, textStatus, errorThrown) {
reply_alert.html('Connection error.');
reply_alert.addClass('error');
reply_alert.show();
},
complete: function() {
// clear button's timeout, we can deal with the rest now
is_posting = false;
clearTimeout(buttonTimeout);
el.attr({'value': originalText});
el_parent.find('[name=reply_gattai]').removeAttr('disabled');
el_parent.find('[name=reply_gattai_spoilered]').removeAttr('disabled');
progress_el.css('width', '0%');
progress_el.parent().animate({'opacity': '0.0'}, 300);
}
};
// if we have FormData support, we can upload files!
if (window.FormData !== undefined)
{
ajax_object.processData = false;
ajax_object.contentType = false;
var data_formdata = new FormData();
jQuery.each(data_obj, function(id, val){
data_formdata.append(id, val);
});
if (typeof file_el[0] !== 'undefined' && typeof file_el[0].files !== 'undefined')
{
data_formdata.append('file_image', file_el[0].files[0])
}
ajax_object.data = data_formdata;
}
jqxhr = jQuery.ajax(ajax_object);
event.preventDefault();
},
realtimeThread: function(el, post, event)
{
realtimethread();
event.preventDefault();
},
expandThread: function(el, post, event)
{
var thread_num = el.data('thread-num');
if (! el.data('expanded'))
{
el.spin('small');
jQuery.ajax({
url: backend_vars.api_url + '_/api/chan/thread/',
dataType: 'json',
type: 'GET',
data: {
num : thread_num,
board: backend_vars.board_shortname,
theme: backend_vars.selected_theme
},
success: function(data, textStatus, jqXHR){
insertPost(data, textStatus, jqXHR);
var post_count = 0;
var media_count = 0;
jQuery.each(data[thread_num].posts, function(id, val){
post_count++;
if (val.media !== null)
{
media_count++;
}
});
var thread = jQuery('article.thread[data-thread-num=' + thread_num + '] ');
var displayed_string = post_count + ' posts ' +
(media_count > 0 ? 'and ' + media_count + ' ' + (media_count == 1 ? 'image' : 'images') : '') + ' displayed';
thread.find('.omitted_text').text(displayed_string);
el.data('expanded', true).html('');
el.spin(false);
}
});
}
else
{
var thread = jQuery('article.thread[data-thread-num=' + thread_num + ']');
var articles = thread.find('aside.posts article');
articles.slice(0, articles.length - 5).hide();
var post_count = articles.filter(':hidden').length;
var media_count = articles.find('.thread_image_box:hidden').length;
var omitted_string = post_count + ' posts ' +
(media_count > 0 ? 'and ' + media_count + ' ' + (media_count == 1 ? 'image' : 'images') : '') + ' omitted';
thread.find('.omitted_text').text(omitted_string);
el.data('expanded', false).html('');
}
return false;
},
clearSearch: function(el, post, event)
{
var form = jQuery('.advanced_search').find('form');
form.find(':input').not(':input[type=submit]').not(':input[type=reset]').val('');
// keep the first radio set
var done_names = [];
form.find('[type=radio]').each(function (idx) {
if (!jQuery.inArray(jQuery(this).attr('name'), done_names))
{
jQuery(this).attr('checked', true);
done_names.push(jQuery(this).attr('name'));
}
});
},
mod: function(el, post, event)
{
el.attr({'disabled': 'disabled'});
_data = {
board: el.data('board'),
id: el.data('id'),
ip: el.data('ip'),
action: el.data('action'),
global: el.data('global'),
theme: backend_vars.selected_theme
};
_data[backend_vars.csrf_token_key] = getCookie(backend_vars.csrf_token_key);
jQuery.ajax({
url: backend_vars.api_url + '_/api/chan/mod_actions/',
dataType: 'json',
type: 'POST',
cache: false,
data: _data,
success: function(data){
el.removeAttr('disabled');
if (typeof data.error !== "undefined")
{
alert(data.error);
return false;
}
// might need to be upgraded to array support
switch(el.data('action'))
{
case 'remove_post':
jQuery('.doc_id_' + el.data('id')).remove();
break;
case 'delete_image':
jQuery('.doc_id_' + el.data('doc-id')).find('.thread_image_box:eq(0) img')
.attr('src', backend_vars.images['missing_image'])
.css({
width: backend_vars.images['missing_image_width'],
height: backend_vars.images['missing_image_height']
});
break;
case 'delete_report':
el.closest('.report_reason').remove();
break;
case 'ban_user':
jQuery('.doc_id_' + el.data('id')).find('[data-action=ban_user]').text('Banned');
break;
case 'ban_image':
jQuery('.doc_id_' + el.data('doc-id')).find('.thread_image_box:eq(0) img')
.attr('src', backend_vars.images['banned_image'])
.css({
width: backend_vars.images['banned_image_width'],
height: backend_vars.images['banned_image_height']
});
break;
case 'delete_all_reports':
$(".report_reason").each(function(){
$(this).remove();
});
break;
default:
el.closest('.report_reason').append(data.success);
break;
}
},
error: function(jqXHR, textStatus, errorThrown) {
},
complete: function() {
}
});
return false;
},
activateModeration: function(el, post, event)
{
jQuery('.post_mod_controls button[data-function]').attr({'disabled': 'disabled'});
setTimeout(function(){
jQuery('.post_mod_controls button[data-function]').removeAttr('disabled');
}, 700);
jQuery('.post_mod_controls').show();
jQuery('button[data-function=activateModeration]').parent().hide();
},
activateExtraMod: function(el, post, event)
{
jQuery('.post_extra_mod button[data-function]').attr({'disabled': 'disabled'});
setTimeout(function(){
jQuery('.post_extra_mod button[data-function]').removeAttr('disabled');
}, 700);
jQuery('.post_extra_mod').show();
jQuery('button[data-function=activateExtraMod]').parent().hide();
},
closeModal: function(el, post)
{
el.closest(".modal").modal('hide');
return false;
},
'delete': function(el, post, event)
{
var modal = jQuery("#post_tools_modal");
var foolfuuka_reply_password = getCookie('foolfuuka_reply_password');
modal.find(".title").html('Delete » Post No. ' + el.data("post-id"));
modal.find(".modal-error").html('');
modal.find(".modal-loading").hide();
modal.find(".modal-information").html('\
Password\n\
\n\
\n\
');
modal.find(".submitModal").data("action", 'delete');
modal.find(".modal-password").val(backend_vars.user_pass);
},
report: function(el, post, event)
{
var modal = jQuery("#post_tools_modal");
modal.find(".title").html('Report » Post No.' + el.data("post-id"));
modal.find(".modal-error").html('');
modal.find(".modal-loading").hide();
modal.find(".modal-information").html('Report Multiple\
\n\
\n\
Comment\n\
\n\
Note: Requests for content removal and take-downs must be sent via email.');
modal.find(".submitModal").data("action", 'report');
},
addBulkReport: function(el, post, event) {
jQuery('article.thread, article.post').each(function () {
if (typeof jQuery(this).attr('data-board') != 'undefined') {
jQuery(this).find('a[data-function=report]:eq(0)').replaceWith('' +
'Report Selected');
}
});
el.closest(".modal").modal('hide');
},
bulkReport: function(el, post, event) {
var modal = jQuery("#post_tools_modal");
modal.find(".title").html('Report Posts');
modal.find(".modal-error").html('');
modal.find(".modal-loading").hide();
modal.find(".modal-information").html('Selected posts:
');
jQuery('.bulkreportselect:checked').each(function () {
modal.find(".modal-information").append('>>>/' + $(this).attr('data-board') + '/' + $(this).attr('data-num') + '
');
});
modal.find(".modal-information").append('
Comment\n\
\n\
Note: Requests for content removal and take-downs must be sent via email.');
modal.find(".submitModal").data("action", 'bulk-report');
},
ban: function(el, post, event)
{
var modal = jQuery("#post_tools_modal");
modal.find(".title").html('Ban user with IP ' + el.data("ip"));
modal.find(".modal-error").html('');
modal.find(".modal-loading").hide();
modal.find(".modal-information").html('\
\n\
IP\n\
\n\
Days\n\
\n\
Only this board\n\
\n\
Global\n\
\n\
Comment\n\
\n\
\
\n\
');
modal.find(".submitModal").data("action", 'ban');
},
editPost: function(el, post, event)
{
var modal = jQuery("#post_tools_modal");
modal.find(".title").html('Edit Post No. ' + el.data("post-id"));
modal.find(".modal-error").html('');
modal.find(".modal-loading").show();
modal.find(".modal-information").html('Bulk Edit\
');
modal.find(".modal-loading").hide();
}
});
},
addBulkEdit: function(el, post, event) {
jQuery('article.thread, article.post').each(function () {
if (typeof jQuery(this).attr('data-board') != 'undefined') {
jQuery('' +
'Edit Selected')
.prependTo($(this).find('.post_data:first'));
}
});
el.closest(".modal").modal('hide');
},
bulkEdit: function(el, post, event) {
var modal = jQuery("#post_tools_modal");
modal.find(".title").html('Edit Posts');
modal.find(".modal-error").html('');
modal.find(".modal-loading").hide();
modal.find(".modal-information").html('This will only modify specified fields. Leave blank to not modify that field.
' +
'Selected posts:
');
jQuery('.bulkselect:checked').each(function () {
modal.find(".modal-information").append('>>>/' + $(this).attr('data-board') + '/' + $(this).attr('data-num') + '
');
});
modal.find(".modal-information").append('