PluginProbe
Polylang / trunk
Polylang vtrunk
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/build/post.js +85 -90 3.0.1 → trunk 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,93 @@
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 + const termId = pll_term_languages[ lg ][ tax ][ i ];
68 + $( `[id^="in-${tax}-${termId}-"]` ).toggle( lang === lg );
69 + }
70 + );
71 + }
72 + );
73 + }
74 + );
75 + }
76 + }
53 77
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 - );
78 + /**
79 + * Filters the parent page dropdown list.
80 + */
81 + function filter_pages( lang ) {
82 + if ( "undefined" != typeof( pll_page_languages ) ) {
83 + $.each(
84 + pll_page_languages,
85 + function ( lg, pages ) {
86 + $.each(
87 + pages,
88 + function ( i ) {
89 + v = $( '#post_parent option[value="' + pll_page_languages[ lg ][ i ] + '"]' );
90 + lang == lg ? v.show() : v.hide();
91 + }
92 + );
93 + }
94 + );
95 + }
76 96 }
77 97 }
98 + }
99 + const table = document.getElementById( 'the-list' );
78 100
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 - );
101 + if ( ! table ) {
102 + return;
103 + }
104 +
105 + const config = { childList: true, subtree: true };
106 + const observer = new MutationObserver( handleQuickEditInsertion );
107 +
108 + observer.observe( table, config);
100 109 }
101 110 );
102 111
103 112 /**
@@ -104,16 +113,16 @@
104 113 * Update rows of translated posts when the language is modified in quick edit
105 114 * Acts on ajaxSuccess event
106 115 */
107 116 jQuery(
108 - function( $ ) {
117 + function ( $ ) {
109 118 $( document ).ajaxSuccess(
110 - function( event, xhr, settings ) {
119 + function ( event, xhr, settings ) {
111 120 function update_rows( post_id ) {
112 121 // collect old translations
113 122 var translations = new Array();
114 123 $( '.translation_' + post_id ).each(
115 - function() {
124 + function () {
116 125 translations.push( $( this ).parent().parent().attr( 'id' ).substring( 5 ) );
117 126 }
118 127 );
119 128
@@ -129,19 +138,21 @@
129 138 // get the modified rows in ajax and update them
130 139 $.post(
131 140 ajaxurl,
132 141 data,
133 - function( response ) {
142 + function ( response ) {
134 143 if ( response ) {
135 - var res = wpAjax.parseAjaxResponse( response, 'ajax-response' );
144 + // Since WP changeset #52710 parseAjaxResponse() return content to notice the user in a HTML tag with ajax-response id.
145 + // Not to disturb this behaviour by executing another ajax request in the ajaxSuccess event, we need to target another unexisting id.
146 + var res = wpAjax.parseAjaxResponse( response, 'pll-ajax-response' );
136 147 $.each(
137 148 res.responses,
138 - function() {
149 + function () {
139 150 if ( 'row' == this.what ) {
140 151 // data is built with a call to WP_Posts_List_Table::single_row method
141 152 // which uses internally other WordPress methods which escape correctly values.
142 153 // For Polylang language columns the HTML code is correctly escaped in PLL_Admin_Filters_Columns::post_column method.
143 - $( "#post-" + this.supplemental.post_id ).replaceWith( this.data ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.replaceWith
154 + $( "#post-" + this.supplemental.post_id ).replaceWith( this.data );
144 155 }
145 156 }
146 157 );
147 158 }
@@ -153,24 +164,8 @@
153 164 var data = wpAjax.unserialize( settings.data ); // what were the data sent by the ajax request?
154 165 if ( 'undefined' != typeof( data['action'] ) && 'inline-save' == data['action'] ) {
155 166 update_rows( data['post_ID'] );
156 167 }
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 168 }
174 169 }
175 170 );
176 171 }