| @@ -1,176 +1,104 @@ | ||
| 1 | -/** | |
| 2 | - * @package Polylang | |
| 3 | - */ | |
| 1 | +// tag suggest in quick edit | |
| 2 | +(function( $ ){ | |
| 3 | + $.ajaxPrefilter(function( options, originalOptions, jqXHR ) { | |
| 4 | + if ( 'string' === typeof options.data && -1 !== options.data.indexOf( 'action=ajax-tag-search' ) && ( lang = $( ':input[name="inline_lang_choice"]' ).val() ) ) { | |
| 5 | + options.data = 'lang=' + lang + '&' + options.data; | |
| 6 | + } | |
| 7 | + }); | |
| 8 | +})( jQuery ); | |
| 4 | 9 | |
| 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 | -); | |
| 10 | +// quick edit | |
| 11 | +(function( $ ) { | |
| 12 | + $( document ).bind( 'DOMNodeInserted', function( e ) { | |
| 13 | + var t = $( e.target ); | |
| 19 | 14 | |
| 20 | -/** | |
| 21 | - * Quick edit | |
| 22 | - */ | |
| 23 | -jQuery( | |
| 24 | - function( $ ) { | |
| 25 | - $( document ).on( | |
| 26 | - 'DOMNodeInserted', | |
| 27 | - function( e ) { | |
| 28 | - var t = $( e.target ); | |
| 15 | + // WP inserts the quick edit from | |
| 16 | + if ( 'inline-edit' == t.attr( 'id' ) ) { | |
| 17 | + var post_id = t.prev().attr( 'id' ).replace( "post-", "" ); | |
| 29 | 18 | |
| 30 | - // WP inserts the quick edit from | |
| 31 | - if ( 'inline-edit' == t.attr( 'id' ) ) { | |
| 32 | - var post_id = t.prev().attr( 'id' ).replace( "post-", "" ); | |
| 19 | + if ( post_id > 0 ) { | |
| 20 | + // language dropdown | |
| 21 | + var select = t.find( ':input[name="inline_lang_choice"]' ); | |
| 22 | + var lang = $( '#lang_' + post_id ).html(); | |
| 23 | + select.val( lang ); // populates the dropdown | |
| 33 | 24 | |
| 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 | |
| 25 | + filter_terms( lang ); // initial filter for category checklist | |
| 26 | + filter_pages( lang ); // initial filter for parent dropdown | |
| 39 | 27 | |
| 40 | - filter_terms( lang ); // initial filter for category checklist | |
| 41 | - filter_pages( lang ); // initial filter for parent dropdown | |
| 28 | + // modify category checklist an parent dropdown on language change | |
| 29 | + select.change(function() { | |
| 30 | + filter_terms( $( this ).val() ); | |
| 31 | + filter_pages( $( this ).val() ); | |
| 32 | + }); | |
| 33 | + } | |
| 34 | + } | |
| 42 | 35 | |
| 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 | - } | |
| 36 | + // filter category checklist | |
| 37 | + function filter_terms( lang ) { | |
| 38 | + if ( "undefined" != typeof( pll_term_languages ) ) { | |
| 39 | + $.each( pll_term_languages, function( lg, term_tax ) { | |
| 40 | + $.each( term_tax, function( tax, terms ) { | |
| 41 | + $.each( terms, function( i ) { | |
| 42 | + id = '#' + tax + '-' + pll_term_languages[ lg ][ tax ][ i ]; | |
| 43 | + lang == lg ? $( id ).show() : $( id ).hide(); | |
| 44 | + }); | |
| 45 | + }); | |
| 46 | + }); | |
| 47 | + } | |
| 48 | + } | |
| 52 | 49 | |
| 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 | - } | |
| 50 | + // filter parent page dropdown list | |
| 51 | + function filter_pages( lang ) { | |
| 52 | + if ( "undefined" != typeof( pll_page_languages ) ) { | |
| 53 | + $.each( pll_page_languages, function( lg, pages ) { | |
| 54 | + $.each( pages, function( i ) { | |
| 55 | + v = $( '#post_parent option[value="' + pll_page_languages[ lg ][ i ] + '"]' ); | |
| 56 | + lang == lg ? v.show() : v.hide(); | |
| 57 | + }); | |
| 58 | + }); | |
| 97 | 59 | } |
| 98 | - ); | |
| 99 | - } | |
| 100 | -); | |
| 60 | + } | |
| 61 | + }); | |
| 62 | +})( jQuery ); | |
| 101 | 63 | |
| 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 | - ); | |
| 64 | +// update rows of translated posts when the language is modified in quick edit | |
| 65 | +// acts on ajaxSuccess event | |
| 66 | +(function( $ ) { | |
| 67 | + $( document ).ajaxSuccess(function( event, xhr, settings ) { | |
| 68 | + function update_rows( post_id ) { | |
| 69 | + // collect old translations | |
| 70 | + var translations = new Array; | |
| 71 | + $( '.translation_' + post_id ).each(function() { | |
| 72 | + translations.push( $( this ).parent().parent().attr( 'id' ).substring( 5 ) ); | |
| 73 | + }); | |
| 118 | 74 | |
| 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 | - }; | |
| 75 | + var data = { | |
| 76 | + action: 'pll_update_post_rows', | |
| 77 | + post_id: post_id, | |
| 78 | + translations: translations.join( ',' ), | |
| 79 | + post_type: $( "input[name='post_type']" ).val(), | |
| 80 | + screen: $( "input[name='screen']" ).val(), | |
| 81 | + _pll_nonce: $( "input[name='_inline_edit']" ).val() // reuse quick edit nonce | |
| 82 | + } | |
| 127 | 83 | |
| 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 | - } | |
| 84 | + // get the modified rows in ajax and update them | |
| 85 | + $.post( ajaxurl, data, function( response ) { | |
| 86 | + if ( response ) { | |
| 87 | + var res = wpAjax.parseAjaxResponse( response, 'ajax-response' ); | |
| 88 | + $.each( res.responses, function() { | |
| 89 | + if ( 'row' == this.what ) { | |
| 90 | + $( "#post-" + this.supplemental.post_id ).replaceWith( this.data ); | |
| 147 | 91 | } |
| 148 | - ); | |
| 92 | + }); | |
| 149 | 93 | } |
| 94 | + }); | |
| 95 | + } | |
| 150 | 96 | |
| 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 | - } | |
| 97 | + if ( 'string' == typeof( settings.data ) ) { // Need to check the type due to Gutenberg sometime sending FormData objects | |
| 98 | + var data = wpAjax.unserialize( settings.data ); // what were the data sent by the ajax request? | |
| 99 | + if ( 'undefined' != typeof( data['action'] ) && 'inline-save' == data['action'] ) { | |
| 100 | + update_rows( data['post_ID'] ); | |
| 157 | 101 | } |
| 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 | -); | |
| 102 | + } | |
| 103 | + }); | |
| 104 | +})( jQuery ); | |