Paste text/html in IE

Change-Id: I9e9b400d9894e2689b86aaca8d0f66bf1f364b0e
This commit is contained in:
Szymon Kłos 2019-06-25 10:45:44 +02:00 committed by Michael Meeks
parent a9e698b1d0
commit c564af1614
3 changed files with 25 additions and 8 deletions

View file

@ -261,6 +261,14 @@ L.TileLayer = L.GridLayer.extend({
this._viewReset();
map.on('drag resize zoomend', this._updateScrollOffset, this);
if (window.isInternetExplorer) {
var tileLayer = this;
document.addEventListener('beforepaste', function() {
console.log('Before paste called !');
tileLayer._map._clipboardContainer.focus(true);
}, true);
}
map.on('copy', this._onCopy, this);
map.on('cut', this._onCut, this);
map.on('paste', this._onPaste, this);
@ -2649,19 +2657,16 @@ L.TileLayer = L.GridLayer.extend({
_onCopy: function (e) {
e = e.originalEvent;
e.preventDefault();
this._map._clip.copy(e, this._selectionType());
},
_onCut: function (e) {
e = e.originalEvent;
e.preventDefault();
this._map._clip.cut(e, this._selectionType());
},
_onPaste: function (e) {
e = e.originalEvent;
e.preventDefault();
this._map._clip.paste(e);
},

View file

@ -32,6 +32,10 @@ if (host === '' && !window.ThisIsAMobileApp) {
vex.dialog.alert(errorMessages.emptyhosturl);
}
var isInternetExplorer = (navigator.userAgent.toLowerCase().indexOf('msie') != -1
|| navigator.userAgent.toLowerCase().indexOf('trident') != -1);
global.isInternetExplorer = isInternetExplorer;
// loleaflet.js accesses these globals
// TODO: Get rid of these globals
global.closebutton = closebutton;

View file

@ -85,8 +85,8 @@ L.Clipboard = L.Class.extend({
var types = dataTransfer.types;
var data = null;
if (types == null) { // IE
data = dataTransfer.getData('text');
content.push('text/plain\n');
data = dataTransfer;
content.push('text/html\n');
content.push(data.length.toString(16) + '\n');
content.push(data);
content.push('\n');
@ -177,7 +177,7 @@ L.Clipboard = L.Class.extend({
var pasteHtml = null;
if (dataTransfer.types == null) { // IE
pasteHtml = dataTransfer.getData('text');
pasteHtml = dataTransfer;
} else {
pasteHtml = dataTransfer.getData('text/html');
}
@ -308,11 +308,13 @@ L.Clipboard = L.Class.extend({
copy: function(e,t) {
console.log('Copy');
e.preventDefault();
this.populateClipboard(e,t);
this._map._socket.sendMessage('uno .uno:Copy');
},
cut: function(e,t) {
e.preventDefault();
console.log('Cut');
this.populateClipboard(e,t);
this._map._socket.sendMessage('uno .uno:Cut');
@ -321,10 +323,16 @@ L.Clipboard = L.Class.extend({
paste: function(e) {
console.log('Paste');
if (e.clipboardData) { // Standard
e.preventDefault();
this.dataTransferToDocument(e.clipboardData, /* preferInternal = */ true);
}
else if (window.clipboardData) { // IE 11
this.dataTransferToDocument(window.clipboardData, /* preferInternal = */ true);
else { // IE 11
console.log('Scrape the content from the clipboard in a timeout!');
var map = this._map;
setTimeout(function() {
console.log('Do paste in timeout');
map._clip.dataTransferToDocument(map._clipboardContainer.getValue(), /* preferInternal = */ true);
}, 1);
}
},