Skip to content

Commit

Permalink
Merge pull request #365 from RocketChat/paste-images
Browse files Browse the repository at this point in the history
Allow to paste images from clipboard
  • Loading branch information
engelgabriel committed Jul 29, 2015
2 parents 6d949ef + 8aec301 commit d66cd22
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions client/views/app/room.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,26 @@ Template.room.events
'keyup .input-message': (event) ->
ChatMessages.keyup(@_id, event, Template.instance())

'paste .input-message': (e) ->
if not e.originalEvent.clipboardData?
return

items = e.originalEvent.clipboardData.items
for item in items
if item.kind is 'file' and item.type.indexOf('image/') isnt -1
e.preventDefault()

blob = item.getAsFile()

newFile = new (FS.File)(blob)
newFile.name('Clipboard')
newFile.rid = Session.get('openedRoom')
newFile.recId = Random.id()
newFile.userId = Meteor.userId()
Files.insert newFile, (error, fileObj) ->
unless error
toastr.success 'Upload from clipboard succeeded!'

'keydown .input-message': (event) ->
ChatMessages.keydown(@_id, event, Template.instance())

Expand Down

0 comments on commit d66cd22

Please sign in to comment.