2018-07-24 07:53:26 -05:00
|
|
|
/* -*- js-indent-level: 8 -*- */
|
2018-04-12 14:57:00 -05:00
|
|
|
(function (global) {
|
|
|
|
|
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() {
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
global.FakeWebSocket.prototype.close = function() {
|
|
|
|
}
|
|
|
|
|
|
|
|
global.FakeWebSocket.prototype.send = function(data) {
|
|
|
|
this.sendCounter++;
|
|
|
|
window.postMobileMessage(data);
|
|
|
|
}
|
|
|
|
|
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() {};
|
|
|
|
}
|
2018-04-12 14:57:00 -05:00
|
|
|
}
|
|
|
|
|
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-02-10 17:15:25 -06:00
|
|
|
var lang = self.getParameterByName('lang');
|
|
|
|
if (lang) {
|
|
|
|
String.locale = lang;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
String.locale = 'en';
|
|
|
|
}
|
|
|
|
|
2019-03-06 06:17:53 -06:00
|
|
|
// In the mobile app case we don't use any "server-side" localisation. For real Online, what
|
|
|
|
// looks like calls to a _ function are in fact replaced by Online's file server with the
|
|
|
|
// translation.
|
|
|
|
if (window.ThisIsTheiOSApp) {
|
|
|
|
global._ = function (string) {
|
2019-01-26 15:21:48 -06:00
|
|
|
// We use another approach just for iOS for now.
|
|
|
|
if (window.LOCALIZATIONS.hasOwnProperty(string)) {
|
|
|
|
// 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-06 06:17:53 -06:00
|
|
|
}
|
|
|
|
} else if (window.ThisIsAMobileApp) {
|
|
|
|
// Bail out without translations on other mobile platforms for now.
|
|
|
|
global._ = function (string) {
|
2018-11-09 14:28:46 -06:00
|
|
|
return string;
|
|
|
|
}
|
2019-03-06 06:17:53 -06: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 != '') {
|
|
|
|
wopiSrc = '?WOPISrc=' + wopiSrc + '&compat=/ws';
|
|
|
|
global.docURL = decodeURIComponent(wopiSrc);
|
|
|
|
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) {
|
|
|
|
return encodeURIComponent(key) + '=' + encodeURIComponent(wopiParams[key])
|
|
|
|
}).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
|
|
|
}
|
|
|
|
|
|
|
|
if (global.socket && global.socket.readyState !== 3) {
|
|
|
|
global.queueMsg = [];
|
|
|
|
|
|
|
|
global.socket.onopen = function () {
|
|
|
|
if (global.socket.readyState === 1) {
|
|
|
|
var ProtocolVersionNumber = '0.1';
|
|
|
|
global.socket.send('loolclient ' + ProtocolVersionNumber);
|
|
|
|
global.socket.send('load url=' + encodeURIComponent(global.docURL));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
global.socket.onerror = function (event) {
|
|
|
|
console.log(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
global.socket.onclose = function (event) {
|
|
|
|
console.log(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
global.socket.onmessage = function (event) {
|
|
|
|
global.queueMsg.push(event.data);
|
|
|
|
}
|
|
|
|
|
|
|
|
global.socket.binaryType = 'arraybuffer';
|
|
|
|
}
|
2018-04-12 14:57:00 -05:00
|
|
|
}(window));
|