| 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 ); |
| 9 |
|
| 10 |
// quick edit |
| 11 |
(function( $ ) { |
| 12 |
$( document ).bind( 'DOMNodeInserted', function( e ) { |
| 13 |
var t = $( e.target ); |
| 14 |
|
| 15 |
// WP inserts the quick edit from |
| 16 |
if ( 'inline-edit' == t.attr( 'id' ) ) { |
| 17 |
var post_id = t.prev().attr( 'id' ).replace( "post-", "" ); |
| 18 |
|
| 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 |
| 24 |
|
| 25 |
filter_terms( lang ); // initial filter for category checklist |
| 26 |
filter_pages( lang ); // initial filter for parent dropdown |
| 27 |
|
| 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 |
} |
| 35 |
|
| 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 |
} |
| 49 |
|
| 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 |
}); |
| 59 |
} |
| 60 |
} |
| 61 |
}); |
| 62 |
})( jQuery ); |
| 63 |
|
| 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 |
}); |
| 74 |
|
| 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 |
} |
| 83 |
|
| 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 ); |
| 91 |
} |
| 92 |
}); |
| 93 |
} |
| 94 |
}); |
| 95 |
} |
| 96 |
|
| 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'] ); |
| 101 |
} |
| 102 |
} |
| 103 |
}); |
| 104 |
})( jQuery ); |
| 105 |
|