update
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
var __webpack_exports__ = {};
|
||||
/**
|
||||
* @package Polylang
|
||||
*/
|
||||
@@ -7,10 +6,11 @@ var __webpack_exports__ = {};
|
||||
* Quick edit
|
||||
*/
|
||||
jQuery(
|
||||
function( $ ) {
|
||||
function ( $ ) {
|
||||
const handleQuickEditInsertion = ( mutationsList ) => {
|
||||
for ( const mutation of mutationsList ) {
|
||||
const form = mutation.addedNodes[0];
|
||||
const addedNodes = Array.from( mutation.addedNodes ).filter( el => el.nodeType === Node.ELEMENT_NODE )
|
||||
const form = addedNodes[0];
|
||||
if ( 0 < mutation.addedNodes.length && form.classList.contains( 'inline-edit-row' ) ) {
|
||||
// WordPress has inserted the quick edit form.
|
||||
const term_id = Number( form.id.substring( 5 ) );
|
||||
@@ -22,7 +22,7 @@ jQuery(
|
||||
select.value = lang; // Populates the dropdown with the post language.
|
||||
|
||||
// Disable the language dropdown for default categories.
|
||||
const default_cat = document.querySelector( `#default_cat_${term_id}` ).innerHTML;
|
||||
const default_cat = document.querySelector( `#default_cat_${term_id}` )?.innerHTML;
|
||||
if ( term_id == default_cat ) {
|
||||
select.disabled = true;
|
||||
}
|
||||
@@ -46,14 +46,14 @@ jQuery(
|
||||
* Acts on ajaxSuccess event.
|
||||
*/
|
||||
jQuery(
|
||||
function( $ ) {
|
||||
function ( $ ) {
|
||||
$( document ).ajaxSuccess(
|
||||
function( event, xhr, settings ) {
|
||||
function ( event, xhr, settings ) {
|
||||
function update_rows( term_id ) {
|
||||
// collect old translations
|
||||
var translations = new Array();
|
||||
$( '.translation_' + term_id ).each(
|
||||
function() {
|
||||
function () {
|
||||
translations.push( $( this ).parent().parent().attr( 'id' ).substring( 4 ) );
|
||||
}
|
||||
);
|
||||
@@ -72,13 +72,13 @@ jQuery(
|
||||
$.post(
|
||||
ajaxurl,
|
||||
data,
|
||||
function( response ) {
|
||||
function ( response ) {
|
||||
if ( response ) {
|
||||
// Target a non existing WP HTML id to avoid a conflict with WP ajax requests.
|
||||
var res = wpAjax.parseAjaxResponse( response, 'pll-ajax-response' );
|
||||
$.each(
|
||||
res.responses,
|
||||
function() {
|
||||
function () {
|
||||
if ( 'row' == this.what ) {
|
||||
// data is built with a call to WP_Terms_List_Table::single_row method
|
||||
// which uses internally other WordPress methods which escape correctly values.
|
||||
@@ -101,7 +101,7 @@ jQuery(
|
||||
res = wpAjax.parseAjaxResponse( xhr.responseXML, 'pll-ajax-response' );
|
||||
$.each(
|
||||
res.responses,
|
||||
function() {
|
||||
function () {
|
||||
if ( 'term' == this.what ) {
|
||||
update_rows( this.supplemental.term_id );
|
||||
}
|
||||
@@ -129,11 +129,11 @@ jQuery(
|
||||
);
|
||||
|
||||
jQuery(
|
||||
function( $ ) {
|
||||
function ( $ ) {
|
||||
// translations autocomplete input box
|
||||
function init_translations() {
|
||||
$( '.tr_lang' ).each(
|
||||
function(){
|
||||
function () {
|
||||
var tr_lang = $( this ).attr( 'id' ).substring( 8 );
|
||||
var td = $( this ).parent().parent().siblings( '.pll-edit-column' );
|
||||
|
||||
@@ -147,7 +147,7 @@ jQuery(
|
||||
'&translation_language=' + tr_lang +
|
||||
'&post_type=' + typenow +
|
||||
'&_pll_nonce=' + $( '#_pll_nonce' ).val(),
|
||||
select: function( event, ui ) {
|
||||
select: function ( event, ui ) {
|
||||
$( '#htr_lang_' + tr_lang ).val( ui.item.id );
|
||||
// ui.item.link is built and come from server side and is well escaped when necessary
|
||||
td.html( ui.item.link ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.html
|
||||
@@ -158,7 +158,7 @@ jQuery(
|
||||
// when the input box is emptied
|
||||
$( this ).on(
|
||||
'blur',
|
||||
function() {
|
||||
function () {
|
||||
if ( ! $( this ).val() ) {
|
||||
$( '#htr_lang_' + tr_lang ).val( 0 );
|
||||
// Value is retrieved from HTML already generated server side
|
||||
@@ -175,10 +175,10 @@ jQuery(
|
||||
// ajax for changing the term's language
|
||||
$( '#term_lang_choice' ).on(
|
||||
'change',
|
||||
function() {
|
||||
function () {
|
||||
var value = $( this ).val();
|
||||
var lang = $( this ).children( 'option[value="' + value + '"]' ).attr( 'lang' );
|
||||
var dir = $( '.pll-translation-column > span[lang="' + lang + '"]' ).attr( 'dir' );
|
||||
// The selected option in the dropdown list.
|
||||
const selectedOption = event.target;
|
||||
|
||||
var data = {
|
||||
action: 'term_lang_choice',
|
||||
@@ -193,12 +193,12 @@ jQuery(
|
||||
$.post(
|
||||
ajaxurl,
|
||||
data,
|
||||
function( response ) {
|
||||
function ( response ) {
|
||||
// Target a non existing WP HTML id to avoid a conflict with WP ajax requests.
|
||||
var res = wpAjax.parseAjaxResponse( response, 'pll-ajax-response' );
|
||||
$.each(
|
||||
res.responses,
|
||||
function() {
|
||||
function () {
|
||||
switch ( this.what ) {
|
||||
case 'translations': // translations fields
|
||||
// Data is built and come from server side and is well escaped when necessary
|
||||
@@ -221,12 +221,30 @@ jQuery(
|
||||
}
|
||||
);
|
||||
|
||||
// Modifies the text direction
|
||||
$( 'body' ).removeClass( 'pll-dir-rtl' ).removeClass( 'pll-dir-ltr' ).addClass( 'pll-dir-' + dir );
|
||||
// Creates an event once the language has been successfully changed.
|
||||
const onTermLangChoice = new CustomEvent(
|
||||
"onTermLangChoice",
|
||||
{
|
||||
detail: {
|
||||
lang: JSON.parse( selectedOption.options[selectedOption.options.selectedIndex].getAttribute( 'data-lang' ) )
|
||||
},
|
||||
}
|
||||
);
|
||||
document.dispatchEvent( onTermLangChoice );
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
// Listen to `onTermLangChoice` to perform actions after the language has been changed.
|
||||
document.addEventListener(
|
||||
'onTermLangChoice',
|
||||
( e ) => {
|
||||
// Modifies the text direction.
|
||||
let dir = e.detail.lang.is_rtl ? 'rtl' : 'ltr'
|
||||
$( 'body' ).removeClass( 'pll-dir-rtl' ).removeClass( 'pll-dir-ltr' ).addClass( 'pll-dir-' + dir );
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user