Skip to content

Commit 53f2967

Browse files
committed
Revert changes to language_link.js
1 parent 09147ca commit 53f2967

1 file changed

Lines changed: 17 additions & 22 deletions

File tree

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,26 @@
1-
(function () {
2-
const set_language_url = document.currentScript ?
3-
document.currentScript.getAttribute('data-set-lang') :
4-
document.querySelectorAll('script')[document.querySelectorAll('script').length - 1].getAttribute('data-set-lang');
1+
(function ($) {
2+
const set_language_url = (document.currentScript ?
3+
$(document.currentScript) :
4+
$('script').last()) // Ugly solution for IE11
5+
.attr('data-set-lang');
56

6-
document.addEventListener('DOMContentLoaded', function () {
7-
document.querySelectorAll('a.change-language').forEach(function (elem) {
8-
const target_lang = elem.getAttribute('data-target-lang');
9-
elem.addEventListener('click', function (event) {
10-
event.preventDefault();
11-
fetch(set_language_url, {
12-
method: 'POST',
13-
headers: {
14-
'Content-Type': 'application/json'
15-
},
16-
body: JSON.stringify({ language: target_lang })
17-
})
18-
.then(function (response) {
19-
if (response.ok) {
20-
const href = elem.getAttribute('href');
7+
$(function () {
8+
$('a.change-language').each(function (i, elem) {
9+
const $elem = $(elem);
10+
const target_lang = $elem.attr('data-target-lang');
11+
$elem.on('click', function () {
12+
$.post(set_language_url, { language: target_lang })
13+
.done(function () {
14+
const href = $elem.attr('href');
15+
// href="#" means "this page, but in another language"
2116
if (href === '#') {
2217
window.location.reload();
2318
} else {
2419
window.location.href = href;
2520
}
26-
}
27-
});
21+
});
22+
return false;
2823
});
2924
});
3025
});
31-
})();
26+
})(jQuery);

0 commit comments

Comments
 (0)