Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clipboard [Firefox version < 50] #6280

Merged
merged 3 commits into from
Mar 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 42 additions & 4 deletions packages/rocketchat-ui-message/client/messageBox.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,45 @@ Template.messageBox.helpers
showSandstorm: ->
return Meteor.settings.public.sandstorm && !Meteor.isCordova

firefoxPasteUpload = (fn) ->
user = navigator.userAgent.match(/Firefox\/(\d+)\.\d/)
if !user or user[1] > 49
return fn
return (event, instance) ->
if (event.originalEvent.ctrlKey or event.originalEvent.metaKey) and (event.keyCode == 86)
textarea = instance.find("textarea")
selectionStart = textarea.selectionStart
selectionEnd = textarea.selectionEnd
contentEditableDiv = instance.find('#msg_contenteditable')
contentEditableDiv.focus()
Meteor.setTimeout ->
pastedImg = contentEditableDiv.querySelector 'img'
textareaContent = textarea.value
startContent = textareaContent.substring(0, selectionStart)
endContent = textareaContent.substring(selectionEnd)
restoreSelection = (pastedText) ->
textarea.value = startContent + pastedText + endContent
textarea.selectionStart = selectionStart + pastedText.length
textarea.selectionEnd = textarea.selectionStart
contentEditableDiv.innerHTML = '' if pastedImg
textarea.focus
return if (!pastedImg || contentEditableDiv.innerHTML.length > 0)
[].slice.call(contentEditableDiv.querySelectorAll("br")).forEach (el) ->
contentEditableDiv.replaceChild(new Text("\n") , el)
restoreSelection(contentEditableDiv.innerText)
imageSrc = pastedImg.getAttribute("src")
if imageSrc.match(/^data:image/)
fetch(imageSrc)
.then((img)->
return img.blob())
.then (blob)->
fileUpload [{
file: blob
name: 'Clipboard'
}]
, 150
fn?.apply @, arguments


Template.messageBox.events
'click .join': (event) ->
Expand Down Expand Up @@ -157,7 +196,6 @@ Template.messageBox.events

if not e.originalEvent.clipboardData?
return

items = e.originalEvent.clipboardData.items
files = []
for item in items
Expand All @@ -172,8 +210,8 @@ Template.messageBox.events
else
instance.isMessageFieldEmpty.set(false)

'keydown .input-message': (event) ->
chatMessages[@_id].keydown(@_id, event, Template.instance())
'keydown .input-message': firefoxPasteUpload((event, instance) ->
chatMessages[@_id].keydown(@_id, event, Template.instance()))

'input .input-message': (event) ->
chatMessages[@_id].valueChanged(@_id, event, Template.instance())
Expand Down Expand Up @@ -318,4 +356,4 @@ Meteor.startup ->

navigator.geolocation.watchPosition success, error
else
RocketChat.Geolocation.set false
RocketChat.Geolocation.set false
1 change: 1 addition & 0 deletions packages/rocketchat-ui-message/client/messageBox.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{{#if allowedToSend}}
<div class="message-input border-component-color">
<div class="input-message-container content-background-color">
<div id="msg_contenteditable" contenteditable="true" style="height: 0; width: 0; overflow: hidden"></div>
<textarea dir="auto" name="msg" maxlength="{{maxMessageLength}}" class="message-form-text input-message autogrow-short" placeholder="{{_ 'Message'}}"></textarea>

<div class="inner-left-toolbar">
Expand Down