| @@ -1,16 +1,13 @@ | ||
| 1 | 1 | /** |
| 2 | 2 | * Tag suggest in quick edit |
| 3 | 3 | */ |
| 4 | - | |
| 5 | 4 | (function( $ ){ |
| 6 | - $.ajaxPrefilter( | |
| 7 | - function( options, originalOptions, jqXHR ) { | |
| 8 | - if ( 'string' === typeof options.data && -1 !== options.data.indexOf( 'action=ajax-tag-search' ) && ( lang = $( ':input[name="inline_lang_choice"]' ).val() ) ) { | |
| 9 | - options.data = 'lang=' + lang + '&' + options.data; | |
| 10 | - } | |
| 5 | + $.ajaxPrefilter(function( options, originalOptions, jqXHR ) { | |
| 6 | + if ( 'string' === typeof options.data && -1 !== options.data.indexOf( 'action=ajax-tag-search' ) && ( lang = $( ':input[name="inline_lang_choice"]' ).val() ) ) { | |
| 7 | + options.data = 'lang=' + lang + '&' + options.data; | |
| 11 | 8 | } |
| 12 | - ); | |
| 9 | + }); | |
| 13 | 10 | })( jQuery ); |
| 14 | 11 | |
| 15 | 12 | /** |
| 16 | 13 | * Quick edit |
| @@ -15,78 +12,58 @@ | ||
| 15 | 12 | /** |
| 16 | 13 | * Quick edit |
| 17 | 14 | */ |
| 18 | 15 | (function( $ ) { |
| 19 | - $( document ).bind( | |
| 20 | - 'DOMNodeInserted', | |
| 21 | - function( e ) { | |
| 22 | - var t = $( e.target ); | |
| 16 | + $( document ).bind( 'DOMNodeInserted', function( e ) { | |
| 17 | + var t = $( e.target ); | |
| 23 | 18 | |
| 24 | - // WP inserts the quick edit from | |
| 25 | - if ( 'inline-edit' == t.attr( 'id' ) ) { | |
| 26 | - var post_id = t.prev().attr( 'id' ).replace( "post-", "" ); | |
| 19 | + // WP inserts the quick edit from | |
| 20 | + if ( 'inline-edit' == t.attr( 'id' ) ) { | |
| 21 | + var post_id = t.prev().attr( 'id' ).replace( "post-", "" ); | |
| 27 | 22 | |
| 28 | - if ( post_id > 0 ) { | |
| 29 | - // language dropdown | |
| 30 | - var select = t.find( ':input[name="inline_lang_choice"]' ); | |
| 31 | - var lang = $( '#lang_' + post_id ).html(); | |
| 32 | - select.val( lang ); // populates the dropdown | |
| 23 | + if ( post_id > 0 ) { | |
| 24 | + // language dropdown | |
| 25 | + var select = t.find( ':input[name="inline_lang_choice"]' ); | |
| 26 | + var lang = $( '#lang_' + post_id ).html(); | |
| 27 | + select.val( lang ); // populates the dropdown | |
| 33 | 28 | |
| 34 | - filter_terms( lang ); // initial filter for category checklist | |
| 35 | - filter_pages( lang ); // initial filter for parent dropdown | |
| 29 | + filter_terms( lang ); // initial filter for category checklist | |
| 30 | + filter_pages( lang ); // initial filter for parent dropdown | |
| 36 | 31 | |
| 37 | - // modify category checklist an parent dropdown on language change | |
| 38 | - select.change( | |
| 39 | - function() { | |
| 40 | - filter_terms( $( this ).val() ); | |
| 41 | - filter_pages( $( this ).val() ); | |
| 42 | - } | |
| 43 | - ); | |
| 44 | - } | |
| 32 | + // modify category checklist an parent dropdown on language change | |
| 33 | + select.change(function() { | |
| 34 | + filter_terms( $( this ).val() ); | |
| 35 | + filter_pages( $( this ).val() ); | |
| 36 | + }); | |
| 45 | 37 | } |
| 38 | + } | |
| 46 | 39 | |
| 47 | - // filter category checklist | |
| 48 | - function filter_terms( lang ) { | |
| 49 | - if ( "undefined" != typeof( pll_term_languages ) ) { | |
| 50 | - $.each( | |
| 51 | - pll_term_languages, | |
| 52 | - function( lg, term_tax ) { | |
| 53 | - $.each( | |
| 54 | - term_tax, | |
| 55 | - function( tax, terms ) { | |
| 56 | - $.each( | |
| 57 | - terms, | |
| 58 | - function( i ) { | |
| 59 | - id = '#' + tax + '-' + pll_term_languages[ lg ][ tax ][ i ]; | |
| 60 | - lang == lg ? $( id ).show() : $( id ).hide(); | |
| 61 | - } | |
| 62 | - ); | |
| 63 | - } | |
| 64 | - ); | |
| 65 | - } | |
| 66 | - ); | |
| 67 | - } | |
| 40 | + // filter category checklist | |
| 41 | + function filter_terms( lang ) { | |
| 42 | + if ( "undefined" != typeof( pll_term_languages ) ) { | |
| 43 | + $.each( pll_term_languages, function( lg, term_tax ) { | |
| 44 | + $.each( term_tax, function( tax, terms ) { | |
| 45 | + $.each( terms, function( i ) { | |
| 46 | + id = '#' + tax + '-' + pll_term_languages[ lg ][ tax ][ i ]; | |
| 47 | + lang == lg ? $( id ).show() : $( id ).hide(); | |
| 48 | + }); | |
| 49 | + }); | |
| 50 | + }); | |
| 68 | 51 | } |
| 52 | + } | |
| 69 | 53 | |
| 70 | - // filter parent page dropdown list | |
| 71 | - function filter_pages( lang ) { | |
| 72 | - if ( "undefined" != typeof( pll_page_languages ) ) { | |
| 73 | - $.each( | |
| 74 | - pll_page_languages, | |
| 75 | - function( lg, pages ) { | |
| 76 | - $.each( | |
| 77 | - pages, | |
| 78 | - function( i ) { | |
| 79 | - v = $( '#post_parent option[value="' + pll_page_languages[ lg ][ i ] + '"]' ); | |
| 80 | - lang == lg ? v.show() : v.hide(); | |
| 81 | - } | |
| 82 | - ); | |
| 83 | - } | |
| 84 | - ); | |
| 85 | - } | |
| 54 | + // filter parent page dropdown list | |
| 55 | + function filter_pages( lang ) { | |
| 56 | + if ( "undefined" != typeof( pll_page_languages ) ) { | |
| 57 | + $.each( pll_page_languages, function( lg, pages ) { | |
| 58 | + $.each( pages, function( i ) { | |
| 59 | + v = $( '#post_parent option[value="' + pll_page_languages[ lg ][ i ] + '"]' ); | |
| 60 | + lang == lg ? v.show() : v.hide(); | |
| 61 | + }); | |
| 62 | + }); | |
| 86 | 63 | } |
| 87 | 64 | } |
| 88 | - ); | |
| 65 | + }); | |
| 89 | 66 | })( jQuery ); |
| 90 | 67 | |
| 91 | 68 | /** |
| 92 | 69 | * Update rows of translated posts when the language is modified in quick edit |
| @@ -92,56 +69,45 @@ | ||
| 92 | 69 | * Update rows of translated posts when the language is modified in quick edit |
| 93 | 70 | * Acts on ajaxSuccess event |
| 94 | 71 | */ |
| 95 | 72 | (function( $ ) { |
| 96 | - $( document ).ajaxSuccess( | |
| 97 | - function( event, xhr, settings ) { | |
| 98 | - function update_rows( post_id ) { | |
| 99 | - // collect old translations | |
| 100 | - var translations = new Array(); | |
| 101 | - $( '.translation_' + post_id ).each( | |
| 102 | - function() { | |
| 103 | - translations.push( $( this ).parent().parent().attr( 'id' ).substring( 5 ) ); | |
| 104 | - } | |
| 105 | - ); | |
| 73 | + $( document ).ajaxSuccess(function( event, xhr, settings ) { | |
| 74 | + function update_rows( post_id ) { | |
| 75 | + // collect old translations | |
| 76 | + var translations = new Array; | |
| 77 | + $( '.translation_' + post_id ).each(function() { | |
| 78 | + translations.push( $( this ).parent().parent().attr( 'id' ).substring( 5 ) ); | |
| 79 | + }); | |
| 106 | 80 | |
| 107 | - var data = { | |
| 108 | - action: 'pll_update_post_rows', | |
| 109 | - post_id: post_id, | |
| 110 | - translations: translations.join( ',' ), | |
| 111 | - post_type: $( "input[name='post_type']" ).val(), | |
| 112 | - screen: $( "input[name='screen']" ).val(), | |
| 113 | - _pll_nonce: $( "input[name='_inline_edit']" ).val() // reuse quick edit nonce | |
| 114 | - }; | |
| 81 | + var data = { | |
| 82 | + action: 'pll_update_post_rows', | |
| 83 | + post_id: post_id, | |
| 84 | + translations: translations.join( ',' ), | |
| 85 | + post_type: $( "input[name='post_type']" ).val(), | |
| 86 | + screen: $( "input[name='screen']" ).val(), | |
| 87 | + _pll_nonce: $( "input[name='_inline_edit']" ).val() // reuse quick edit nonce | |
| 88 | + } | |
| 115 | 89 | |
| 116 | - // get the modified rows in ajax and update them | |
| 117 | - $.post( | |
| 118 | - ajaxurl, | |
| 119 | - data, | |
| 120 | - function( response ) { | |
| 121 | - if ( response ) { | |
| 122 | - var res = wpAjax.parseAjaxResponse( response, 'ajax-response' ); | |
| 123 | - $.each( | |
| 124 | - res.responses, | |
| 125 | - function() { | |
| 126 | - if ( 'row' == this.what ) { | |
| 127 | - $( "#post-" + this.supplemental.post_id ).replaceWith( this.data ); | |
| 128 | - } | |
| 129 | - } | |
| 130 | - ); | |
| 90 | + // get the modified rows in ajax and update them | |
| 91 | + $.post( ajaxurl, data, function( response ) { | |
| 92 | + if ( response ) { | |
| 93 | + var res = wpAjax.parseAjaxResponse( response, 'ajax-response' ); | |
| 94 | + $.each( res.responses, function() { | |
| 95 | + if ( 'row' == this.what ) { | |
| 96 | + $( "#post-" + this.supplemental.post_id ).replaceWith( this.data ); | |
| 131 | 97 | } |
| 132 | - } | |
| 133 | - ); | |
| 134 | - } | |
| 98 | + }); | |
| 99 | + } | |
| 100 | + }); | |
| 101 | + } | |
| 135 | 102 | |
| 136 | - if ( 'string' == typeof( settings.data ) ) { // Need to check the type due to block editor sometime sending FormData objects | |
| 137 | - var data = wpAjax.unserialize( settings.data ); // what were the data sent by the ajax request? | |
| 138 | - if ( 'undefined' != typeof( data['action'] ) && 'inline-save' == data['action'] ) { | |
| 139 | - update_rows( data['post_ID'] ); | |
| 140 | - } | |
| 103 | + if ( 'string' == typeof( settings.data ) ) { // Need to check the type due to block editor sometime sending FormData objects | |
| 104 | + var data = wpAjax.unserialize( settings.data ); // what were the data sent by the ajax request? | |
| 105 | + if ( 'undefined' != typeof( data['action'] ) && 'inline-save' == data['action'] ) { | |
| 106 | + update_rows( data['post_ID'] ); | |
| 141 | 107 | } |
| 142 | 108 | } |
| 143 | - ); | |
| 109 | + }); | |
| 144 | 110 | })( jQuery ); |
| 145 | 111 | |
| 146 | 112 | /** |
| 147 | 113 | * Media list table |
| @@ -147,91 +113,62 @@ | ||
| 147 | 113 | * Media list table |
| 148 | 114 | * When clicking on attach link, filters find post list per media language |
| 149 | 115 | */ |
| 150 | 116 | (function( $ ){ |
| 151 | - $.ajaxPrefilter( | |
| 152 | - function ( options, originalOptions, jqXHR ) { | |
| 153 | - if ( 'string' === typeof options.data && -1 !== options.data.indexOf( 'action=find_posts' ) ) { | |
| 154 | - options.data = 'pll_post_id=' + $( '#affected' ).val() + '&' + options.data; | |
| 155 | - } | |
| 117 | + $.ajaxPrefilter( function ( options, originalOptions, jqXHR ) { | |
| 118 | + if ( 'string' === typeof options.data && -1 !== options.data.indexOf( 'action=find_posts' ) ) { | |
| 119 | + options.data = 'pll_post_id=' + $( '#affected' ).val() + '&' + options.data; | |
| 156 | 120 | } |
| 157 | - ); | |
| 158 | -})( jQuery ); | |
| 121 | + }); | |
| 122 | +})( jQuery ) | |
| 159 | 123 | |
| 124 | + | |
| 160 | 125 | /** |
| 161 | 126 | * Bulk translate |
| 162 | 127 | */ |
| 163 | -jQuery( document ).ready( | |
| 164 | - function( $ ) { | |
| 165 | - var t = this; | |
| 128 | +jQuery( document ).ready( function( $ ) { | |
| 129 | + var t = this; | |
| 166 | 130 | |
| 167 | - $( '.editinline' ).click( | |
| 168 | - function(){ | |
| 169 | - $( '#pll-translate' ).find( '.cancel' ).click(); // Close the form on quick edit | |
| 170 | - } | |
| 171 | - ); | |
| 131 | + $( '.editinline' ).click( function(){ | |
| 132 | + $( '#pll-translate' ).find( '.cancel' ).click(); // Close the form on quick edit | |
| 133 | + } ); | |
| 172 | 134 | |
| 173 | - $( '#doaction, #doaction2' ).click( | |
| 174 | - function( e ){ | |
| 175 | - t.whichBulkButtonId = $( this ).attr( 'id' ); | |
| 176 | - var n = t.whichBulkButtonId.substr( 2 ); | |
| 135 | + $( '#doaction, #doaction2' ).click( function( e ){ | |
| 136 | + t.whichBulkButtonId = $( this ).attr( 'id' ); | |
| 137 | + var n = t.whichBulkButtonId.substr( 2 ); | |
| 177 | 138 | |
| 178 | - if ( 'pll_translate' === $( 'select[name="' + n + '"]' ).val() ) { | |
| 179 | - e.preventDefault(); | |
| 139 | + if ( 'pll_translate' === $( 'select[name="' + n + '"]' ).val() ) { | |
| 140 | + e.preventDefault(); | |
| 180 | 141 | |
| 181 | - if ( typeof inlineEditPost !== 'undefined' ) { // Not available for media. | |
| 182 | - inlineEditPost.revert(); // Close Bulk edit and Quick edit if open. | |
| 183 | - } | |
| 142 | + if ( typeof inlineEditPost !== 'undefined' ) { // Not available for media. | |
| 143 | + inlineEditPost.revert(); // Close Bulk edit and Quick edit if open. | |
| 144 | + } | |
| 184 | 145 | |
| 185 | - $( '#pll-translate td' ).attr( 'colspan', $( 'th:visible, td:visible', '.widefat:first thead' ).length ); | |
| 186 | - $( 'table.widefat tbody' ).prepend( $( '#pll-translate' ) ).prepend( '<tr class="hidden"></tr>' ); // The hidden tr allows to keep the background color | |
| 187 | - } else { | |
| 188 | - $( '#pll-translate' ).find( '.cancel' ).click(); | |
| 189 | - } | |
| 190 | - } | |
| 191 | - ); | |
| 146 | + $( '#pll-translate td' ).attr( 'colspan', $( 'th:visible, td:visible', '.widefat:first thead' ).length ); | |
| 147 | + $( 'table.widefat tbody' ).prepend( $( '#pll-translate' ) ).prepend( '<tr class="hidden"></tr>' ); // The hidden tr allows to keep the background color | |
| 148 | + } else { | |
| 149 | + $( '#pll-translate' ).find( '.cancel' ).click(); // Close the form on any other bulk action | |
| 150 | + } | |
| 151 | + } ); | |
| 192 | 152 | |
| 193 | - // Cancel | |
| 194 | - $( '#pll-translate' ).on( | |
| 195 | - 'click', | |
| 196 | - '.cancel', | |
| 197 | - function(){ | |
| 198 | - // Close the form on any other bulk action | |
| 199 | - $( '#pll-translate' ).siblings( '.hidden' ).remove(); | |
| 200 | - // #pll-translate is built and come from server side and is well escaped when necessary | |
| 201 | - $( '#pll-bulk-translate' ).append( $( '#pll-translate' ) ); //phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.append | |
| 153 | + // Cancel | |
| 154 | + $( '#pll-translate' ).on( 'click', '.cancel', function(){ | |
| 155 | + $( '#pll-translate' ).siblings( '.hidden' ).remove(); | |
| 156 | + $( '#pll-bulk-translate' ).append( $( '#pll-translate' ) ); | |
| 202 | 157 | |
| 203 | - // Move focus back to the Bulk Action button that was activated. | |
| 204 | - $( '#' + t.whichBulkButtonId ).focus(); | |
| 205 | - } | |
| 206 | - ); | |
| 158 | + // Move focus back to the Bulk Action button that was activated. | |
| 159 | + $( '#' + t.whichBulkButtonId ).focus(); | |
| 160 | + } ); | |
| 207 | 161 | |
| 208 | - // Act when pressing enter or esc | |
| 209 | - $( '#pll-translate' ).keydown( | |
| 210 | - function( event ){ | |
| 211 | - if ( 13 === event.keyCode && ! $( event.target ).hasClass( 'cancel' ) ) { | |
| 212 | - event.preventDefault(); | |
| 213 | - $( this ).find( 'input[type=submit]' ).click(); | |
| 214 | - } | |
| 215 | - if ( 27 === event.keyCode ) { | |
| 216 | - event.preventDefault(); | |
| 217 | - $( this ).find( '.cancel' ).click(); | |
| 218 | - } | |
| 219 | - } | |
| 220 | - ); | |
| 162 | + // Act when pressing enter or esc | |
| 163 | + $( '#pll-translate' ).keydown( function( event ){ | |
| 164 | + if ( 13 === event.keyCode && ! $( event.target ).hasClass( 'cancel' ) ) { | |
| 165 | + event.preventDefault(); | |
| 166 | + $( this ).find( 'input[type=submit]' ).click(); | |
| 167 | + } | |
| 221 | 168 | |
| 222 | - // Clean DOM in case of file download | |
| 223 | - $( '#posts-filter' ).on( | |
| 224 | - 'submit', | |
| 225 | - function() { | |
| 226 | - $( '.settings-error' ).remove(); | |
| 227 | - setTimeout( | |
| 228 | - function() { | |
| 229 | - $( 'input[type=checkbox]:checked' ).attr( 'checked', false ); | |
| 230 | - $( '#pll-translate' ).find( '.cancel' ).trigger( 'click' ); | |
| 231 | - }, | |
| 232 | - 500 | |
| 233 | - ); | |
| 234 | - } | |
| 235 | - ); | |
| 236 | - } | |
| 237 | -); | |
| 169 | + if ( 27 === event.keyCode ) { | |
| 170 | + event.preventDefault(); | |
| 171 | + $( this ).find( '.cancel' ).click(); | |
| 172 | + } | |
| 173 | + } ); | |
| 174 | +} ); | |