diff --git a/app/assets/javascripts/app/controllers/ticket_zoom/article_action/email_reply.coffee b/app/assets/javascripts/app/controllers/ticket_zoom/article_action/email_reply.coffee index 1827adcbc..204dbd7d4 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom/article_action/email_reply.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom/article_action/email_reply.coffee @@ -131,6 +131,7 @@ class EmailReply extends App.Controller selected = App.ClipBoard.getSelected('html') if selected selected = App.Utils.htmlCleanup(selected).html() + selected = App.Utils.htmlImage2DataUrl(selected) if !selected selected = App.ClipBoard.getSelected('text') if selected @@ -173,6 +174,8 @@ class EmailReply extends App.Controller body = '' if article.content_type.match('html') body = App.Utils.textCleanup(article.body) + body = App.Utils.htmlImage2DataUrl(article.body) + if article.content_type.match('plain') body = App.Utils.textCleanup(article.body) body = App.Utils.text2html(body) diff --git a/app/assets/javascripts/app/lib/app_post/utils.coffee b/app/assets/javascripts/app/lib/app_post/utils.coffee index 8fc83ec1f..7307bcf3d 100644 --- a/app/assets/javascripts/app/lib/app_post/utils.coffee +++ b/app/assets/javascripts/app/lib/app_post/utils.coffee @@ -1080,3 +1080,23 @@ class App.Utils ) App.Delay.set(a, 500, undefined, 'tags') + @htmlImage2DataUrl: (html) -> + return html if !html + return html if !html.match(/#{html}") + + html.find('img').each( (index) -> + src = $(@).attr('src') + if !src.match(/^data:/i) + base64 = App.Utils._htmlImage2DataUrl(@) + $(@).attr('src', base64) + ) + html.get(0).innerHTML + + @_htmlImage2DataUrl: (img) -> + canvas = document.createElement('canvas') + canvas.width = img.width + canvas.height = img.height + ctx = canvas.getContext('2d') + ctx.drawImage(img, 0, 0) + canvas.toDataURL('image/png') diff --git a/app/views/tests/html_utils.html.erb b/app/views/tests/html_utils.html.erb index b5df0ebde..97cadc26b 100644 --- a/app/views/tests/html_utils.html.erb +++ b/app/views/tests/html_utils.html.erb @@ -13,3 +13,5 @@ body {
+ +
diff --git a/public/assets/tests/html_utils.js b/public/assets/tests/html_utils.js index 8097ceb88..492fed2a9 100644 --- a/public/assets/tests/html_utils.js +++ b/public/assets/tests/html_utils.js @@ -2644,8 +2644,6 @@ test('check getRecipientArticle format', function() { }); -} - test("contentTypeCleanup", function() { var source = "image/png" @@ -2682,4 +2680,51 @@ test("contentTypeCleanup", function() { should = "image/gif" result = App.Utils.contentTypeCleanup(source) equal(result, should, source) -}); \ No newline at end of file +}); + +// htmlImage2DataUrl +test("htmlImage2DataUrl", function() { + + var source = '
test 13
' + var should = '
test 13
' + var result = App.Utils.htmlImage2DataUrl(source) + equal(result, should, source) + + source = 'some test' + should = 'some test' + result = App.Utils.htmlImage2DataUrl(source) + equal(result, should, source) + + source = 'some test' + should = 'some test' + result = App.Utils.htmlImage2DataUrl(source) + equal(result, should, source) + + source = 'some test' + should = 'some test' + result = App.Utils.htmlImage2DataUrl(source) + equal(result, should, source) + + source = 'some test' + should = 'some test' + result = App.Utils.htmlImage2DataUrl(source) + equal(result, should, source) + +}); + +source = 'some test' +$('#image2text').html(source) +var htmlImage2DataUrlTest = function() { + + var result = App.Utils.htmlImage2DataUrl(source) + test("htmlImage2DataUrl async", function() { + var result = App.Utils.htmlImage2DataUrl(source) + ok(result.match(/some test/), source) + ok(!result.match(/avatar-bg.png/), source) + ok(result.match(/^\