Browse Source

Paste from clipboard in Firefox

master
Haktrum 11 years ago
parent
commit
a30af8bce4
  1. 27
      app/js/directives.js

27
app/js/directives.js

@ -438,6 +438,7 @@ angular.module('myApp.directives', ['myApp.filters'])
$('body').on('dragenter dragleave dragover drop', onDragDropEvent); $('body').on('dragenter dragleave dragover drop', onDragDropEvent);
$(document).on('paste', onPasteEvent); $(document).on('paste', onPasteEvent);
$('.emoji-wysiwyg-editor.form-control').bind('DOMNodeInserted', onPastedImageEvent);
scope.$on('ui_peer_change', focusField); scope.$on('ui_peer_change', focusField);
scope.$on('ui_history_focus', focusField); scope.$on('ui_history_focus', focusField);
@ -450,6 +451,7 @@ angular.module('myApp.directives', ['myApp.filters'])
scope.$on('$destroy', function cleanup() { scope.$on('$destroy', function cleanup() {
$('body').off('dragenter dragleave dragover drop', onDragDropEvent); $('body').off('dragenter dragleave dragover drop', onDragDropEvent);
$(document).off('paste', onPasteEvent); $(document).off('paste', onPasteEvent);
$('.emoji-wysiwyg-editor.form-control').unbind('DOMNodeInserted', onPastedImageEvent);
}); });
focusField(); 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) { function onPasteEvent (e) {
var cData = (e.originalEvent || e).clipboardData, var cData = (e.originalEvent || e).clipboardData,
items = cData && cData.items || [], items = cData && cData.items || [],

Loading…
Cancel
Save