Improved reply of twitter status, set cursor to end of input field.

This commit is contained in:
Martin Edenhofer 2016-10-30 01:08:28 +02:00
parent 7cbe4f9da1
commit f3cc078cb3
3 changed files with 39 additions and 31 deletions

View file

@ -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()

View file

@ -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 && "<div>#{cleanHTML.html()}</div>" 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 && "<div>#{cleanHTML.html()}</div>" 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 && "<div>#{cleanHTML.html()}</div>" 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)

View file

@ -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 $("<div>#{item}</div>")
@_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')