From 7e1e6c6b6e45c6a07b60dd99c8b83e9f4821b878 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 5 Jan 2015 23:21:08 +0100 Subject: [PATCH] Moved back to quote text on reply.
is not working with medium.js. --- .../app/controllers/ticket_zoom.js.coffee | 4 +- .../app/lib/app_post/utils.js.coffee | 46 +++++++++++++++++-- app/assets/stylesheets/zammad.css.scss | 3 -- public/assets/tests/html-utils.js | 42 +++++++++++++++++ 4 files changed, 87 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee b/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee index f76439a18..dbecd4bd6 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee @@ -890,7 +890,7 @@ class Edit extends App.Controller ) @$('[data-name="body"]').ce({ - mode: 'textonly' + mode: 'richtext' multiline: true maxlength: 2500 }) @@ -1494,10 +1494,10 @@ class ArticleView extends App.Controller # quote text selectedText = App.Utils.textCleanup( selectedText ) + selectedText = App.Utils.quote( selectedText ) # convert to html selectedText = App.Utils.text2html( selectedText ) - selectedText = '
' + selectedText + '
' articleNew.body = selectedText + body diff --git a/app/assets/javascripts/app/lib/app_post/utils.js.coffee b/app/assets/javascripts/app/lib/app_post/utils.js.coffee index 1fcf934bd..3cfc8318d 100644 --- a/app/assets/javascripts/app/lib/app_post/utils.js.coffee +++ b/app/assets/javascripts/app/lib/app_post/utils.js.coffee @@ -5,7 +5,7 @@ class App.Utils $.trim( ascii ) .replace(/(\r\n|\n\r)/g, "\n") # cleanup .replace(/\r/g, "\n") # cleanup - .replace(/[ ]\n/g, "\n") # remove tailing spaces + .replace(/[ ]\n/g, "\n") # remove tailing spaces .replace(/\n{3,9}/g, "\n\n") # remove multible empty lines # htmlEscapedAndLinkified = App.Utils.text2html( rawText ) @@ -28,12 +28,52 @@ class App.Utils @linkify: (ascii) -> window.linkify( ascii ) + # wrappedText = App.Utils.wrap( rawText, maxLineLength ) + @wrap: (ascii, max = 82) -> + result = '' + counter_lines = 0 + lines = ascii.split(/\n/) + for line in lines + counter_lines += 1 + counter_parts = 0 + part_length = 0 + result_part = '' + parts = line.split(/\s/) + for part in parts + counter_parts += 1 + + # put overflow of parts to result and start new line + if (part_length + part.length) > max + part_length = 0 + result_part = result_part.trim() + result_part += "\n" + result += result_part + result_part = '' + + part_length += part.length + result_part += part + + # add spacer at the end + if counter_parts isnt parts.length + part_length += 1 + result_part += ' ' + + # put parts to result + result += result_part + result_part = '' + + # add new line + if counter_lines isnt lines.length + result += "\n" + result + # quotedText = App.Utils.quote( rawText ) - @quote: (ascii) -> + @quote: (ascii, max = 82) -> ascii = @textCleanup(ascii) + ascii = @wrap(ascii, max) $.trim( ascii ) .replace /^(.*)$/mg, (match) => if match '> ' + match else - '>' \ No newline at end of file + '>' diff --git a/app/assets/stylesheets/zammad.css.scss b/app/assets/stylesheets/zammad.css.scss index b5a3e0b8a..65948a1ea 100644 --- a/app/assets/stylesheets/zammad.css.scss +++ b/app/assets/stylesheets/zammad.css.scss @@ -36,9 +36,6 @@ small { font-size: 12px; } -blockquote { - font-size: inherit; -} .u-unclickable { pointer-events: none; diff --git a/public/assets/tests/html-utils.js b/public/assets/tests/html-utils.js index cb8607f6b..0b3af1ea0 100644 --- a/public/assets/tests/html-utils.js +++ b/public/assets/tests/html-utils.js @@ -160,6 +160,41 @@ test( "linkify", function() { }); +// wrap +test( "wrap", function() { + + var source = "some text" + var should = 'some text' + var result = App.Utils.wrap( source ) + equal( result, should, source ) + + source = "some text\nsome other text\n" + should = "some text\nsome other text\n" + result = App.Utils.wrap( source ) + equal( result, should, source ) + + source = "some text with some line to wrap" + should = "some text with\nsome line to\nwrap" + result = App.Utils.wrap( source, 14 ) + equal( result, should, source ) + + source = "some text\nsome other text\n" + should = "some text\nsome other text\n" + result = App.Utils.wrap( source ) + equal( result, should, source ) + + source = "1234567890 1234567890 1234567890 1234567890" + should = "1234567890 1234567890 1234567890 1234567890" + result = App.Utils.wrap( source ) + equal( result, should, source ) + + source = "123456789012 123456789012 123456789012" + should = "123456789012\n123456789012\n123456789012" + result = App.Utils.wrap( source, 14 ) + equal( result, should, source ) + +}); + // quote test( "quote", function() { @@ -183,6 +218,13 @@ test( "quote", function() { result = App.Utils.quote( source ) equal( result, should, source ) + + source = "Welcome! Thank you for installing Zammad. You will find ..." + should = "> Welcome! Thank you\n> for installing\n> Zammad. You will\n> find ..." + result = App.Utils.quote( source, 20 ) + equal( result, should, source ) + + }); } \ No newline at end of file