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