forked from lichess-org/lila
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtranslation.js
43 lines (39 loc) · 1.19 KB
/
translation.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
$(function() {
if ($('div.locale_menu').length > 0) {
$('div.messages div.message').each(function() {
if (!$(this).find('input').val()) {
$(this).addClass('missing');
}
});
$('div.locale_menu a').click(function() {
$(this).parent().find('a').removeClass('active');
$(this).addClass('active');
$('div.messages div.message').show();
if ($(this).hasClass('missing')) {
$('div.messages div.message').not('.missing').hide();
}
});
if ($('div.messages div.missing').length > 0) {
$('div.locale_menu a.missing').click();
}
}
var inputHash = function() {
return Array.prototype.map.call(
document.querySelectorAll('div.messages input'),
function(el) {
return el.value;
}).join('');
};
var initialHash = inputHash();
var beforeUnload = function(e) {
if (initialHash !== inputHash()) {
var msg = 'There are unsaved translations!';
(e || window.event).returnValue = msg;
return msg;
}
};
window.addEventListener('beforeunload', beforeUnload);
$('form.translation_form').on('submit', function() {
window.removeEventListener('beforeunload', beforeUnload);
});
});