| 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.change( |
| 45 |
function() { |
| 46 |
filter_terms( $( this ).val() ); |
| 47 |
filter_pages( $( this ).val() ); |
| 48 |
} |
| 49 |
); |
| 50 |
} |
| 51 |
} |
| 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 |
id = '#' + tax + '-' + pll_term_languages[ lg ][ tax ][ i ]; |
| 68 |
lang == lg ? $( id ).show() : $( id ).hide(); |
| 69 |
} |
| 70 |
); |
| 71 |
} |
| 72 |
); |
| 73 |
} |
| 74 |
); |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 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 |
} |
| 96 |
} |
| 97 |
} |
| 98 |
); |
| 99 |
} |
| 100 |
); |
| 101 |
|
| 102 |
/** |
| 103 |
* Update rows of translated posts when the language is modified in quick edit |
| 104 |
* Acts on ajaxSuccess event |
| 105 |
*/ |
| 106 |
jQuery( |
| 107 |
function( $ ) { |
| 108 |
$( document ).ajaxSuccess( |
| 109 |
function( event, xhr, settings ) { |
| 110 |
function update_rows( post_id ) { |
| 111 |
// collect old translations |
| 112 |
var translations = new Array(); |
| 113 |
$( '.translation_' + post_id ).each( |
| 114 |
function() { |
| 115 |
translations.push( $( this ).parent().parent().attr( 'id' ).substring( 5 ) ); |
| 116 |
} |
| 117 |
); |
| 118 |
|
| 119 |
var data = { |
| 120 |
action: 'pll_update_post_rows', |
| 121 |
post_id: post_id, |
| 122 |
translations: translations.join( ',' ), |
| 123 |
post_type: $( "input[name='post_type']" ).val(), |
| 124 |
screen: $( "input[name='screen']" ).val(), |
| 125 |
_pll_nonce: $( "input[name='_inline_edit']" ).val() // reuse quick edit nonce |
| 126 |
}; |
| 127 |
|
| 128 |
// get the modified rows in ajax and update them |
| 129 |
$.post( |
| 130 |
ajaxurl, |
| 131 |
data, |
| 132 |
function( response ) { |
| 133 |
if ( response ) { |
| 134 |
var res = wpAjax.parseAjaxResponse( response, 'ajax-response' ); |
| 135 |
$.each( |
| 136 |
res.responses, |
| 137 |
function() { |
| 138 |
if ( 'row' == this.what ) { |
| 139 |
// data is built with a call to WP_Posts_List_Table::single_row method |
| 140 |
// which uses internally other WordPress methods which escape correctly values. |
| 141 |
// For Polylang language columns the HTML code is correctly escaped in PLL_Admin_Filters_Columns::post_column method. |
| 142 |
$( "#post-" + this.supplemental.post_id ).replaceWith( this.data ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.replaceWith |
| 143 |
} |
| 144 |
} |
| 145 |
); |
| 146 |
} |
| 147 |
} |
| 148 |
); |
| 149 |
} |
| 150 |
|
| 151 |
if ( 'string' == typeof( settings.data ) ) { // Need to check the type due to block editor sometime sending FormData objects |
| 152 |
var data = wpAjax.unserialize( settings.data ); // what were the data sent by the ajax request? |
| 153 |
if ( 'undefined' != typeof( data['action'] ) && 'inline-save' == data['action'] ) { |
| 154 |
update_rows( data['post_ID'] ); |
| 155 |
} |
| 156 |
} |
| 157 |
} |
| 158 |
); |
| 159 |
} |
| 160 |
); |
| 161 |
|
| 162 |
/** |
| 163 |
* Media list table |
| 164 |
* When clicking on attach link, filters find post list per media language |
| 165 |
*/ |
| 166 |
jQuery( |
| 167 |
function( $ ) { |
| 168 |
$.ajaxPrefilter( |
| 169 |
function ( options, originalOptions, jqXHR ) { |
| 170 |
if ( 'string' === typeof options.data && -1 !== options.data.indexOf( 'action=find_posts' ) ) { |
| 171 |
options.data = 'pll_post_id=' + $( '#affected' ).val() + '&' + options.data; |
| 172 |
} |
| 173 |
} |
| 174 |
); |
| 175 |
} |
| 176 |
); |
| 177 |
|