loleaflet/src/map/handler/Map.FileInserter.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-)
New commits: commit af1bc0bfa5bc1af85d9c457e3b09537973d8a384 Author: Tor Lillqvist <t...@collabora.com> AuthorDate: Thu Nov 29 11:26:53 2018 +0200 Commit: Tor Lillqvist <t...@collabora.com> CommitDate: Thu Nov 29 11:29:45 2018 +0200 Implement JavaScript parts of inserting an image in a mobile app We must read the image file contents using a FileReader and then pass on the data to the Online code in a message. Re-use the same "insertfile" message used in web-based Online, but add a "data" parameter that contains the base64-encoded image file contents. Change-Id: I95c5668ac8da9d03dbcf19a921e5fba045d7a94f diff --git a/loleaflet/src/map/handler/Map.FileInserter.js b/loleaflet/src/map/handler/Map.FileInserter.js index c11c23350..63c94a63e 100644 --- a/loleaflet/src/map/handler/Map.FileInserter.js +++ b/loleaflet/src/map/handler/Map.FileInserter.js @@ -3,7 +3,7 @@ * L.Map.FileInserter is handling the fileInserter action */ -/* global _ */ +/* global _ Uint8Array */ L.Map.mergeOptions({ fileInserter: true @@ -76,7 +76,26 @@ L.Map.FileInserter = L.Handler.extend({ var socket = this._map._socket; var map = this._map; if (window.ThisIsAMobileApp) { - console.log('FIXME: image insertion in mobile app'); + // Pass the file contents as a base64-encoded parameter in an insertfile message + var reader = new FileReader(); + reader.onload = (function(aFile) { + return function(e) { + var byteBuffer = new Uint8Array(e.target.result); + var strBytes = ''; + for (var i = 0; i < byteBuffer.length; i++) { + strBytes += String.fromCharCode(byteBuffer[i]); + } + window.webkit.messageHandlers.lool.postMessage('insertfile name=' + aFile.name + ' type=graphic' + + ' data=' + window.btoa(strBytes)); + }; + })(file); + reader.onerror = function(e) { + window.webkit.messageHandlers.error.postMessage('Error when reading file: ' + e); + }; + reader.onprogress = function(e) { + window.webkit.messageHandlers.debug.postMessage('FileReader progress: ' + Math.round(e.loaded*100 / e.total) + '%'); + }; + reader.readAsArrayBuffer(file); } else { var xmlHttp = new XMLHttpRequest(); this._map.showBusy(_('Uploading...'), false); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits