PluginProbe
Polylang / 2.5
Polylang v2.5
3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 3.0.3 All 233 releases
← All changes | js/widgets.js +66 -76 2.72.5 View file →
@@ -1,93 +1,83 @@
1 -jQuery(
2 - function( $ ) {
3 - var widgets_container, widgets_selector, flags;
1 +jQuery( function( $ ) {
2 + var widgets_container, widgets_selector, flags;
4 3
5 - if ( 'undefined' !== typeof pll_widgets && pll_widgets.hasOwnProperty( 'flags' ) ) {
6 - flags = pll_widgets.flags;
4 + if ( 'undefined' !== typeof pll_widgets && pll_widgets.hasOwnProperty( 'flags' ) ) {
5 + flags = pll_widgets.flags;
6 + }
7 +
8 + /**
9 + * Prepend widget titles with a flag once a language is selected.
10 + * @param {object} widget The widget element.
11 + * @return {void} Nothing.
12 + */
13 + function add_flag( widget ) {
14 + if ( ! flags ) {
15 + return;
7 16 }
17 + widget = $( widget );
18 + var title = $( '.widget-top .widget-title h3', widget ),
19 + locale = $( '.pll-lang-choice option:selected', widget ).val(),
20 + icon = ( locale && flags.hasOwnProperty( locale ) ) ? flags[ locale ] : null;
8 21
22 + if ( icon ) {
23 + icon += '   ';
24 + var current = $( '.pll-lang', title );
25 + if ( current.length ) {
26 + current.html( icon );
27 + } else {
28 + flag = '<span class="pll-lang">' + icon + '</span>';
29 + title.prepend( flag );
30 + }
31 + } else {
32 + $( '.pll-lang', title ).remove();
33 + }
34 + }
35 +
36 + if ( 'undefined' !== typeof wp.customize ) {
37 +
38 + widgets_container = $( '#customize-controls' );
39 + widgets_selector = '.customize-control .widget';
40 +
9 41 /**
10 - * Prepend widget titles with a flag once a language is selected.
11 - *
12 - * @param {object} widget The widget element.
42 + * WP Customizer add control listener.
43 + *
44 + * @link https://wordpress.stackexchange.com/questions/256536/callback-after-wordpress-customizer-complete-loading
45 + *
46 + * @param {object} control The control type.
13 47 * @return {void} Nothing.
14 48 */
15 - function add_flag( widget ) {
16 - if ( ! flags ) {
49 + function customize_add_flag( control ) {
50 + if ( ! control.extended( wp.customize.Widgets.WidgetControl ) ) {
17 51 return;
18 52 }
19 - widget = $( widget );
20 - var title = $( '.widget-top .widget-title h3', widget ),
21 - locale = $( '.pll-lang-choice option:selected', widget ).val(),
22 - // Icon is HTML built and come from server side and is well escaped when necessary
23 - icon = ( locale && flags.hasOwnProperty( locale ) ) ? flags[ locale ] : null;
24 53
25 - if ( icon ) {
26 - icon += ' &nbsp; ';
27 - var current = $( '.pll-lang', title );
28 - if ( current.length ) {
29 - current.html( icon ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.html
30 - } else {
31 - flag = $( '<span />' ).addClass( 'pll-lang' ).html( icon ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.html
32 - title.prepend( flag );
33 - }
34 - } else {
35 - $( '.pll-lang', title ).remove();
36 - }
37 - }
38 -
39 - if ( 'undefined' !== typeof wp.customize ) {
40 -
41 - widgets_container = $( '#customize-controls' );
42 - widgets_selector = '.customize-control .widget';
43 -
44 - /**
45 - * WP Customizer add control listener.
46 - *
47 - * @link https://wordpress.stackexchange.com/questions/256536/callback-after-wordpress-customizer-complete-loading
48 - *
49 - * @param {object} control The control type.
50 - * @return {void} Nothing.
54 + /*
55 + * Make sure the widget's contents are embedded; normally this is done
56 + * when the control is expanded, for DOM performance reasons.
51 57 */
52 - function customize_add_flag( control ) {
53 - if ( ! control.extended( wp.customize.Widgets.WidgetControl ) ) {
54 - return;
55 - }
58 + control.embedWidgetContent();
56 59
57 - /*
58 - * Make sure the widget's contents are embedded; normally this is done
59 - * when the control is expanded, for DOM performance reasons.
60 - */
61 - control.embedWidgetContent();
60 + // Now we know for sure the widget is fully embedded.
61 + add_flag( control.container.find( '.widget' ) );
62 + }
63 + wp.customize.control.each( customize_add_flag );
64 + wp.customize.control.bind( 'add', customize_add_flag );
62 65
63 - // Now we know for sure the widget is fully embedded.
64 - add_flag( control.container.find( '.widget' ) );
65 - }
66 - wp.customize.control.each( customize_add_flag );
67 - wp.customize.control.bind( 'add', customize_add_flag );
66 + } else {
68 67
69 - } else {
68 + widgets_container = $( '#widgets-right' );
69 + widgets_selector = '.widget';
70 70
71 - widgets_container = $( '#widgets-right' );
72 - widgets_selector = '.widget';
71 + }
73 72
74 - }
73 + // Add flags on load.
74 + $( widgets_selector, widgets_container ).each( function() {
75 + add_flag( this );
76 + } );
75 77
76 - // Add flags on load.
77 - $( widgets_selector, widgets_container ).each(
78 - function() {
79 - add_flag( this );
80 - }
81 - );
78 + // Update flags.
79 + widgets_container.on( 'change', '.pll-lang-choice', function() {
80 + add_flag( $( this ).parents( '.widget' ) );
81 + } );
82 82
83 - // Update flags.
84 - widgets_container.on(
85 - 'change',
86 - '.pll-lang-choice',
87 - function() {
88 - add_flag( $( this ).parents( '.widget' ) );
89 - }
90 - );
91 -
92 - }
93 -);
83 +} );