2018-07-24 07:53:26 -05:00
|
|
|
/* -*- js-indent-level: 8 -*- */
|
2018-04-12 14:57:00 -05:00
|
|
|
(function (global) {
|
|
|
|
|
2020-01-07 12:04:14 -06:00
|
|
|
document.addEventListener('contextmenu', function(e) {
|
|
|
|
if (e.preventDefault) {
|
|
|
|
e.preventDefault();
|
|
|
|
} else {
|
|
|
|
e.returnValue = false;
|
|
|
|
}
|
|
|
|
}, false);
|
|
|
|
|
2019-03-06 05:32:59 -06:00
|
|
|
global.fakeWebSocketCounter = 0;
|
|
|
|
global.FakeWebSocket = function () {
|
|
|
|
this.binaryType = 'arraybuffer';
|
|
|
|
this.bufferedAmount = 0;
|
|
|
|
this.extensions = '';
|
|
|
|
this.protocol = '';
|
|
|
|
this.readyState = 1;
|
|
|
|
this.id = window.fakeWebSocketCounter++;
|
|
|
|
this.sendCounter = 0;
|
|
|
|
this.onclose = function() {
|
|
|
|
};
|
|
|
|
this.onerror = function() {
|
|
|
|
};
|
|
|
|
this.onmessage = function() {
|
|
|
|
};
|
|
|
|
this.onopen = function() {
|
|
|
|
};
|
2020-01-16 08:44:23 -06:00
|
|
|
};
|
2019-03-06 05:32:59 -06:00
|
|
|
|
|
|
|
global.FakeWebSocket.prototype.close = function() {
|
2020-01-16 08:44:23 -06:00
|
|
|
};
|
2019-03-06 05:32:59 -06:00
|
|
|
|
|
|
|
global.FakeWebSocket.prototype.send = function(data) {
|
|
|
|
this.sendCounter++;
|
|
|
|
window.postMobileMessage(data);
|
2020-01-16 08:44:23 -06:00
|
|
|
};
|
2019-03-06 05:32:59 -06:00
|
|
|
|
2019-01-26 15:21:48 -06:00
|
|
|
// If not debug, don't print anything on the console
|
|
|
|
// except in tile debug mode (Ctrl-Shift-Alt-d)
|
|
|
|
console.log2 = console.log;
|
|
|
|
if (global.loleafletLogging !== 'true') {
|
|
|
|
var methods = ['warn', 'info', 'debug', 'trace', 'log', 'assert', 'time', 'timeEnd'];
|
|
|
|
for (var i = 0; i < methods.length; i++) {
|
|
|
|
console[methods[i]] = function() {};
|
|
|
|
}
|
2019-07-01 19:25:10 -05:00
|
|
|
} else {
|
|
|
|
window.onerror = function (msg, src, row, col, err) {
|
|
|
|
var data = {
|
|
|
|
userAgent: navigator.userAgent.toLowerCase(),
|
|
|
|
vendor: navigator.vendor.toLowerCase(),
|
|
|
|
message: msg,
|
|
|
|
source: src,
|
|
|
|
line: row,
|
|
|
|
column: col
|
2019-12-10 15:05:13 -06:00
|
|
|
};
|
|
|
|
var desc = err ? err.message || {}: {}, stack = err ? err.stack || {}: {};
|
2019-07-01 19:25:10 -05:00
|
|
|
var log = 'jserror ' + JSON.stringify(data, null, 2) + '\n' + desc + '\n' + stack + '\n';
|
2019-10-31 03:03:47 -05:00
|
|
|
if (window.ThisIsAMobileApp) {
|
|
|
|
window.postMobileError(log);
|
|
|
|
} else if (global.socket && (global.socket instanceof WebSocket) && global.socket.readyState === 1) {
|
2019-07-01 19:25:10 -05:00
|
|
|
global.socket.send(log);
|
|
|
|
} else if (global.socket && (global.socket instanceof global.L.Socket) && global.socket.connected()) {
|
|
|
|
global.socket.sendMessage(log);
|
|
|
|
} else {
|
|
|
|
var req = new XMLHttpRequest();
|
|
|
|
var url = global.location.protocol + '//' + global.location.host + global.location.pathname.match(/.*\//) + 'logging.html';
|
|
|
|
req.open('POST', url, true);
|
|
|
|
req.setRequestHeader('Content-type','application/json; charset=utf-8');
|
|
|
|
req.send(log);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2020-01-16 08:44:23 -06:00
|
|
|
};
|
2018-04-12 14:57:00 -05:00
|
|
|
}
|
|
|
|
|
2019-03-20 03:44:39 -05:00
|
|
|
// fix jquery-ui
|
|
|
|
// var jQuery = require('jquery');
|
|
|
|
global.require = function (path) {
|
|
|
|
if (path=='jquery') {
|
|
|
|
return global.jQuery;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-01-26 15:21:48 -06:00
|
|
|
global.getParameterByName = function (name) {
|
|
|
|
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
|
|
|
|
var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
|
|
|
|
var results = regex.exec(location.search);
|
|
|
|
return results === null ? '' : results[1].replace(/\+/g, ' ');
|
|
|
|
};
|
2018-04-12 14:57:00 -05:00
|
|
|
|
2019-03-15 11:23:28 -05:00
|
|
|
global._ = function (string) {
|
|
|
|
// In the mobile app case we can't use the stuff from l10n-for-node, as that assumes HTTP.
|
2019-12-11 04:46:52 -06:00
|
|
|
if (window.ThisIsAMobileApp) {
|
2019-01-26 15:21:48 -06:00
|
|
|
// We use another approach just for iOS for now.
|
2019-12-19 07:49:59 -06:00
|
|
|
if (window.LOCALIZATIONS && window.LOCALIZATIONS.hasOwnProperty(string)) {
|
2019-01-26 15:21:48 -06:00
|
|
|
// window.postMobileDebug('_(' + string + '): YES: ' + window.LOCALIZATIONS[string]);
|
|
|
|
var result = window.LOCALIZATIONS[string];
|
|
|
|
if (window.LANG === 'de-CH') {
|
|
|
|
result = result.replace(/ß/g, 'ss');
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
} else {
|
|
|
|
// window.postMobileDebug('_(' + string + '): NO');
|
|
|
|
return string;
|
2018-11-15 16:38:40 -06:00
|
|
|
}
|
2019-03-15 11:23:28 -05:00
|
|
|
} else {
|
|
|
|
return string.toLocaleString();
|
2018-11-09 14:28:46 -06:00
|
|
|
}
|
2019-03-15 11:23:28 -05:00
|
|
|
};
|
2018-04-12 14:57:00 -05:00
|
|
|
|
2019-01-27 12:04:26 -06:00
|
|
|
var docParams, wopiParams;
|
|
|
|
var filePath = global.getParameterByName('file_path');
|
|
|
|
var wopiSrc = global.getParameterByName('WOPISrc');
|
|
|
|
if (wopiSrc != '') {
|
|
|
|
global.docURL = decodeURIComponent(wopiSrc);
|
2019-03-12 13:56:11 -05:00
|
|
|
wopiSrc = '?WOPISrc=' + wopiSrc + '&compat=/ws';
|
2019-01-27 12:04:26 -06:00
|
|
|
if (global.accessToken !== '') {
|
|
|
|
wopiParams = { 'access_token': global.accessToken, 'access_token_ttl': global.accessTokenTTL };
|
|
|
|
}
|
|
|
|
else if (global.accessHeader !== '') {
|
|
|
|
wopiParams = { 'access_header': global.accessHeader };
|
|
|
|
}
|
|
|
|
docParams = Object.keys(wopiParams).map(function(key) {
|
2020-01-16 08:44:23 -06:00
|
|
|
return encodeURIComponent(key) + '=' + encodeURIComponent(wopiParams[key]);
|
2019-01-27 12:04:26 -06:00
|
|
|
}).join('&');
|
|
|
|
} else {
|
|
|
|
global.docURL = filePath;
|
|
|
|
}
|
|
|
|
|
2019-03-06 05:32:59 -06:00
|
|
|
if (window.ThisIsAMobileApp) {
|
|
|
|
global.socket = new global.FakeWebSocket();
|
|
|
|
window.TheFakeWebSocket = global.socket;
|
|
|
|
} else {
|
|
|
|
var websocketURI = global.host + global.serviceRoot + '/lool/' + encodeURIComponent(global.docURL + (docParams ? '?' + docParams : '')) + '/ws' + wopiSrc;
|
2019-01-27 12:04:26 -06:00
|
|
|
|
2019-03-06 05:32:59 -06:00
|
|
|
try {
|
|
|
|
global.socket = new WebSocket(websocketURI);
|
|
|
|
} catch (err) {
|
|
|
|
console.log(err);
|
|
|
|
}
|
2019-01-27 12:04:26 -06:00
|
|
|
}
|
|
|
|
|
2019-11-12 12:49:19 -06:00
|
|
|
var lang = global.getParameterByName('lang');
|
2019-03-07 12:02:15 -06:00
|
|
|
global.queueMsg = [];
|
2019-12-11 04:46:52 -06:00
|
|
|
if (window.ThisIsAMobileApp)
|
2019-11-12 12:49:19 -06:00
|
|
|
window.LANG = lang;
|
2019-01-27 12:04:26 -06:00
|
|
|
if (global.socket && global.socket.readyState !== 3) {
|
|
|
|
global.socket.onopen = function () {
|
|
|
|
if (global.socket.readyState === 1) {
|
|
|
|
var ProtocolVersionNumber = '0.1';
|
2019-11-12 12:49:19 -06:00
|
|
|
var timestamp = global.getParameterByName('timestamp');
|
|
|
|
var msg = 'load url=' + encodeURIComponent(global.docURL);
|
|
|
|
|
2019-01-27 12:04:26 -06:00
|
|
|
global.socket.send('loolclient ' + ProtocolVersionNumber);
|
2019-11-12 12:49:19 -06:00
|
|
|
|
2019-12-11 04:46:52 -06:00
|
|
|
if (window.ThisIsAMobileApp) {
|
2019-11-12 12:49:19 -06:00
|
|
|
msg += ' lang=' + window.LANG;
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (timestamp) {
|
|
|
|
msg += ' timestamp=' + timestamp;
|
|
|
|
}
|
|
|
|
if (lang) {
|
|
|
|
msg += ' lang=' + lang;
|
|
|
|
}
|
|
|
|
// renderingOptions?
|
|
|
|
}
|
|
|
|
global.socket.send(msg);
|
2019-01-27 12:04:26 -06:00
|
|
|
}
|
2020-01-16 08:44:23 -06:00
|
|
|
};
|
2019-01-27 12:04:26 -06:00
|
|
|
|
|
|
|
global.socket.onerror = function (event) {
|
|
|
|
console.log(event);
|
2020-01-16 08:44:23 -06:00
|
|
|
};
|
2019-01-27 12:04:26 -06:00
|
|
|
|
|
|
|
global.socket.onclose = function (event) {
|
|
|
|
console.log(event);
|
2020-01-16 08:44:23 -06:00
|
|
|
};
|
2019-01-27 12:04:26 -06:00
|
|
|
|
|
|
|
global.socket.onmessage = function (event) {
|
2019-06-19 02:48:54 -05:00
|
|
|
if (typeof global.socket._onMessage === 'function') {
|
2019-03-07 12:02:15 -06:00
|
|
|
global.socket._onMessage(event);
|
|
|
|
} else {
|
|
|
|
global.queueMsg.push(event.data);
|
|
|
|
}
|
2020-01-16 08:44:23 -06:00
|
|
|
};
|
2019-01-27 12:04:26 -06:00
|
|
|
|
|
|
|
global.socket.binaryType = 'arraybuffer';
|
2019-03-06 07:29:17 -06:00
|
|
|
|
|
|
|
if (window.ThisIsAMobileApp) {
|
|
|
|
// This corresponds to the initial GET request when creating a WebSocket
|
|
|
|
// connection and tells the app's code that it is OK to start invoking
|
|
|
|
// TheFakeWebSocket's onmessage handler. The app code that handles this
|
|
|
|
// special message knows the document to be edited anyway, and can send it
|
|
|
|
// on as necessary to the Online code.
|
|
|
|
window.postMobileMessage('HULLO');
|
|
|
|
// A FakeWebSocket is immediately open.
|
|
|
|
this.socket.onopen();
|
|
|
|
}
|
2019-01-27 12:04:26 -06:00
|
|
|
}
|
2018-04-12 14:57:00 -05:00
|
|
|
}(window));
|