PluginProbe
Polylang / 2.7.1
Polylang v2.7.1
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
polylang / js / term.js

term.js in Polylang 2.7.1, at js/term.js

204 lines 6.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 );
204