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 +63 -112 3.02.5 View file →
@@ -1,132 +1,83 @@
1 -/**
2 - * Adds a flag to the widgets filtered by a language.
3 - *
4 - * @package Polylang
5 - */
1 +jQuery( function( $ ) {
2 + var widgets_container, widgets_selector, flags;
6 3
7 -jQuery(
8 - function( $ ) {
9 - var widgets_container, widgets_selector, flags;
4 + if ( 'undefined' !== typeof pll_widgets && pll_widgets.hasOwnProperty( 'flags' ) ) {
5 + flags = pll_widgets.flags;
6 + }
10 7
11 - if ( 'undefined' !== typeof pll_widgets && pll_widgets.hasOwnProperty( 'flags' ) ) {
12 - flags = pll_widgets.flags;
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;
13 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;
14 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 +
15 41 /**
16 - * Prepend widget titles with a flag once a language is selected.
42 + * WP Customizer add control listener.
17 43 *
18 - * @param {object} widget The widget element.
44 + * @link https://wordpress.stackexchange.com/questions/256536/callback-after-wordpress-customizer-complete-loading
45 + *
46 + * @param {object} control The control type.
19 47 * @return {void} Nothing.
20 48 */
21 - function add_flag( widget ) {
22 - if ( ! flags ) {
49 + function customize_add_flag( control ) {
50 + if ( ! control.extended( wp.customize.Widgets.WidgetControl ) ) {
23 51 return;
24 52 }
25 - widget = $( widget );
26 - var title = $( '.widget-top .widget-title h3', widget ),
27 - locale = $( '.pll-lang-choice option:selected', widget ).val(),
28 - // Icon is HTML built and come from server side and is well escaped when necessary
29 - icon = ( locale && flags.hasOwnProperty( locale ) ) ? flags[ locale ] : null;
30 53
31 - if ( icon ) {
32 - icon += ' &nbsp; ';
33 - var current = $( '.pll-lang', title );
34 - if ( current.length ) {
35 - current.html( icon ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.html
36 - } else {
37 - flag = $( '<span />' ).addClass( 'pll-lang' ).html( icon ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.html
38 - // See the comment above about the icon which is safe. So it is also safe to prepend flag which uses icon.
39 - title.prepend( flag ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.prepend
40 - }
41 - } else {
42 - $( '.pll-lang', title ).remove();
43 - }
44 - }
45 -
46 - if ( 'undefined' !== typeof wp.customize ) {
47 -
48 - widgets_container = $( '#customize-controls' );
49 - widgets_selector = '.customize-control .widget';
50 -
51 - /**
52 - * WP Customizer add control listener.
53 - *
54 - * @link https://wordpress.stackexchange.com/questions/256536/callback-after-wordpress-customizer-complete-loading
55 - *
56 - * @param {object} control The control type.
57 - * @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.
58 57 */
59 - function customize_add_flag( control ) {
60 - if ( ! control.extended( wp.customize.Widgets.WidgetControl ) ) {
61 - return;
62 - }
58 + control.embedWidgetContent();
63 59
64 - /*
65 - * Make sure the widget's contents are embedded; normally this is done
66 - * when the control is expanded, for DOM performance reasons.
67 - */
68 - control.embedWidgetContent();
69 -
70 - // Now we know for sure the widget is fully embedded.
71 - add_flag( control.container.find( '.widget' ) );
72 - }
73 - wp.customize.control.each( customize_add_flag );
74 - wp.customize.control.bind( 'add', customize_add_flag );
75 -
76 - } else {
77 -
78 - widgets_container = $( '#widgets-right' );
79 - widgets_selector = '.widget';
80 -
60 + // Now we know for sure the widget is fully embedded.
61 + add_flag( control.container.find( '.widget' ) );
81 62 }
63 + wp.customize.control.each( customize_add_flag );
64 + wp.customize.control.bind( 'add', customize_add_flag );
82 65
83 - // Add flags on load.
84 - $( widgets_selector, widgets_container ).each(
85 - function() {
86 - add_flag( this );
87 - }
88 - );
66 + } else {
89 67
90 - // Update flags.
91 - widgets_container.on(
92 - 'change',
93 - '.pll-lang-choice',
94 - function() {
95 - add_flag( $( this ).parents( '.widget' ) );
96 - }
97 - );
68 + widgets_container = $( '#widgets-right' );
69 + widgets_selector = '.widget';
98 70
99 - function pll_toggle( a, test ) {
100 - test ? a.show() : a.hide();
101 - }
71 + }
102 72
103 - // Remove all options if dropdown is checked.
104 - $( '.widgets-sortables,.control-section-sidebar' ).on(
105 - 'change',
106 - '.pll-dropdown',
107 - function() {
108 - var this_id = $( this ).parent().parent().parent().children( '.widget-id' ).attr( 'value' );
109 - pll_toggle( $( '.no-dropdown-' + this_id ), true != $( this ).prop( 'checked' ) );
110 - }
111 - );
73 + // Add flags on load.
74 + $( widgets_selector, widgets_container ).each( function() {
75 + add_flag( this );
76 + } );
112 77
113 - // Disallow unchecking both show names and show flags.
114 - var options = ['-show_flags', '-show_names'];
115 - $.each(
116 - options,
117 - function( i, v ) {
118 - $( '.widgets-sortables,.control-section-sidebar' ).on(
119 - 'change',
120 - '.pll' + v,
121 - function() {
122 - var this_id = $( this ).parent().parent().parent().children( '.widget-id' ).attr( 'value' );
123 - if ( true != $( this ).prop( 'checked' ) ) {
124 - $( '#widget-' + this_id + options[ 1 - i ] ).prop( 'checked', true );
125 - }
126 - }
127 - );
128 - }
129 - );
78 + // Update flags.
79 + widgets_container.on( 'change', '.pll-lang-choice', function() {
80 + add_flag( $( this ).parents( '.widget' ) );
81 + } );
130 82
131 - }
132 -);
83 +} );