| @@ -4,173 +4,158 @@ | ||
| 4 | 4 | |
| 5 | 5 | /** |
| 6 | 6 | * Tag suggest in quick edit |
| 7 | 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 | - } | |
| 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; | |
| 15 | 13 | } |
| 16 | - ); | |
| 17 | - } | |
| 18 | -); | |
| 14 | + } | |
| 15 | + ); | |
| 16 | +})( jQuery ); | |
| 19 | 17 | |
| 20 | 18 | /** |
| 21 | 19 | * Quick edit |
| 22 | 20 | */ |
| 23 | -jQuery( | |
| 24 | - function( $ ) { | |
| 25 | - $( document ).on( | |
| 26 | - 'DOMNodeInserted', | |
| 27 | - function( e ) { | |
| 28 | - var t = $( e.target ); | |
| 21 | +(function( $ ) { | |
| 22 | + $( document ).bind( | |
| 23 | + 'DOMNodeInserted', | |
| 24 | + function( e ) { | |
| 25 | + var t = $( e.target ); | |
| 29 | 26 | |
| 30 | - // WP inserts the quick edit from | |
| 31 | - if ( 'inline-edit' == t.attr( 'id' ) ) { | |
| 32 | - var post_id = t.prev().attr( 'id' ).replace( "post-", "" ); | |
| 27 | + // WP inserts the quick edit from | |
| 28 | + if ( 'inline-edit' == t.attr( 'id' ) ) { | |
| 29 | + var post_id = t.prev().attr( 'id' ).replace( "post-", "" ); | |
| 33 | 30 | |
| 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 | |
| 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 | |
| 39 | 36 | |
| 40 | - filter_terms( lang ); // initial filter for category checklist | |
| 41 | - filter_pages( lang ); // initial filter for parent dropdown | |
| 37 | + filter_terms( lang ); // initial filter for category checklist | |
| 38 | + filter_pages( lang ); // initial filter for parent dropdown | |
| 42 | 39 | |
| 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 | - } | |
| 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 | + ); | |
| 51 | 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 | - } | |
| 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 | + ); | |
| 76 | 70 | } |
| 71 | + } | |
| 77 | 72 | |
| 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 | - } | |
| 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 | + ); | |
| 96 | 88 | } |
| 97 | 89 | } |
| 98 | - ); | |
| 99 | - } | |
| 100 | -); | |
| 90 | + } | |
| 91 | + ); | |
| 92 | +})( jQuery ); | |
| 101 | 93 | |
| 102 | 94 | /** |
| 103 | 95 | * Update rows of translated posts when the language is modified in quick edit |
| 104 | 96 | * Acts on ajaxSuccess event |
| 105 | 97 | */ |
| 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 | - ); | |
| 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 | + ); | |
| 118 | 109 | |
| 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 | - }; | |
| 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 | + }; | |
| 127 | 118 | |
| 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 | - } | |
| 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 | + $( "#post-" + this.supplemental.post_id ).replaceWith( this.data ); | |
| 144 | 131 | } |
| 145 | - ); | |
| 146 | - } | |
| 132 | + } | |
| 133 | + ); | |
| 147 | 134 | } |
| 148 | - ); | |
| 149 | - } | |
| 135 | + } | |
| 136 | + ); | |
| 137 | + } | |
| 150 | 138 | |
| 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 | - } | |
| 139 | + if ( 'string' == typeof( settings.data ) ) { // Need to check the type due to block editor sometime sending FormData objects | |
| 140 | + var data = wpAjax.unserialize( settings.data ); // what were the data sent by the ajax request? | |
| 141 | + if ( 'undefined' != typeof( data['action'] ) && 'inline-save' == data['action'] ) { | |
| 142 | + update_rows( data['post_ID'] ); | |
| 156 | 143 | } |
| 157 | 144 | } |
| 158 | - ); | |
| 159 | - } | |
| 160 | -); | |
| 145 | + } | |
| 146 | + ); | |
| 147 | +})( jQuery ); | |
| 161 | 148 | |
| 162 | 149 | /** |
| 163 | 150 | * Media list table |
| 164 | 151 | * When clicking on attach link, filters find post list per media language |
| 165 | 152 | */ |
| 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 | - } | |
| 153 | +(function( $ ){ | |
| 154 | + $.ajaxPrefilter( | |
| 155 | + function ( options, originalOptions, jqXHR ) { | |
| 156 | + if ( 'string' === typeof options.data && -1 !== options.data.indexOf( 'action=find_posts' ) ) { | |
| 157 | + options.data = 'pll_post_id=' + $( '#affected' ).val() + '&' + options.data; | |
| 173 | 158 | } |
| 174 | - ); | |
| 175 | - } | |
| 176 | -); | |
| 159 | + } | |
| 160 | + ); | |
| 161 | +})( jQuery ); | |