diff --git a/app/assets/javascripts/app/controllers/ticket_zoom/article_actions.coffee b/app/assets/javascripts/app/controllers/ticket_zoom/article_actions.coffee
index 4a552ac44..bc8987d6a 100644
--- a/app/assets/javascripts/app/controllers/ticket_zoom/article_actions.coffee
+++ b/app/assets/javascripts/app/controllers/ticket_zoom/article_actions.coffee
@@ -240,7 +240,7 @@ class App.TicketZoomArticleActions extends App.Controller
else
articleNew.body = "#{recipientString} "
- App.Event.trigger('ui::ticket::setArticleType', { ticket: @ticket, type: type, article: articleNew } )
+ App.Event.trigger('ui::ticket::setArticleType', { ticket: @ticket, type: type, article: articleNew, position: 'end' } )
twitterDirectMessageReply: (e) =>
e.preventDefault()
diff --git a/app/assets/javascripts/app/controllers/ticket_zoom/article_new.coffee b/app/assets/javascripts/app/controllers/ticket_zoom/article_new.coffee
index 0979968e6..e769a72fe 100644
--- a/app/assets/javascripts/app/controllers/ticket_zoom/article_new.coffee
+++ b/app/assets/javascripts/app/controllers/ticket_zoom/article_new.coffee
@@ -141,6 +141,11 @@ class App.TicketZoomArticleNew extends App.Controller
# preselect article type
@setArticleType(data.type.name)
+ # set focus at end of field
+ if data.position is 'end'
+ @placeCaretAtEnd(@textarea.get(0))
+ return
+
# set focus into field
@textarea.focus()
)
@@ -158,6 +163,22 @@ class App.TicketZoomArticleNew extends App.Controller
@render()
)
+ placeCaretAtEnd: (el) ->
+ el.focus()
+ if typeof window.getSelection isnt 'undefined' && typeof document.createRange isnt 'undefined'
+ range = document.createRange()
+ range.selectNodeContents(el)
+ range.collapse(false)
+ sel = window.getSelection()
+ sel.removeAllRanges()
+ sel.addRange(range)
+ return
+ if typeof document.body.createTextRange isnt 'undefined'
+ textRange = document.body.createTextRange()
+ textRange.moveToElementText(el)
+ textRange.collapse(false)
+ textRange.select()
+
isIE10: ->
Function('/*@cc_on return document.documentMode===10@*/')()
@@ -293,32 +314,17 @@ class App.TicketZoomArticleNew extends App.Controller
params.type_id = type.id
if params.type is 'twitter status'
- rawHTML = @$('[data-name=body]').html()
- cleanHTML = App.Utils.htmlRemoveRichtext(rawHTML)
-
- # if markup is included, strip it out
- if cleanHTML && cleanHTML.html() isnt rawHTML && "
#{cleanHTML.html()}
" isnt rawHTML
- @$('[data-name=body]').html(cleanHTML)
+ App.Utils.htmlRemoveRichtext(@$('[data-name=body]'), false)
params.content_type = 'text/plain'
params.body = "#{App.Utils.html2text(params.body, true)}\n#{@signature.text()}"
if params.type is 'twitter direct-message'
- rawHTML = @$('[data-name=body]').html()
- cleanHTML = App.Utils.htmlRemoveRichtext(rawHTML)
-
- # if markup is included, strip it out
- if cleanHTML && cleanHTML.html() isnt rawHTML && "#{cleanHTML.html()}
" isnt rawHTML
- @$('[data-name=body]').html(cleanHTML)
+ App.Utils.htmlRemoveRichtext(@$('[data-name=body]'), false)
params.content_type = 'text/plain'
params.body = "#{App.Utils.html2text(params.body, true)}\n#{@signature.text()}"
if params.type is 'facebook feed comment'
- rawHTML = @$('[data-name=body]').html()
- cleanHTML = App.Utils.htmlRemoveRichtext(rawHTML)
-
- # if markup is included, strip it out
- if cleanHTML && cleanHTML.html() isnt rawHTML && "#{cleanHTML.html()}
" isnt rawHTML
- @$('[data-name=body]').html(cleanHTML)
+ App.Utils.htmlRemoveRichtext(@$('[data-name=body]'), false)
params.content_type = 'text/plain'
params.body = App.Utils.html2text(params.body, true)
diff --git a/app/assets/javascripts/app/lib/app_post/utils.coffee b/app/assets/javascripts/app/lib/app_post/utils.coffee
index e1bc97808..0fc24917e 100644
--- a/app/assets/javascripts/app/lib/app_post/utils.coffee
+++ b/app/assets/javascripts/app/lib/app_post/utils.coffee
@@ -157,7 +157,7 @@ class App.Utils
html
# htmlOnlyWithRichtext = App.Utils.htmlRemoveRichtext(html)
- @htmlRemoveRichtext: (html) ->
+ @htmlRemoveRichtext: (html, parent = true) ->
return html if !html
html = @_checkTypeOf(html)
@@ -165,7 +165,8 @@ class App.Utils
@_removeComments(html)
# remove style and class
- @_removeAttributes(html)
+ if parent
+ @_removeAttributes(html)
# remove work markup
@_removeWordMarkup(html)
@@ -241,16 +242,17 @@ class App.Utils
catch err
return $("#{item}
")
- @_removeAttributes: (html) ->
- html.find('*')
- .removeAttr('style')
- .removeAttr('class')
- .removeAttr('title')
- .removeAttr('lang')
- .removeAttr('type')
- .removeAttr('id')
- .removeAttr('wrap')
- .removeAttrs(/data-/)
+ @_removeAttributes: (html, parent = true) ->
+ if parent
+ html.find('*')
+ .removeAttr('style')
+ .removeAttr('class')
+ .removeAttr('title')
+ .removeAttr('lang')
+ .removeAttr('type')
+ .removeAttr('id')
+ .removeAttr('wrap')
+ .removeAttrs(/data-/)
html
.removeAttr('style')
.removeAttr('class')