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