libreoffice-online/browser/welcome/welcome.js
Gökay Şatır 7410e2ff85 Enable translations for paragraphs containing links.
Signed-off-by: Gökay Şatır <gokaysatir@collabora.com>
Change-Id: I9b66f7b301487cf345c9a136943a6148827a2d49
2022-03-14 08:32:27 +01:00

85 lines
2.5 KiB
JavaScript

window.onload = onLoaded;
function onLoaded() {
window.addEventListener('message', onMessage, false);
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);
}
}