From a8312b519622fd4998a427f728d1409a7d7e43ec Mon Sep 17 00:00:00 2001 From: marktaiwan Date: Wed, 28 Jan 2015 22:49:42 +0800 Subject: [PATCH] multi-line quotes & init no longer uses jQuery --- templates/main.js | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/templates/main.js b/templates/main.js index 76cb5347..a7e3445d 100644 --- a/templates/main.js +++ b/templates/main.js @@ -333,21 +333,23 @@ function citeReply(id, with_link) { // ??? textarea.value += '>>' + id + '\n'; } - if (typeof $ != 'undefined') { - // multiline quotes - var select = sessionStorage.quoteClipboard; - if (select) { - select = select.split('\n'); - $(select).each(function () { - if (this !== '') - var str = '>'+ this +'\n'; - else - var str = '\n'; - textarea.value += str; - }); - delete sessionStorage.quoteClipboard; - } + // multiline quotes + var select = sessionStorage.quoteClipboard; + if (select) { + select = select.split('\n'); + select.forEach(function (str) { + if (str !== '') { + str = '>' + str + '\n'; + } else { + str = '\n'; + } + textarea.value += str; + }); + delete sessionStorage.quoteClipboard; + } + + if (typeof $ != 'undefined') { $(window).trigger('cite', [id, with_link]); $(textarea).change(); } @@ -408,12 +410,10 @@ 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(); - }); - } + // store highlighted text for citeReply() + document.querySelector('form[name="postcontrols"]').addEventListener('mouseup', function (e) { + sessionStorage.quoteClipboard = window.getSelection().toString(); + }); {% endraw %} {% if config.allow_delete %}