From 5acdf16f5e7f754c99703862666479235ee642fc Mon Sep 17 00:00:00 2001 From: marktaiwan Date: Sun, 25 Jan 2015 22:08:25 +0800 Subject: [PATCH] reply quoting improvement - multi line quoting - ability to quote from board index - works in Chrome --- templates/main.js | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/templates/main.js b/templates/main.js index 254e12c0..76cb5347 100644 --- a/templates/main.js +++ b/templates/main.js @@ -334,13 +334,18 @@ function citeReply(id, with_link) { textarea.value += '>>' + id + '\n'; } if (typeof $ != 'undefined') { - var select = document.getSelection().toString(); + // multiline quotes + var select = sessionStorage.quoteClipboard; if (select) { - var body = $('#reply_' + id + ', #op_' + id).find('div.body'); // TODO: support for OPs - var index = body.text().indexOf(select.replace('\n', '')); // for some reason this only works like this - if (index > -1) { - textarea.value += '>' + select + '\n'; - } + select = select.split('\n'); + $(select).each(function () { + if (this !== '') + var str = '>'+ this +'\n'; + else + var str = '\n'; + textarea.value += str; + }); + delete sessionStorage.quoteClipboard; } $(window).trigger('cite', [id, with_link]); @@ -403,6 +408,13 @@ var script_settings = function(script_name) { function init() { init_stylechooser(); + if (typeof $ != 'undefined') { + // store highlighted text for citeReply() + $('form[name="postcontrols"]').on('mouseup', function (e) { + sessionStorage.quoteClipboard = window.getSelection().toString(); + }); + } + {% endraw %} {% if config.allow_delete %} if (document.forms.postcontrols) {