/* * quick-reply.js * https://github.com/savetheinternet/Tinyboard/blob/master/js/quick-reply.js * * Released under the MIT license * Copyright (c) 2013 Michael Save * Copyright (c) 2013-2014 Marcin Ɓabanowski * * Usage: * $config['additional_javascript'][] = 'js/jquery.min.js'; * $config['additional_javascript'][] = 'js/jquery-ui.custom.min.js'; // Optional; if you want the form to be draggable. * $config['additional_javascript'][] = 'js/quick-reply.js'; * */ (function() { var settings = new script_settings('quick-reply'); var do_css = function() { $('#quick-reply-css').remove(); // Find background of reply posts var dummy_reply = $('
').appendTo($('body')); var reply_background = dummy_reply.css('backgroundColor'); var reply_border_style = dummy_reply.css('borderStyle'); var reply_border_color = dummy_reply.css('borderColor'); var reply_border_width = dummy_reply.css('borderWidth'); dummy_reply.remove(); $('').appendTo($('head')); }; var show_quick_reply = function(){ if($('div.banner').length == 0) return; if($('#quick-reply').length != 0) return; do_css(); var $postForm = $('form[name="post"]').clone(); $postForm.clone(); $dummyStuff = $('
').appendTo($postForm); $postForm.find('table tr').each(function() { var $th = $(this).children('th:first'); var $td = $(this).children('td:first'); if ($th.length && $td.length) { $td.attr('colspan', 2); if ($td.find('input[type="text"]').length) { // Replace with input placeholders $td.find('input[type="text"]') .removeAttr('size') .attr('placeholder', $th.clone().children().remove().end().text()); } // Move anti-spam nonsense and remove $th.contents().filter(function() { return this.nodeType == 3; // Node.TEXT_NODE }).remove(); $th.contents().appendTo($dummyStuff); $th.remove(); if ($td.find('input[name="password"]').length) { // Hide password field $(this).hide(); } // Fix submit button if ($td.find('input[type="submit"]').length) { $td.removeAttr('colspan'); $('').append($td.find('input[type="submit"]')).insertAfter($td); } // reCAPTCHA if ($td.find('#recaptcha_widget_div').length) { // Just show the image, and have it interact with the real form. var $captchaimg = $td.find('#recaptcha_image img'); $captchaimg .removeAttr('id') .removeAttr('style') .addClass('recaptcha_image') .click(function() { $('#recaptcha_reload').click(); }); // When we get a new captcha... $('#recaptcha_response_field').focus(function() { if ($captchaimg.attr('src') != $('#recaptcha_image img').attr('src')) { $captchaimg.attr('src', $('#recaptcha_image img').attr('src')); $postForm.find('input[name="recaptcha_challenge_field"]').val($('#recaptcha_challenge_field').val()); $postForm.find('input[name="recaptcha_response_field"]').val('').focus(); } }); $postForm.submit(function() { setTimeout(function() { $('#recaptcha_reload').click(); }, 200); }); // Make a new row for the response text var $newRow = $(''); $newRow.children().first().append( $td.find('input').removeAttr('style') ); $newRow.find('#recaptcha_response_field') .removeAttr('id') .addClass('recaptcha_response_field') .attr('placeholder', $('#recaptcha_response_field').attr('placeholder')); $('#recaptcha_response_field').addClass('recaptcha_response_field') $td.replaceWith($('').append($('').append($captchaimg))); $newRow.insertAfter(this); } // Upload section if ($td.find('input[type="file"]').length) { if ($td.find('input[name="file_url"]').length) { $file_url = $td.find('input[name="file_url"]'); if (settings.get('show_remote', false)) { // Make a new row for it var $newRow = $(''); $file_url.clone().attr('placeholder', _('Upload URL')).appendTo($newRow.find('td')); $newRow.insertBefore(this); } $file_url.parent().remove(); $td.find('label').remove(); $td.contents().filter(function() { return this.nodeType == 3; // Node.TEXT_NODE }).remove(); $td.find('input[name="file_url"]').removeAttr('id'); } if ($(this).find('input[name="spoiler"]').length) { $td.removeAttr('colspan'); } } // Disable embedding if configured so if (!settings.get('show_embed', false) && $td.find('input[name="embed"]').length) { $(this).remove(); } // Remove oekaki if existent if ($(this).is('#oekaki')) { $(this).remove(); } // Remove upload selection if ($td.is('#upload_selection')) { $(this).remove(); } // Remove mod controls, because it looks shit. if ($td.find('input[type="checkbox"]').length) { var tr = this; $td.find('input[type="checkbox"]').each(function() { if ($(this).attr('name') == 'spoiler') { $td.find('label').remove(); $(this).attr('id', 'q-spoiler-image'); $postForm.find('input[type="file"]').parent() .removeAttr('colspan') .after($('').append(this, ' ', $('