PluginProbe
Polylang / 2.8.4
Polylang v2.8.4
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 2.8.4, at js/post.js

165 lines 4.5 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 (function( $ ){
9 $.ajaxPrefilter(
10 function( options, originalOptions, jqXHR ) {
11 if ( 'string' === typeof options.data && -1 !== options.data.indexOf( 'action=ajax-tag-search' ) && ( lang = $( ':input[name="inline_lang_choice"]' ).val() ) ) {
12 options.data = 'lang=' + lang + '&' + options.data;
13 }
14 }
15 );
16 })( jQuery );
17
18 /**
19 * Quick edit
20 */
21 (function( $ ) {
22 $( document ).bind(
23 'DOMNodeInserted',
24 function( e ) {
25 var t = $( e.target );
26
27 // WP inserts the quick edit from
28 if ( 'inline-edit' == t.attr( 'id' ) ) {
29 var post_id = t.prev().attr( 'id' ).replace( "post-", "" );
30
31 if ( post_id > 0 ) {
32 // language dropdown
33 var select = t.find( ':input[name="inline_lang_choice"]' );
34 var lang = $( '#lang_' + post_id ).html();
35 select.val( lang ); // populates the dropdown
36
37 filter_terms( lang ); // initial filter for category checklist
38 filter_pages( lang ); // initial filter for parent dropdown
39
40 // modify category checklist an parent dropdown on language change
41 select.change(
42 function() {
43 filter_terms( $( this ).val() );
44 filter_pages( $( this ).val() );
45 }
46 );
47 }
48 }
49
50 // filter category checklist
51 function filter_terms( lang ) {
52 if ( "undefined" != typeof( pll_term_languages ) ) {
53 $.each(
54 pll_term_languages,
55 function( lg, term_tax ) {
56 $.each(
57 term_tax,
58 function( tax, terms ) {
59 $.each(
60 terms,
61 function( i ) {
62 id = '#' + tax + '-' + pll_term_languages[ lg ][ tax ][ i ];
63 lang == lg ? $( id ).show() : $( id ).hide();
64 }
65 );
66 }
67 );
68 }
69 );
70 }
71 }
72
73 // filter parent page dropdown list
74 function filter_pages( lang ) {
75 if ( "undefined" != typeof( pll_page_languages ) ) {
76 $.each(
77 pll_page_languages,
78 function( lg, pages ) {
79 $.each(
80 pages,
81 function( i ) {
82 v = $( '#post_parent option[value="' + pll_page_languages[ lg ][ i ] + '"]' );
83 lang == lg ? v.show() : v.hide();
84 }
85 );
86 }
87 );
88 }
89 }
90 }
91 );
92 })( jQuery );
93
94 /**
95 * Update rows of translated posts when the language is modified in quick edit
96 * Acts on ajaxSuccess event
97 */
98 (function( $ ) {
99 $( document ).ajaxSuccess(
100 function( event, xhr, settings ) {
101 function update_rows( post_id ) {
102 // collect old translations
103 var translations = new Array();
104 $( '.translation_' + post_id ).each(
105 function() {
106 translations.push( $( this ).parent().parent().attr( 'id' ).substring( 5 ) );
107 }
108 );
109
110 var data = {
111 action: 'pll_update_post_rows',
112 post_id: post_id,
113 translations: translations.join( ',' ),
114 post_type: $( "input[name='post_type']" ).val(),
115 screen: $( "input[name='screen']" ).val(),
116 _pll_nonce: $( "input[name='_inline_edit']" ).val() // reuse quick edit nonce
117 };
118
119 // get the modified rows in ajax and update them
120 $.post(
121 ajaxurl,
122 data,
123 function( response ) {
124 if ( response ) {
125 var res = wpAjax.parseAjaxResponse( response, 'ajax-response' );
126 $.each(
127 res.responses,
128 function() {
129 if ( 'row' == this.what ) {
130 // data is built with a call to WP_Posts_List_Table::single_row method
131 // which uses internally other WordPress methods which escape correctly values.
132 // For Polylang language columns the HTML code is correctly escaped in PLL_Admin_Filters_Columns::post_column method.
133 $( "#post-" + this.supplemental.post_id ).replaceWith( this.data ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.replaceWith
134 }
135 }
136 );
137 }
138 }
139 );
140 }
141
142 if ( 'string' == typeof( settings.data ) ) { // Need to check the type due to block editor sometime sending FormData objects
143 var data = wpAjax.unserialize( settings.data ); // what were the data sent by the ajax request?
144 if ( 'undefined' != typeof( data['action'] ) && 'inline-save' == data['action'] ) {
145 update_rows( data['post_ID'] );
146 }
147 }
148 }
149 );
150 })( jQuery );
151
152 /**
153 * Media list table
154 * When clicking on attach link, filters find post list per media language
155 */
156 (function( $ ){
157 $.ajaxPrefilter(
158 function ( options, originalOptions, jqXHR ) {
159 if ( 'string' === typeof options.data && -1 !== options.data.indexOf( 'action=find_posts' ) ) {
160 options.data = 'pll_post_id=' + $( '#affected' ).val() + '&' + options.data;
161 }
162 }
163 );
164 })( jQuery );
165