Improved _checkTypeOf().
This commit is contained in:
parent
8f0b7c30a3
commit
4996f4a15f
2 changed files with 37 additions and 6 deletions
|
@ -132,7 +132,6 @@ class App.Utils
|
|||
# htmlOnlyWithRichtext = App.Utils.htmlRemoveRichtext(html)
|
||||
@htmlRemoveRichtext: (html) ->
|
||||
return html if !html
|
||||
|
||||
html = @_checkTypeOf(html)
|
||||
|
||||
# remove comments
|
||||
|
@ -156,6 +155,7 @@ class App.Utils
|
|||
|
||||
# cleanHtmlWithRichText = App.Utils.htmlCleanup(html)
|
||||
@htmlCleanup: (html) ->
|
||||
return html if !html
|
||||
html = @_checkTypeOf(html)
|
||||
|
||||
# remove comments
|
||||
|
@ -198,7 +198,21 @@ class App.Utils
|
|||
|
||||
@_checkTypeOf: (item) ->
|
||||
return item if typeof item isnt 'string'
|
||||
$("<div>#{item}</div>")
|
||||
|
||||
try
|
||||
result = $(item)
|
||||
|
||||
# if we have more then on element at first level
|
||||
if result.length > 1
|
||||
return $("<div>#{item}</div>")
|
||||
|
||||
# if we have just a text string without html markup
|
||||
if !result || !result.get(0)
|
||||
return $("<div>#{item}</div>")
|
||||
|
||||
return result
|
||||
catch err
|
||||
return $("<div>#{item}</div>")
|
||||
|
||||
@_removeAttributes: (html) ->
|
||||
html.find('*')
|
||||
|
@ -229,6 +243,7 @@ class App.Utils
|
|||
html
|
||||
|
||||
@_removeWordMarkup: (html) ->
|
||||
return html if !html.get(0)
|
||||
match = false
|
||||
htmlTmp = html.get(0).outerHTML
|
||||
regex = new RegExp('<(/w|w)\:[A-Za-z]')
|
||||
|
|
|
@ -313,7 +313,8 @@ test("htmlRemoveTags", function() {
|
|||
should = "This is some text!"
|
||||
result = App.Utils.htmlRemoveRichtext($(source))
|
||||
equal(result.html(), should, source)
|
||||
should = "<div>This is some text!</div>"
|
||||
|
||||
should = "This is some text!"
|
||||
result = App.Utils.htmlRemoveRichtext(source)
|
||||
equal(result.html(), should, source)
|
||||
|
||||
|
@ -403,7 +404,7 @@ 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"
|
||||
//should = "<div>test 123</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"
|
||||
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>'
|
||||
result = App.Utils.htmlRemoveRichtext(source)
|
||||
equal(result.html(), should, source)
|
||||
|
||||
|
@ -412,7 +413,7 @@ test("htmlRemoveRichtext", function() {
|
|||
result = App.Utils.htmlRemoveRichtext($(source))
|
||||
equal(result.html(), should, source)
|
||||
|
||||
should = "<div>This is some text!</div>"
|
||||
should = "This is some text!"
|
||||
result = App.Utils.htmlRemoveRichtext(source)
|
||||
equal(result.html(), should, source)
|
||||
|
||||
|
@ -427,6 +428,21 @@ test("htmlCleanup", function() {
|
|||
var result = App.Utils.htmlCleanup($(source))
|
||||
equal(result.html(), should, source)
|
||||
|
||||
source = "<div><!--test comment--><a href=\"test\">test</a></div>"
|
||||
should = "test"
|
||||
result = App.Utils.htmlCleanup(source)
|
||||
equal(result.html(), should, source)
|
||||
|
||||
source = "some link to somewhere"
|
||||
should = "some link to somewhere"
|
||||
result = App.Utils.htmlCleanup(source)
|
||||
equal(result.html(), should, source)
|
||||
|
||||
source = "<li>a</li><li>b</li>"
|
||||
should = "<li>a</li><li>b</li>"
|
||||
result = App.Utils.htmlCleanup(source)
|
||||
equal(result.html(), should, source)
|
||||
|
||||
source = "<a href=\"some_link\">some link to somewhere</a>"
|
||||
should = "some link to somewhere"
|
||||
result = App.Utils.htmlCleanup($(source))
|
||||
|
@ -503,7 +519,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"
|
||||
//should = "<div>test 123</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"
|
||||
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>'
|
||||
result = App.Utils.htmlCleanup(source)
|
||||
equal(result.html(), should, source)
|
||||
|
||||
|
|
Loading…
Reference in a new issue