From a30af8bce4b69a023cc0ad7683065bbeed363b7e Mon Sep 17 00:00:00 2001 From: Haktrum Date: Mon, 10 Mar 2014 03:20:55 -0300 Subject: [PATCH] Paste from clipboard in Firefox --- app/js/directives.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/app/js/directives.js b/app/js/directives.js index e49ad249..3e3e7e4f 100644 --- a/app/js/directives.js +++ b/app/js/directives.js @@ -438,6 +438,7 @@ angular.module('myApp.directives', ['myApp.filters']) $('body').on('dragenter dragleave dragover drop', onDragDropEvent); $(document).on('paste', onPasteEvent); + $('.emoji-wysiwyg-editor.form-control').bind('DOMNodeInserted', onPastedImageEvent); scope.$on('ui_peer_change', focusField); scope.$on('ui_history_focus', focusField); @@ -450,6 +451,7 @@ angular.module('myApp.directives', ['myApp.filters']) scope.$on('$destroy', function cleanup() { $('body').off('dragenter dragleave dragover drop', onDragDropEvent); $(document).off('paste', onPasteEvent); + $('.emoji-wysiwyg-editor.form-control').unbind('DOMNodeInserted', onPastedImageEvent); }); focusField(); @@ -460,6 +462,31 @@ angular.module('myApp.directives', ['myApp.filters']) }); } + function onPastedImageEvent (e) { + var element = e && e.target; + var src; + if (element && (src = element.src) && src.indexOf('data') === 0) { + element.parentNode.removeChild(element); + src = src.substr(5).split(';'); + var contentType = src[0]; + var base64 = atob(src[1].split(',')[1]); + var array = new Uint8Array(base64.length); + + for (var i = 0; i < base64.length; i++) { + array[i] = base64.charCodeAt(i); + } + + var blob = new Blob([array], {type: contentType}); + + if (safeConfirm('Are you sure to send file(s) from clipboard?')) { + scope.$apply(function () { + scope.draftMessage.files = [blob]; + scope.draftMessage.isMedia = true; + }); + } + } + }; + function onPasteEvent (e) { var cData = (e.originalEvent || e).clipboardData, items = cData && cData.items || [],