Improved use of App.Utils.htmlRemoveRichtext. Fixed twitter browser tests.

This commit is contained in:
Martin Edenhofer 2016-05-17 20:40:00 +02:00
parent 7f39927506
commit 73f6cc6389
5 changed files with 28 additions and 15 deletions

View file

@ -283,15 +283,24 @@ class App.TicketZoomArticleNew extends App.Controller
params.type_id = type.id params.type_id = type.id
if params.type is 'twitter status' if params.type is 'twitter status'
App.Utils.htmlRemoveRichtext(@$('[data-name=body]')) rawHTML = @$('[data-name=body]').html()
cleanHTML = App.Utils.htmlRemoveRichtext(rawHTML)
if cleanHTML && cleanHTML.html() != rawHTML
@$('[data-name=body]').html(cleanHTML)
params.content_type = 'text/plain' params.content_type = 'text/plain'
params.body = "#{App.Utils.html2text(params.body, true)}\n#{@signature.text()}" params.body = "#{App.Utils.html2text(params.body, true)}\n#{@signature.text()}"
if params.type is 'twitter direct-message' if params.type is 'twitter direct-message'
App.Utils.htmlRemoveRichtext(@$('[data-name=body]')) rawHTML = @$('[data-name=body]').html()
cleanHTML = App.Utils.htmlRemoveRichtext(rawHTML)
if cleanHTML && cleanHTML.html() != rawHTML
@$('[data-name=body]').html(cleanHTML)
params.content_type = 'text/plain' params.content_type = 'text/plain'
params.body = "#{App.Utils.html2text(params.body, true)}\n#{@signature.text()}" params.body = "#{App.Utils.html2text(params.body, true)}\n#{@signature.text()}"
if params.type is 'facebook feed comment' if params.type is 'facebook feed comment'
App.Utils.htmlRemoveRichtext(@$('[data-name=body]')) rawHTML = @$('[data-name=body]').html()
cleanHTML = App.Utils.htmlRemoveRichtext(rawHTML)
if cleanHTML && cleanHTML.html() != rawHTML
@$('[data-name=body]').html(cleanHTML)
params.content_type = 'text/plain' params.content_type = 'text/plain'
params.body = App.Utils.html2text(params.body, true) params.body = App.Utils.html2text(params.body, true)
@ -438,10 +447,11 @@ class App.TicketZoomArticleNew extends App.Controller
@$('[data-name=body] [data-signature=true]').remove() @$('[data-name=body] [data-signature=true]').remove()
# remove richtext # remove richtext
if @type is 'twitter status' if @type is 'twitter status' || @type is 'twitter direct-message'
App.Utils.htmlRemoveRichtext(@$('[data-name=body]')) rawHTML = @$('[data-name=body]').html()
if @type is 'twitter direct-message' cleanHTML = App.Utils.htmlRemoveRichtext(rawHTML)
App.Utils.htmlRemoveRichtext(@$('[data-name=body]')) if cleanHTML && cleanHTML.html() != rawHTML
@$('[data-name=body]').html(cleanHTML)
# show/hide attributes/features # show/hide attributes/features
@maxTextLength = undefined @maxTextLength = undefined

View file

@ -183,11 +183,11 @@ class _trackSingleton
} }
window.onerrorOld = window.onerror window.onerrorOld = window.onerror
window.onerror = function(errorMsg, url, lineNumber) { window.onerror = function(errorMsg, url, lineNumber) {
console.error(errorMsg + " - in " + url + ", line " + lineNumber + "\n" + window.getStackTrace().join('\n')); console.error(errorMsg + " - in " + url + ", line " + lineNumber + "\n" + window.getStackTrace().join("\n"))
if (window.onerrorOld) { if (window.onerrorOld) {
window.onerrorOld(errorMsg, url, lineNumber) window.onerrorOld(errorMsg, url, lineNumber)
} }
return true return false
} }
var console = window.console var console = window.console

View file

@ -19,6 +19,7 @@ class App.Utils
# rawText = App.Utils.html2text(html, no_trim) # rawText = App.Utils.html2text(html, no_trim)
@html2text: (html, no_trim) -> @html2text: (html, no_trim) ->
return html if !html
if no_trim if no_trim
html = html html = html
@ -130,6 +131,8 @@ class App.Utils
# htmlOnlyWithRichtext = App.Utils.htmlRemoveRichtext(html) # htmlOnlyWithRichtext = App.Utils.htmlRemoveRichtext(html)
@htmlRemoveRichtext: (html) -> @htmlRemoveRichtext: (html) ->
return html if !html
html = @_checkTypeOf(html) html = @_checkTypeOf(html)
# remove comments # remove comments
@ -195,7 +198,6 @@ class App.Utils
@_checkTypeOf: (item) -> @_checkTypeOf: (item) ->
return item if typeof item isnt 'string' return item if typeof item isnt 'string'
return $(item) if item.substr(0,9) isnt '<!DOCTYPE' && item.substr(0,5) isnt '<html'
$("<div>#{item}</div>") $("<div>#{item}</div>")
@_removeAttributes: (html) -> @_removeAttributes: (html) ->

View file

@ -148,7 +148,8 @@
document.execCommand('RemoveFormat') document.execCommand('RemoveFormat')
} }
if (e.keyCode == 89) { if (e.keyCode == 89) {
App.Utils.htmlRemoveRichtext(_this.$element) var cleanHtml = App.Utils.htmlRemoveRichtext(_this.$element.html())
_this.$element.html(cleanHtml)
} }
if (e.keyCode == 90) { if (e.keyCode == 90) {
document.execCommand('insertHorizontalRule') document.execCommand('insertHorizontalRule')

View file

@ -305,10 +305,10 @@ test("htmlRemoveTags", function() {
equal(result.html(), should, source) equal(result.html(), should, source)
source = "<div><font size=\"3\" color=\"red\">This is some text!</font></div>" source = "<div><font size=\"3\" color=\"red\">This is some text!</font></div>"
//should = "<div>This is some text!</div>"
should = "This is some text!" should = "This is some text!"
result = App.Utils.htmlRemoveRichtext($(source)) result = App.Utils.htmlRemoveRichtext($(source))
equal(result.html(), should, source) equal(result.html(), should, source)
should = "<div>This is some text!</div>"
result = App.Utils.htmlRemoveRichtext(source) result = App.Utils.htmlRemoveRichtext(source)
equal(result.html(), should, source) equal(result.html(), should, source)
@ -398,16 +398,16 @@ test("htmlRemoveRichtext", function() {
source = "<div><div><label for=\"Ticket_888344_group_id\">Gruppe <span>*</span></label></div><div><div></div></div><div><div><span></span><span></span></div></div><div><div><label for=\"Ticket_888344_owner_id\">Besitzer <span></span></label></div><div><div></div></div></div><div><div><div><svg><use xlink:href=\"http://localhost:3000/assets/images/icons.svg#icon-arrow-down\"></use></svg></div><span></span><span></span></div></div><div><div> <label for=\"Ticket_888344_state_id\">Status <span>*</span></label></div></div></div>\n" source = "<div><div><label for=\"Ticket_888344_group_id\">Gruppe <span>*</span></label></div><div><div></div></div><div><div><span></span><span></span></div></div><div><div><label for=\"Ticket_888344_owner_id\">Besitzer <span></span></label></div><div><div></div></div></div><div><div><div><svg><use xlink:href=\"http://localhost:3000/assets/images/icons.svg#icon-arrow-down\"></use></svg></div><span></span><span></span></div></div><div><div> <label for=\"Ticket_888344_state_id\">Status <span>*</span></label></div></div></div>\n"
//should = "<div>test 123</div>" //should = "<div>test 123</div>"
should = '<div>Gruppe <span>*</span></div><div><div></div></div><div><div><span></span><span></span></div></div><div><div>Besitzer <span></span></div><div><div></div></div></div><div><div><div></div><span></span><span></span></div></div><div><div> Status <span>*</span></div></div>' should = '<div><div>Gruppe <span>*</span></div><div><div></div></div><div><div><span></span><span></span></div></div><div><div>Besitzer <span></span></div><div><div></div></div></div><div><div><div></div><span></span><span></span></div></div><div><div> Status <span>*</span></div></div></div>' + "\n"
result = App.Utils.htmlRemoveRichtext(source) result = App.Utils.htmlRemoveRichtext(source)
equal(result.html(), should, source) equal(result.html(), should, source)
source = "<div><font size=\"3\" color=\"red\">This is some text!</font><svg><use xlink:href=\"assets/images/icons.svg#icon-status\"></svg></div>" source = "<div><font size=\"3\" color=\"red\">This is some text!</font><svg><use xlink:href=\"assets/images/icons.svg#icon-status\"></svg></div>"
//should = "<div>This is some text!</div>"
should = "This is some text!" should = "This is some text!"
result = App.Utils.htmlRemoveRichtext($(source)) result = App.Utils.htmlRemoveRichtext($(source))
equal(result.html(), should, source) equal(result.html(), should, source)
should = "<div>This is some text!</div>"
result = App.Utils.htmlRemoveRichtext(source) result = App.Utils.htmlRemoveRichtext(source)
equal(result.html(), should, source) equal(result.html(), should, source)
@ -498,7 +498,7 @@ test("htmlCleanup", function() {
source = "<div><div><label for=\"Ticket_888344_group_id\">Gruppe <span>*</span></label></div><div><div></div></div><div><div><span></span><span></span></div></div><div><div><label for=\"Ticket_888344_owner_id\">Besitzer <span></span></label></div><div><div></div></div></div><div><div><div><svg><use xlink:href=\"http://localhost:3000/assets/images/icons.svg#icon-arrow-down\"></use></svg></div><span></span><span></span></div></div><div><div> <label for=\"Ticket_888344_state_id\">Status <span>*</span></label></div></div></div>\n" source = "<div><div><label for=\"Ticket_888344_group_id\">Gruppe <span>*</span></label></div><div><div></div></div><div><div><span></span><span></span></div></div><div><div><label for=\"Ticket_888344_owner_id\">Besitzer <span></span></label></div><div><div></div></div></div><div><div><div><svg><use xlink:href=\"http://localhost:3000/assets/images/icons.svg#icon-arrow-down\"></use></svg></div><span></span><span></span></div></div><div><div> <label for=\"Ticket_888344_state_id\">Status <span>*</span></label></div></div></div>\n"
//should = "<div>test 123</div>" //should = "<div>test 123</div>"
should = '<div>Gruppe <span>*</span></div><div><div></div></div><div><div><span></span><span></span></div></div><div><div>Besitzer <span></span></div><div><div></div></div></div><div><div><div></div><span></span><span></span></div></div><div><div> Status <span>*</span></div></div>' should = '<div><div>Gruppe <span>*</span></div><div><div></div></div><div><div><span></span><span></span></div></div><div><div>Besitzer <span></span></div><div><div></div></div></div><div><div><div></div><span></span><span></span></div></div><div><div> Status <span>*</span></div></div></div>' + "\n"
result = App.Utils.htmlCleanup(source) result = App.Utils.htmlCleanup(source)
equal(result.html(), should, source) equal(result.html(), should, source)