PluginProbe
Polylang / 3.0.1
Polylang v3.0.1
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
polylang / js / post.js

post.js in Polylang 3.0.1, at js/post.js

178 lines 4.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * @package Polylang
3 */
4
5 /**
6 * Tag suggest in quick edit
7 */
8 jQuery(
9 function( $ ) {
10 $.ajaxPrefilter(
11 function( options, originalOptions, jqXHR ) {
12 if ( 'string' === typeof options.data && -1 !== options.data.indexOf( 'action=ajax-tag-search' ) && ( lang = $( ':input[name="inline_lang_choice"]' ).val() ) ) {
13 options.data = 'lang=' + lang + '&' + options.data;
14 }
15 }
16 );
17 }
18 );
19
20 /**
21 * Quick edit
22 */
23 jQuery(
24 function( $ ) {
25 $( document ).on(
26 'DOMNodeInserted',
27 function( e ) {
28 var t = $( e.target );
29
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 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
39
40 filter_terms( lang ); // initial filter for category checklist
41 filter_pages( lang ); // initial filter for parent dropdown
42
43 // modify category checklist an parent dropdown on language change
44 select.on(
45 'change',
46 function() {
47 filter_terms( $( this ).val() );
48 filter_pages( $( this ).val() );
49 }
50 );
51 }
52 }
53
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 );
76 }
77 }
78
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 );
100 }
101 );
102
103 /**
104 * Update rows of translated posts when the language is modified in quick edit
105 * Acts on ajaxSuccess event
106 */
107 jQuery(
108 function( $ ) {
109 $( document ).ajaxSuccess(
110 function( event, xhr, settings ) {
111 function update_rows( post_id ) {
112 // collect old translations
113 var translations = new Array();
114 $( '.translation_' + post_id ).each(
115 function() {
116 translations.push( $( this ).parent().parent().attr( 'id' ).substring( 5 ) );
117 }
118 );
119
120 var data = {
121 action: 'pll_update_post_rows',
122 post_id: post_id,
123 translations: translations.join( ',' ),
124 post_type: $( "input[name='post_type']" ).val(),
125 screen: $( "input[name='screen']" ).val(),
126 _pll_nonce: $( "input[name='_inline_edit']" ).val() // reuse quick edit nonce
127 };
128
129 // get the modified rows in ajax and update them
130 $.post(
131 ajaxurl,
132 data,
133 function( response ) {
134 if ( response ) {
135 var res = wpAjax.parseAjaxResponse( response, 'ajax-response' );
136 $.each(
137 res.responses,
138 function() {
139 if ( 'row' == this.what ) {
140 // data is built with a call to WP_Posts_List_Table::single_row method
141 // which uses internally other WordPress methods which escape correctly values.
142 // 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
144 }
145 }
146 );
147 }
148 }
149 );
150 }
151
152 if ( 'string' == typeof( settings.data ) ) { // Need to check the type due to block editor sometime sending FormData objects
153 var data = wpAjax.unserialize( settings.data ); // what were the data sent by the ajax request?
154 if ( 'undefined' != typeof( data['action'] ) && 'inline-save' == data['action'] ) {
155 update_rows( data['post_ID'] );
156 }
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 }
174 }
175 );
176 }
177 );
178