libreoffice-online/browser/welcome/welcome.js
Andras Timar a88738e22d Fix fallback welcome dialog on phone + other backports from online welcome dialog
Signed-off-by: Andras Timar <andras.timar@collabora.com>
Change-Id: Ifdf373c2c0b5a0962610d5fcb35f5845603a7a03
2022-04-12 14:08:39 +03:00

89 lines
2.6 KiB
JavaScript

window.onload = onLoaded;
function onLoaded() {
window.addEventListener('message', onMessage, false);
document.getElementById('welcome-close').onclick = function() {
onClose();
}
document.getElementById('slide-1-button').onclick = function() {
onSlideClick('slide-2-indicator', true);
};
document.getElementById('slide-2-button').onclick = function() {
onSlideClick('slide-3-indicator', true);
};
document.getElementById('slide-3-button').onclick = function() {
onClose();
};
document.getElementById('slide-1-indicator').onclick = function() {
onSlideClick('slide-1-indicator');
};
document.getElementById('slide-2-indicator').onclick = function() {
onSlideClick('slide-2-indicator');
};
document.getElementById('slide-3-indicator').onclick = function() {
onSlideClick('slide-3-indicator');
};
if (window.parent !== window.self) {
var message = {
MessageId: 'welcome-translate',
strings: {}
};
getTranslatable(document.body, message.strings);
window.parent.postMessage(JSON.stringify(message), '*');
}
}
function onClose() {
if (window.parent !== window.self) {
window.parent.postMessage('{"MessageId":"welcome-close"}', '*');
}
}
function onSlideClick(e, isButton = false) {
for (var i = 1; i < 4; i++)
document.getElementById('slide-' + i + '-indicator').classList.remove("active");
document.getElementById(e).classList.add("active");
if (isButton)
document.location = '#' + e.replace('-indicator', '');
}
function onMessage(e) {
try {
var msg = JSON.parse(e.data);
if (window.parent !== window.self && msg.MessageId === 'welcome-translate') {
setTranslatable(document.body, msg.strings);
window.parent.postMessage('{"MessageId":"welcome-show"}', '*');
}
} catch (err) {
return;
}
}
function getTranslatable(root, strings) {
var children = root.children;
for (var i = 0; i < children.length; ++i) {
if (children[i].dataset.translate === 'true') {
strings[children[i].innerHTML.trim().replace('\n', '')] = '';
}
getTranslatable(children[i], strings);
}
}
function setTranslatable(root, strings) {
var children = root.children;
for (var i = 0; i < children.length; ++i) {
if (children[i].dataset.translate === 'true') {
children[i].innerHTML = strings[children[i].innerHTML.trim().replace('\n', '')];
}
setTranslatable(children[i], strings);
}
}