wpml-simple-language-selector.js
1.31 KB
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
var WPML_Core = WPML_Core || {};
WPML_Core.SimpleLanguageSelector = function () {
var self = this;
var init = function () {
jQuery(function () {
self.initialize_select2();
});
};
var add_flags = function ( state ) {
if (!state.id) { return state.text; }
var text = state.text;
if (jQuery(state.element).data('status') == 'active' ) {
text = '<strong> ' + text + '</strong>';
}
return '<img width="18" height="12" src="' + jQuery(state.element).data('flag_url') + '"/> ' + text;
};
self.initialize_select2 = function () {
jQuery('.js-simple-lang-selector-flags').wpml_select2({
formatResult: add_flags,
formatSelection: add_flags,
width: 'auto',
dropdownCss: {'z-index': parseInt(jQuery('.ui-dialog').css('z-index'), 10) + 100},
dropdownAutoWidth: true
});
var lang_selector_flags = jQuery('.js-simple-lang-selector-flags');
if (lang_selector_flags.is(':disabled')) {
lang_selector_flags.find('.wpml_select2-choice').addClass('button button-secondary').attr('disabled', 'true');
}
};
init();
};
WPML_Core.simple_language_selector = new WPML_Core.SimpleLanguageSelector();