blob: 694716fb187cb54daf5e1417343c7ec94b45582b (
plain)
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
|
const i18n = {
init: function(root) {
$('.i18n_group', root).each(function() {
var languages = $(this).children('.i18n'),
select = $('<select tabindex="-1">')
.addClass('i18n')
.css(
'background-image',
$(languages)
.first()
.data('icon')
);
select.change(function() {
var opt = $(this).find('option:selected'),
index = opt.index();
languages.not(':eq(' + index + ')').hide();
languages
.eq(index)
.show()
.find(':input')
.trigger('focus');
$(this).css('background-image', opt.css('background-image'));
});
languages.each(function(id, lang) {
select.append(
$('<option>', { text: $(lang).data('lang') }).css('background-image', $(lang).data('icon'))
);
});
$(this).append(select);
languages.not(':eq(0)').hide();
$('div.i18n input[required], div.i18n textarea[required]', this).on('invalid', function() {
var element = $(this).closest('.i18n');
element
.siblings('select')
.val($(element).data('lang'))
.change();
});
});
}
};
export default i18n;
|