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