| 1 |
// quick edit |
| 2 |
(function( $ ) { |
| 3 |
$( document ).bind( 'DOMNodeInserted', function( e ) { |
| 4 |
var t = $( e.target ); |
| 5 |
|
| 6 |
// WP inserts the quick edit from |
| 7 |
if ( 'inline-edit' == t.attr( 'id' ) ) { |
| 8 |
var term_id = t.prev().attr( 'id' ).replace( "tag-", "" ); |
| 9 |
|
| 10 |
if ( term_id > 0 ) { |
| 11 |
// language dropdown |
| 12 |
var select = t.find( ':input[name="inline_lang_choice"]' ); |
| 13 |
var lang = $( '#lang_' + term_id ).html(); |
| 14 |
select.val( lang ); // populates the dropdown |
| 15 |
|
| 16 |
// disable the language dropdown for default categories |
| 17 |
var default_cat = $( '#default_cat_' + term_id ).html(); |
| 18 |
if ( term_id == default_cat ) { |
| 19 |
select.prop( 'disabled', true ); |
| 20 |
} |
| 21 |
} |
| 22 |
} |
| 23 |
}); |
| 24 |
})( jQuery ); |
| 25 |
|
| 26 |
|
| 27 |
// update rows of translated terms when adding / deleting a translation or when the language is modified in quick edit |
| 28 |
// acts on ajaxSuccess event |
| 29 |
(function( $ ) { |
| 30 |
$( document ).ajaxSuccess(function( event, xhr, settings ) { |
| 31 |
function update_rows( term_id ) { |
| 32 |
// collect old translations |
| 33 |
var translations = new Array; |
| 34 |
$( '.translation_' + term_id ).each(function() { |
| 35 |
translations.push( $( this ).parent().parent().attr( 'id' ).substring( 4 ) ); |
| 36 |
}); |
| 37 |
|
| 38 |
var data = { |
| 39 |
action: 'pll_update_term_rows', |
| 40 |
term_id: term_id, |
| 41 |
translations: translations.join( ',' ), |
| 42 |
taxonomy: $( "input[name='taxonomy']" ).val(), |
| 43 |
post_type: $( "input[name='post_type']" ).val(), |
| 44 |
screen: $( "input[name='screen']" ).val(), |
| 45 |
_pll_nonce: $( '#_pll_nonce' ).val() |
| 46 |
} |
| 47 |
|
| 48 |
// get the modified rows in ajax and update them |
| 49 |
$.post( ajaxurl, data, function( response ) { |
| 50 |
if ( response ) { |
| 51 |
var res = wpAjax.parseAjaxResponse( response, 'ajax-response' ); |
| 52 |
$.each( res.responses, function() { |
| 53 |
if ( 'row' == this.what ) { |
| 54 |
$( "#tag-" + this.supplemental.term_id ).replaceWith( this.data ); |
| 55 |
} |
| 56 |
}); |
| 57 |
} |
| 58 |
}); |
| 59 |
} |
| 60 |
|
| 61 |
var data = wpAjax.unserialize( settings.data ); // what were the data sent by the ajax request? |
| 62 |
if ( 'undefined' != typeof( data['action'] ) ) { |
| 63 |
switch ( data['action'] ) { |
| 64 |
// when adding a term, the new term_id is in the ajax response |
| 65 |
case 'add-tag': |
| 66 |
res = wpAjax.parseAjaxResponse( xhr.responseXML, 'ajax-response' ); |
| 67 |
$.each( res.responses, function() { |
| 68 |
if ( 'term' == this.what ) { |
| 69 |
update_rows( this.supplemental.term_id ); |
| 70 |
} |
| 71 |
}); |
| 72 |
|
| 73 |
// and also reset translations hidden input fields |
| 74 |
$( '.htr_lang' ).val( 0 ); |
| 75 |
break; |
| 76 |
|
| 77 |
// when deleting a term |
| 78 |
case 'delete-tag': |
| 79 |
update_rows( data['tag_ID'] ); |
| 80 |
break; |
| 81 |
|
| 82 |
// in case the language is modified in quick edit and breaks translations |
| 83 |
case 'inline-save-tax': |
| 84 |
update_rows( data['tax_ID'] ); |
| 85 |
break; |
| 86 |
} |
| 87 |
} |
| 88 |
}); |
| 89 |
})( jQuery ); |
| 90 |
|
| 91 |
jQuery( document ).ready(function( $ ) { |
| 92 |
// translations autocomplete input box |
| 93 |
function init_translations() { |
| 94 |
$( '.tr_lang' ).each(function(){ |
| 95 |
var tr_lang = $( this ).attr( 'id' ).substring( 8 ); |
| 96 |
var td = $( this ).parent().parent().siblings( '.pll-edit-column' ); |
| 97 |
|
| 98 |
$( this ).autocomplete({ |
| 99 |
minLength: 0, |
| 100 |
|
| 101 |
source: ajaxurl + '?action=pll_terms_not_translated' + |
| 102 |
'&term_language=' + $( '#term_lang_choice' ).val() + |
| 103 |
'&term_id=' + $( "input[name='tag_ID']" ).val() + |
| 104 |
'&taxonomy=' + $( "input[name='taxonomy']" ).val() + |
| 105 |
'&translation_language=' + tr_lang + |
| 106 |
'&post_type=' + typenow + |
| 107 |
'&_pll_nonce=' + $( '#_pll_nonce' ).val(), |
| 108 |
|
| 109 |
select: function( event, ui ) { |
| 110 |
$( '#htr_lang_' + tr_lang ).val( ui.item.id ); |
| 111 |
td.html( ui.item.link ); |
| 112 |
}, |
| 113 |
}); |
| 114 |
|
| 115 |
// when the input box is emptied |
| 116 |
$( this ).blur(function() { |
| 117 |
if ( ! $( this ).val() ) { |
| 118 |
$( '#htr_lang_' + tr_lang ).val( 0 ); |
| 119 |
td.html( td.siblings( '.hidden' ).children().clone() ); |
| 120 |
} |
| 121 |
}); |
| 122 |
}); |
| 123 |
} |
| 124 |
|
| 125 |
init_translations(); |
| 126 |
|
| 127 |
// ajax for changing the term's language |
| 128 |
$( '#term_lang_choice' ).change(function() { |
| 129 |
var value = $( this ).val(); |
| 130 |
var lang = $( this ).children( 'option[value="' + value + '"]' ).attr( 'lang' ); |
| 131 |
var dir = $( '.pll-translation-column > span[lang="' + lang + '"]' ).attr( 'dir' ); |
| 132 |
|
| 133 |
var data = { |
| 134 |
action: 'term_lang_choice', |
| 135 |
lang: value, |
| 136 |
from_tag: $( "input[name='from_tag']" ).val(), |
| 137 |
term_id: $( "input[name='tag_ID']" ).val(), |
| 138 |
taxonomy: $( "input[name='taxonomy']" ).val(), |
| 139 |
post_type: typenow, |
| 140 |
_pll_nonce: $( '#_pll_nonce' ).val() |
| 141 |
} |
| 142 |
|
| 143 |
$.post( ajaxurl, data, function( response ) { |
| 144 |
var res = wpAjax.parseAjaxResponse( response, 'ajax-response' ); |
| 145 |
$.each( res.responses, function() { |
| 146 |
switch ( this.what ) { |
| 147 |
case 'translations': // translations fields |
| 148 |
$( "#term-translations" ).html( this.data ); |
| 149 |
init_translations(); |
| 150 |
break; |
| 151 |
case 'parent': // parent dropdown list for hierarchical taxonomies |
| 152 |
$( '#parent' ).replaceWith( this.data ); |
| 153 |
break; |
| 154 |
case 'tag_cloud': // popular items |
| 155 |
$( '.tagcloud' ).replaceWith( this.data ); |
| 156 |
break; |
| 157 |
case 'flag': // flag in front of the select dropdown |
| 158 |
$( '.pll-select-flag' ).html( this.data ); |
| 159 |
break; |
| 160 |
} |
| 161 |
}); |
| 162 |
|
| 163 |
// Modifies the text direction |
| 164 |
$( 'body' ).removeClass( 'pll-dir-rtl' ).removeClass( 'pll-dir-ltr' ).addClass( 'pll-dir-' + dir ); |
| 165 |
}); |
| 166 |
}); |
| 167 |
}); |
| 168 |
|