PluginProbe
Polylang / 3.8.10
Polylang v3.8.10
3.8.10 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 All 234 releases
← All changes | js/build/post.js +89 -89 3.0 → 3.8.10 View file →
@@ -5,11 +5,11 @@
5 5 /**
6 6 * Tag suggest in quick edit
7 7 */
8 8 jQuery(
9 - function( $ ) {
9 + function ( $ ) {
10 10 $.ajaxPrefilter(
11 - function( options, originalOptions, jqXHR ) {
11 + function ( options, originalOptions, jqXHR ) {
12 12 if ( 'string' === typeof options.data && -1 !== options.data.indexOf( 'action=ajax-tag-search' ) && ( lang = $( ':input[name="inline_lang_choice"]' ).val() ) ) {
13 13 options.data = 'lang=' + lang + '&' + options.data;
14 14 }
15 15 }
@@ -20,84 +20,98 @@
20 20 /**
21 21 * Quick edit
22 22 */
23 23 jQuery(
24 - function( $ ) {
25 - $( document ).on(
26 - 'DOMNodeInserted',
27 - function( e ) {
28 - var t = $( e.target );
24 + function ( $ ) {
25 + const handleQuickEditInsertion = ( mutationsList ) => {
26 + for ( const mutation of mutationsList ) {
27 + const addedNodes = Array.from( mutation.addedNodes ).filter( el => el.nodeType === Node.ELEMENT_NODE )
28 + const form = addedNodes[0];
29 + if ( 0 < mutation.addedNodes.length && form.classList.contains( 'inline-editor' ) ) {
30 + // WordPress has inserted the quick edit form.
31 + const post_id = Number( form.id.substring( 5 ) );
29 32
30 - // WP inserts the quick edit from
31 - if ( 'inline-edit' == t.attr( 'id' ) ) {
32 - var post_id = t.prev().attr( 'id' ).replace( "post-", "" );
33 -
34 33 if ( post_id > 0 ) {
35 - // language dropdown
36 - var select = t.find( ':input[name="inline_lang_choice"]' );
37 - var lang = $( '#lang_' + post_id ).html();
38 - select.val( lang ); // populates the dropdown
34 + // Get the language dropdown.
35 + const select = form.querySelector( 'select[name="inline_lang_choice"]' );
36 + const lang = document.querySelector( '#lang_' + String( post_id ) ).innerHTML;
37 + select.value = lang; // Populates the dropdown with the post language.
39 38
40 - filter_terms( lang ); // initial filter for category checklist
41 - filter_pages( lang ); // initial filter for parent dropdown
39 + filter_terms( lang ); // Initial filter for category checklist.
40 + filter_pages( lang ); // Initial filter for parent dropdown.
42 41
43 - // modify category checklist an parent dropdown on language change
44 - select.on(
42 + // Modify category checklist and parent dropdown on language change.
43 + select.addEventListener(
45 44 'change',
46 - function() {
47 - filter_terms( $( this ).val() );
48 - filter_pages( $( this ).val() );
45 + function ( event ) {
46 + const newLang = event.target.value;
47 + filter_terms( newLang );
48 + filter_pages( newLang );
49 49 }
50 - );
50 + );
51 + }
51 52 }
52 - }
53 + /**
54 + * Filters the category checklist.
55 + */
56 + function filter_terms( lang ) {
57 + if ( "undefined" != typeof( pll_term_languages ) ) {
58 + $.each(
59 + pll_term_languages,
60 + function ( lg, term_tax ) {
61 + $.each(
62 + term_tax,
63 + function ( tax, terms ) {
64 + $.each(
65 + terms,
66 + function ( i ) {
67 + // Backward compatibility with WordPress < 6.7.
68 + // Support both old (WP < 6.7) and new (WP >= 6.7) ID formats.
69 + // Old format: category-123 (WordPress < 6.7).
70 + // New format: in-category-123-1 (WordPress >= 6.7).
71 + const termId = pll_term_languages[ lg ][ tax ][ i ];
72 + const selector = `#${tax}-${termId}, [id^="in-${tax}-${termId}-"]`;
73 + $( selector ).toggle( lang === lg );
74 + }
75 + );
76 + }
77 + );
78 + }
79 + );
80 + }
81 + }
53 82
54 - /**
55 - * Filters the category checklist.
56 - */
57 - function filter_terms( lang ) {
58 - if ( "undefined" != typeof( pll_term_languages ) ) {
59 - $.each(
60 - pll_term_languages,
61 - function( lg, term_tax ) {
62 - $.each(
63 - term_tax,
64 - function( tax, terms ) {
65 - $.each(
66 - terms,
67 - function( i ) {
68 - id = '#' + tax + '-' + pll_term_languages[ lg ][ tax ][ i ];
69 - lang == lg ? $( id ).show() : $( id ).hide();
70 - }
71 - );
72 - }
73 - );
74 - }
75 - );
83 + /**
84 + * Filters the parent page dropdown list.
85 + */
86 + function filter_pages( lang ) {
87 + if ( "undefined" != typeof( pll_page_languages ) ) {
88 + $.each(
89 + pll_page_languages,
90 + function ( lg, pages ) {
91 + $.each(
92 + pages,
93 + function ( i ) {
94 + v = $( '#post_parent option[value="' + pll_page_languages[ lg ][ i ] + '"]' );
95 + lang == lg ? v.show() : v.hide();
96 + }
97 + );
98 + }
99 + );
100 + }
76 101 }
77 102 }
103 + }
104 + const table = document.getElementById( 'the-list' );
78 105
79 - /**
80 - * Filters the parent page dropdown list.
81 - */
82 - function filter_pages( lang ) {
83 - if ( "undefined" != typeof( pll_page_languages ) ) {
84 - $.each(
85 - pll_page_languages,
86 - function( lg, pages ) {
87 - $.each(
88 - pages,
89 - function( i ) {
90 - v = $( '#post_parent option[value="' + pll_page_languages[ lg ][ i ] + '"]' );
91 - lang == lg ? v.show() : v.hide();
92 - }
93 - );
94 - }
95 - );
96 - }
97 - }
98 - }
99 - );
106 + if ( ! table ) {
107 + return;
108 + }
109 +
110 + const config = { childList: true, subtree: true };
111 + const observer = new MutationObserver( handleQuickEditInsertion );
112 +
113 + observer.observe( table, config);
100 114 }
101 115 );
102 116
103 117 /**
@@ -104,16 +118,16 @@
104 118 * Update rows of translated posts when the language is modified in quick edit
105 119 * Acts on ajaxSuccess event
106 120 */
107 121 jQuery(
108 - function( $ ) {
122 + function ( $ ) {
109 123 $( document ).ajaxSuccess(
110 - function( event, xhr, settings ) {
124 + function ( event, xhr, settings ) {
111 125 function update_rows( post_id ) {
112 126 // collect old translations
113 127 var translations = new Array();
114 128 $( '.translation_' + post_id ).each(
115 - function() {
129 + function () {
116 130 translations.push( $( this ).parent().parent().attr( 'id' ).substring( 5 ) );
117 131 }
118 132 );
119 133
@@ -129,14 +143,16 @@
129 143 // get the modified rows in ajax and update them
130 144 $.post(
131 145 ajaxurl,
132 146 data,
133 - function( response ) {
147 + function ( response ) {
134 148 if ( response ) {
135 - var res = wpAjax.parseAjaxResponse( response, 'ajax-response' );
149 + // Since WP changeset #52710 parseAjaxResponse() return content to notice the user in a HTML tag with ajax-response id.
150 + // Not to disturb this behaviour by executing another ajax request in the ajaxSuccess event, we need to target another unexisting id.
151 + var res = wpAjax.parseAjaxResponse( response, 'pll-ajax-response' );
136 152 $.each(
137 153 res.responses,
138 - function() {
154 + function () {
139 155 if ( 'row' == this.what ) {
140 156 // data is built with a call to WP_Posts_List_Table::single_row method
141 157 // which uses internally other WordPress methods which escape correctly values.
142 158 // For Polylang language columns the HTML code is correctly escaped in PLL_Admin_Filters_Columns::post_column method.
@@ -153,24 +169,8 @@
153 169 var data = wpAjax.unserialize( settings.data ); // what were the data sent by the ajax request?
154 170 if ( 'undefined' != typeof( data['action'] ) && 'inline-save' == data['action'] ) {
155 171 update_rows( data['post_ID'] );
156 172 }
157 - }
158 - }
159 - );
160 - }
161 -);
162 -
163 -/**
164 - * Media list table
165 - * When clicking on attach link, filters find post list per media language
166 - */
167 -jQuery(
168 - function( $ ) {
169 - $.ajaxPrefilter(
170 - function ( options, originalOptions, jqXHR ) {
171 - if ( 'string' === typeof options.data && -1 !== options.data.indexOf( 'action=find_posts' ) ) {
172 - options.data = 'pll_post_id=' + $( '#affected' ).val() + '&' + options.data;
173 173 }
174 174 }
175 175 );
176 176 }