From 9a8cebe4a1c298b3d6ff13332a2daded90506d3c Mon Sep 17 00:00:00 2001 From: Michael Foster Date: Sun, 15 Sep 2013 07:17:02 +1000 Subject: [PATCH] add real quick reply (wtf was the other thing?) --- js/quick-reply-old.js | 46 ++++++++++++ js/quick-reply.js | 168 ++++++++++++++++++++++++++++++++++-------- templates/main.js | 4 + 3 files changed, 188 insertions(+), 30 deletions(-) create mode 100644 js/quick-reply-old.js diff --git a/js/quick-reply-old.js b/js/quick-reply-old.js new file mode 100644 index 00000000..ea504b48 --- /dev/null +++ b/js/quick-reply-old.js @@ -0,0 +1,46 @@ +/* + * quick-reply.js + * https://github.com/savetheinternet/Tinyboard/blob/master/js/quick-reply.js + * + * Released under the MIT license + * Copyright (c) 2012 Michael Save + * + * Usage: + * $config['quick_reply'] = true; + * $config['additional_javascript'][] = 'js/jquery.min.js'; + * $config['additional_javascript'][] = 'js/quick-reply.js'; + * + */ + +$(document).ready(function(){ + if($('div.banner').length != 0) + return; // not index + + txt_new_topic = $('form[name=post] input[type=submit]').val(); + txt_new_reply = txt_new_topic == _('Submit') ? txt_new_topic : new_reply_string; + + undo_quick_reply = function() { + $('div.banner').remove(); + $('form[name=post] input[type=submit]').val(txt_new_topic); + $('form[name=post] input[name=quick-reply]').remove(); + } + + $('div.post.op').each(function() { + var id = $(this).children('p.intro').children('a.post_no:eq(1)').text(); + $('['+_("Quick reply")+']').insertAfter($(this).children('p.intro').children('a:last')).click(function() { + $('div.banner').remove(); + $('') + .insertBefore('form[name=post]'); + $('form[name=post] input[type=submit]').val(txt_new_reply); + + $('').appendTo($('form[name=post]')); + + $('form[name=post] textarea').select(); + + window.scrollTo(0, 0); + + return false; + }); + }); +}); + diff --git a/js/quick-reply.js b/js/quick-reply.js index ea504b48..3ff6002c 100644 --- a/js/quick-reply.js +++ b/js/quick-reply.js @@ -3,44 +3,152 @@ * https://github.com/savetheinternet/Tinyboard/blob/master/js/quick-reply.js * * Released under the MIT license - * Copyright (c) 2012 Michael Save + * Copyright (c) 2013 Michael Save * * Usage: - * $config['quick_reply'] = true; * $config['additional_javascript'][] = 'js/jquery.min.js'; * $config['additional_javascript'][] = 'js/quick-reply.js'; * */ -$(document).ready(function(){ - if($('div.banner').length != 0) +var show_quick_reply = function(){ + if($('div.banner').length == 0) return; // not index + + $('').appendTo($('head')); + + var $postForm = $('form[name="post"]').clone(); + + $postForm.clone(); - txt_new_topic = $('form[name=post] input[type=submit]').val(); - txt_new_reply = txt_new_topic == _('Submit') ? txt_new_topic : new_reply_string; - - undo_quick_reply = function() { - $('div.banner').remove(); - $('form[name=post] input[type=submit]').val(txt_new_topic); - $('form[name=post] input[name=quick-reply]').remove(); - } - - $('div.post.op').each(function() { - var id = $(this).children('p.intro').children('a.post_no:eq(1)').text(); - $('['+_("Quick reply")+']').insertAfter($(this).children('p.intro').children('a:last')).click(function() { - $('div.banner').remove(); - $('') - .insertBefore('form[name=post]'); - $('form[name=post] input[type=submit]').val(txt_new_reply); - - $('').appendTo($('form[name=post]')); - - $('form[name=post] textarea').select(); - - window.scrollTo(0, 0); - - return false; - }); + $dummyStuff = $('
').appendTo($postForm); + + $postForm.find('table tr').each(function() { + var $th = $(this).children('th'); + var $td = $(this).children('td'); + 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().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); + } + + if ($td.find('input[type="file"]').length) { + if ($td.find('input[name="file_url"]').length) { + $file_url = $td.find('input[name="file_url"]'); + + // Make a new row for it + $newRow = $(''); + + $file_url.clone().attr('placeholder', _('Upload URL')).appendTo($newRow.find('td')); + $file_url.parent().remove(); + + $newRow.insertBefore(this); + + $td.find('label').remove(); + $td.contents().filter(function() { + return this.nodeType == 3; // Node.TEXT_NODE + }).remove(); + $td.find('input[name="file_url"]').removeAttr('id'); + } + } + } }); -}); + + $postForm.find('textarea[name="body"]').removeAttr('id').removeAttr('cols').attr('placeholder', _('Comment')); + + $postForm.find('br').remove(); + $postForm.find('table').prepend('' + _('Quick Reply') + ''); + + $postForm.attr('id', 'quick-reply'); + + $postForm.appendTo($('body')); + + // Synchronise body text with original post form + $('#body').bind('change input propertychange', function() { + $postForm.find('textarea[name="body"]').val($(this).val()); + }); + $postForm.find('textarea[name="body"]').bind('change input propertychange', function() { + $('#body').val($(this).val()); + }); + // Synchronise other inputs + $('form[name="post"] input[type="text"]').bind('change input propertychange', function() { + $postForm.find('input[name="' + $(this).attr('name') + '"]').val($(this).val()); + }); + $postForm.find('input[type="text"]').bind('change input propertychange', function() { + $('form[name="post"] input[name="' + $(this).attr('name') + '"]').val($(this).val()); + }); +}; +$(window).on('cite', function() { + show_quick_reply(); + $('#quick-reply textarea').focus(); +}); diff --git a/templates/main.js b/templates/main.js index 144c5f62..c0961878 100644 --- a/templates/main.js +++ b/templates/main.js @@ -198,6 +198,10 @@ function citeReply(id) { // ??? body.value += '>>' + id + '\n'; } + if ($) { + $(window).trigger('cite', id); + $(body).change(); + } } function rememberStuff() {