PluginProbe
Polylang / 2.0.12
Polylang v2.0.12
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/post.js +204 -198 2.7.32.0.12 View file →
@@ -1,237 +1,243 @@
1 -/**
2 - * Tag suggest in quick edit
3 - */
1 +// tag suggest
2 +// valid for both tag metabox and quick edit
3 +(function( $ ){
4 + $.ajaxPrefilter(function( options, originalOptions, jqXHR ) {
5 + if ( 'string' === typeof options.data && ( -1 !== options.url.indexOf( 'action=ajax-tag-search' ) || -1 !== options.data.indexOf( 'action=ajax-tag-search' ) ) && ( ( lang = $( '.post_lang_choice' ).val() ) || ( lang = $( ':input[name="inline_lang_choice"]' ).val() ) ) ) {
6 + options.data = 'lang=' + lang + '&' + options.data;
7 + }
8 + });
9 +})( jQuery );
4 10
11 +// overrides tagBox.get
5 12 (function( $ ){
6 - $.ajaxPrefilter(
7 - function( options, originalOptions, jqXHR ) {
8 - if ( 'string' === typeof options.data && -1 !== options.data.indexOf( 'action=ajax-tag-search' ) && ( lang = $( ':input[name="inline_lang_choice"]' ).val() ) ) {
9 - options.data = 'lang=' + lang + '&' + options.data;
13 + // overrides function to add the language
14 + tagBox.get = function( id ) {
15 + var tax = id.substr( id.indexOf( '-' ) + 1 );
16 +
17 + // add the language in the $_POST variable
18 + var data = {
19 + action: 'get-tagcloud',
20 + lang: $( '.post_lang_choice' ).val(),
21 + tax: tax
22 + }
23 +
24 + $.post( ajaxurl, data, function( r, stat ) {
25 + if ( 0 == r || 'success' != stat ) {
26 + r = wpAjax.broken;
10 27 }
11 - }
12 - );
28 +
29 + r = $( '<p id="tagcloud-' + tax + '" class="the-tagcloud">' + r + '</p>' );
30 + $( 'a', r ).click(function(){
31 + tagBox.flushTags( $( this ).closest( '.inside' ).children( '.tagsdiv' ), this );
32 + return false;
33 + });
34 +
35 + // add an if else condition to allow modifying the tags outputed when switching the language
36 + if ( v = $( '.the-tagcloud' ).css( 'display' ) ) {
37 + $( '.the-tagcloud' ).replaceWith( r );
38 + $( '.the-tagcloud' ).css( 'display', v );
39 + }
40 + else {
41 + $( '#' + id ).after( r );
42 + }
43 + });
44 + }
13 45 })( jQuery );
14 46
15 -/**
16 - * Quick edit
17 - */
47 +// quick edit
18 48 (function( $ ) {
19 - $( document ).bind(
20 - 'DOMNodeInserted',
21 - function( e ) {
22 - var t = $( e.target );
49 + $( document ).bind( 'DOMNodeInserted', function( e ) {
50 + var t = $( e.target );
23 51
24 - // WP inserts the quick edit from
25 - if ( 'inline-edit' == t.attr( 'id' ) ) {
26 - var post_id = t.prev().attr( 'id' ).replace( "post-", "" );
52 + // WP inserts the quick edit from
53 + if ( 'inline-edit' == t.attr( 'id' ) ) {
54 + var post_id = t.prev().attr( 'id' ).replace( "post-", "" );
27 55
28 - if ( post_id > 0 ) {
29 - // language dropdown
30 - var select = t.find( ':input[name="inline_lang_choice"]' );
31 - var lang = $( '#lang_' + post_id ).html();
32 - select.val( lang ); // populates the dropdown
56 + if ( post_id > 0 ) {
57 + // language dropdown
58 + var select = t.find( ':input[name="inline_lang_choice"]' );
59 + var lang = $( '#lang_' + post_id ).html();
60 + select.val( lang ); // populates the dropdown
33 61
34 - filter_terms( lang ); // initial filter for category checklist
35 - filter_pages( lang ); // initial filter for parent dropdown
62 + filter_terms( lang ); // initial filter for category checklist
63 + filter_pages( lang ); // initial filter for parent dropdown
36 64
37 - // modify category checklist an parent dropdown on language change
38 - select.change(
39 - function() {
40 - filter_terms( $( this ).val() );
41 - filter_pages( $( this ).val() );
42 - }
43 - );
44 - }
65 + // modify category checklist an parent dropdown on language change
66 + select.change(function() {
67 + filter_terms( $( this ).val() );
68 + filter_pages( $( this ).val() );
69 + });
45 70 }
71 + }
46 72
47 - // filter category checklist
48 - function filter_terms( lang ) {
49 - if ( "undefined" != typeof( pll_term_languages ) ) {
50 - $.each(
51 - pll_term_languages,
52 - function( lg, term_tax ) {
53 - $.each(
54 - term_tax,
55 - function( tax, terms ) {
56 - $.each(
57 - terms,
58 - function( i ) {
59 - id = '#' + tax + '-' + pll_term_languages[ lg ][ tax ][ i ];
60 - lang == lg ? $( id ).show() : $( id ).hide();
61 - }
62 - );
63 - }
64 - );
65 - }
66 - );
67 - }
73 + // filter category checklist
74 + function filter_terms( lang ) {
75 + if ( "undefined" != typeof( pll_term_languages ) ) {
76 + $.each( pll_term_languages, function( lg, term_tax ) {
77 + $.each( term_tax, function( tax, terms ) {
78 + $.each( terms, function( i ) {
79 + id = '#' + tax + '-' + pll_term_languages[ lg ][ tax ][ i ];
80 + lang == lg ? $( id ).show() : $( id ).hide();
81 + });
82 + });
83 + });
68 84 }
85 + }
69 86
70 - // filter parent page dropdown list
71 - function filter_pages( lang ) {
72 - if ( "undefined" != typeof( pll_page_languages ) ) {
73 - $.each(
74 - pll_page_languages,
75 - function( lg, pages ) {
76 - $.each(
77 - pages,
78 - function( i ) {
79 - v = $( '#post_parent option[value="' + pll_page_languages[ lg ][ i ] + '"]' );
80 - lang == lg ? v.show() : v.hide();
81 - }
82 - );
83 - }
84 - );
85 - }
87 + // filter parent page dropdown list
88 + function filter_pages( lang ) {
89 + if ( "undefined" != typeof( pll_page_languages ) ) {
90 + $.each( pll_page_languages, function( lg, pages ) {
91 + $.each( pages, function( i ) {
92 + v = $( '#post_parent option[value="' + pll_page_languages[ lg ][ i ] + '"]' );
93 + lang == lg ? v.show() : v.hide();
94 + });
95 + });
86 96 }
87 97 }
88 - );
98 + });
89 99 })( jQuery );
90 100
91 -/**
92 - * Update rows of translated posts when the language is modified in quick edit
93 - * Acts on ajaxSuccess event
94 - */
101 +// update rows of translated posts when the language is modified in quick edit
102 +// acts on ajaxSuccess event
95 103 (function( $ ) {
96 - $( document ).ajaxSuccess(
97 - function( event, xhr, settings ) {
98 - function update_rows( post_id ) {
99 - // collect old translations
100 - var translations = new Array();
101 - $( '.translation_' + post_id ).each(
102 - function() {
103 - translations.push( $( this ).parent().parent().attr( 'id' ).substring( 5 ) );
104 - }
105 - );
104 + $( document ).ajaxSuccess(function( event, xhr, settings ) {
105 + function update_rows( post_id ) {
106 + // collect old translations
107 + var translations = new Array;
108 + $( '.translation_' + post_id ).each(function() {
109 + translations.push( $( this ).parent().parent().attr( 'id' ).substring( 5 ) );
110 + });
106 111
107 - var data = {
108 - action: 'pll_update_post_rows',
109 - post_id: post_id,
110 - translations: translations.join( ',' ),
111 - post_type: $( "input[name='post_type']" ).val(),
112 - screen: $( "input[name='screen']" ).val(),
113 - _pll_nonce: $( "input[name='_inline_edit']" ).val() // reuse quick edit nonce
114 - };
112 + var data = {
113 + action: 'pll_update_post_rows',
114 + post_id: post_id,
115 + translations: translations.join( ',' ),
116 + post_type: $( "input[name='post_type']" ).val(),
117 + screen: $( "input[name='screen']" ).val(),
118 + _pll_nonce: $( "input[name='_inline_edit']" ).val() // reuse quick edit nonce
119 + }
115 120
116 - // get the modified rows in ajax and update them
117 - $.post(
118 - ajaxurl,
119 - data,
120 - function( response ) {
121 - if ( response ) {
122 - var res = wpAjax.parseAjaxResponse( response, 'ajax-response' );
123 - $.each(
124 - res.responses,
125 - function() {
126 - if ( 'row' == this.what ) {
127 - $( "#post-" + this.supplemental.post_id ).replaceWith( this.data );
128 - }
129 - }
130 - );
121 + // get the modified rows in ajax and update them
122 + $.post( ajaxurl, data, function( response ) {
123 + if ( response ) {
124 + var res = wpAjax.parseAjaxResponse( response, 'ajax-response' );
125 + $.each( res.responses, function() {
126 + if ( 'row' == this.what ) {
127 + $( "#post-" + this.supplemental.post_id ).replaceWith( this.data );
131 128 }
132 - }
133 - );
134 - }
135 -
136 - if ( 'string' == typeof( settings.data ) ) { // Need to check the type due to block editor sometime sending FormData objects
137 - var data = wpAjax.unserialize( settings.data ); // what were the data sent by the ajax request?
138 - if ( 'undefined' != typeof( data['action'] ) && 'inline-save' == data['action'] ) {
139 - update_rows( data['post_ID'] );
129 + });
140 130 }
141 - }
131 + });
142 132 }
143 - );
144 -})( jQuery );
145 133
146 -/**
147 - * Media list table
148 - * When clicking on attach link, filters find post list per media language
149 - */
150 -(function( $ ){
151 - $.ajaxPrefilter(
152 - function ( options, originalOptions, jqXHR ) {
153 - if ( 'string' === typeof options.data && -1 !== options.data.indexOf( 'action=find_posts' ) ) {
154 - options.data = 'pll_post_id=' + $( '#affected' ).val() + '&' + options.data;
155 - }
134 + var data = wpAjax.unserialize( settings.data ); // what were the data sent by the ajax request?
135 + if ( 'undefined' != typeof( data['action'] ) && 'inline-save' == data['action'] ) {
136 + update_rows( data['post_ID'] );
156 137 }
157 - );
138 + });
158 139 })( jQuery );
159 140
160 -/**
161 - * Bulk translate
162 - */
163 -jQuery( document ).ready(
164 - function( $ ) {
165 - var t = this;
141 +jQuery( document ).ready(function( $ ) {
142 + // collect taxonomies - code partly copied from WordPress
143 + var taxonomies = new Array();
144 + $( '.categorydiv' ).each(function(){
145 + var this_id = $( this ).attr( 'id' ), taxonomyParts, taxonomy;
166 146
167 - $( '.editinline' ).click(
168 - function(){
169 - $( '#pll-translate' ).find( '.cancel' ).click(); // Close the form on quick edit
170 - }
147 + taxonomyParts = this_id.split( '-' );
148 + taxonomyParts.shift();
149 + taxonomy = taxonomyParts.join( '-' );
150 + taxonomies.push( taxonomy ); // store the taxonomy for future use
151 +
152 + // add our hidden field in the new category form - for each hierarchical taxonomy
153 + // to set the language when creating a new category
154 + $( '#' + taxonomy + '-add-submit' ).before( $( '<input />' )
155 + .attr( 'type', 'hidden' )
156 + .attr( 'id', taxonomy + '-lang' )
157 + .attr( 'name', 'term_lang_choice' )
158 + .attr( 'value', $( '.post_lang_choice' ).val() )
171 159 );
160 + });
172 161
173 - $( '#doaction, #doaction2' ).click(
174 - function( e ){
175 - t.whichBulkButtonId = $( this ).attr( 'id' );
176 - var n = t.whichBulkButtonId.substr( 2 );
162 + // ajax for changing the post's language in the languages metabox
163 + $( '.post_lang_choice' ).change(function() {
164 + var data = {
165 + action: 'post_lang_choice',
166 + lang: $( this ).val(),
167 + post_type: $( '#post_type' ).val(),
168 + taxonomies: taxonomies,
169 + post_id: $( '#post_ID' ).val(),
170 + _pll_nonce: $( '#_pll_nonce' ).val()
171 + }
177 172
178 - if ( 'pll_translate' === $( 'select[name="' + n + '"]' ).val() ) {
179 - e.preventDefault();
173 + $.post( ajaxurl, data , function( response ) {
174 + var res = wpAjax.parseAjaxResponse( response, 'ajax-response' );
175 + $.each( res.responses, function() {
176 + switch ( this.what ) {
177 + case 'translations': // translations fields
178 + $( '.translations' ).html( this.data );
179 + init_translations();
180 + break;
181 + case 'taxonomy': // categories metabox for posts
182 + var tax = this.data;
183 + $( '#' + tax + 'checklist' ).html( this.supplemental.all );
184 + $( '#' + tax + 'checklist-pop' ).html( this.supplemental.populars );
185 + $( '#new' + tax + '_parent' ).replaceWith( this.supplemental.dropdown );
186 + $( '#' + tax + '-lang' ).val( $( '.post_lang_choice' ).val() ); // hidden field
187 + break;
188 + case 'pages': // parent dropdown list for pages
189 + $( '#parent_id' ).html( this.data );
190 + break;
191 + case 'flag': // flag in front of the select dropdown
192 + $( '.pll-select-flag' ).html( this.data );
193 + break;
194 + case 'permalink': // Sample permalink
195 + var div = $( '#edit-slug-box' );
196 + if ( '-1' != this.data && div.children().length ) {
197 + div.html( this.data );
198 + }
199 + break;
200 + }
201 + });
180 202
181 - if ( typeof inlineEditPost !== 'undefined' ) { // Not available for media.
182 - inlineEditPost.revert(); // Close Bulk edit and Quick edit if open.
183 - }
203 + // modifies the language in the tag cloud
204 + $( '.tagcloud-link' ).each(function() {
205 + var id = $( this ).attr( 'id' );
206 + tagBox.get( id );
207 + });
208 + });
209 + });
184 210
185 - $( '#pll-translate td' ).attr( 'colspan', $( 'th:visible, td:visible', '.widefat:first thead' ).length );
186 - $( 'table.widefat tbody' ).prepend( $( '#pll-translate' ) ).prepend( '<tr class="hidden"></tr>' ); // The hidden tr allows to keep the background color
187 - } else {
188 - $( '#pll-translate' ).find( '.cancel' ).click();
189 - }
190 - }
191 - );
211 + // translations autocomplete input box
212 + function init_translations() {
213 + $( '.tr_lang' ).each(function(){
214 + var tr_lang = $( this ).attr( 'id' ).substring( 8 );
215 + var td = $( this ).parent().siblings( '.pll-edit-column' );
192 216
193 - // Cancel
194 - $( '#pll-translate' ).on(
195 - 'click',
196 - '.cancel',
197 - function(){
198 - // Close the form on any other bulk action
199 - $( '#pll-translate' ).siblings( '.hidden' ).remove();
200 - // #pll-translate is built and come from server side and is well escaped when necessary
201 - $( '#pll-bulk-translate' ).append( $( '#pll-translate' ) ); //phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.append
217 + $( this ).autocomplete({
218 + minLength: 0,
202 219
203 - // Move focus back to the Bulk Action button that was activated.
204 - $( '#' + t.whichBulkButtonId ).focus();
205 - }
206 - );
220 + source: ajaxurl + '?action=pll_posts_not_translated' +
221 + '&post_language=' + $( '.post_lang_choice' ).val() +
222 + '&translation_language=' + tr_lang +
223 + '&post_type=' + $( '#post_type' ).val() +
224 + '&_pll_nonce=' + $( '#_pll_nonce' ).val(),
207 225
208 - // Act when pressing enter or esc
209 - $( '#pll-translate' ).keydown(
210 - function( event ){
211 - if ( 13 === event.keyCode && ! $( event.target ).hasClass( 'cancel' ) ) {
212 - event.preventDefault();
213 - $( this ).find( 'input[type=submit]' ).click();
226 + select: function( event, ui ) {
227 + $( '#htr_lang_' + tr_lang ).val( ui.item.id );
228 + td.html( ui.item.link );
229 + },
230 + });
231 +
232 + // when the input box is emptied
233 + $( this ).blur(function() {
234 + if ( ! $( this ).val() ) {
235 + $( '#htr_lang_' + tr_lang ).val( 0 );
236 + td.html( td.siblings( '.hidden' ).children().clone() );
214 237 }
215 - if ( 27 === event.keyCode ) {
216 - event.preventDefault();
217 - $( this ).find( '.cancel' ).click();
218 - }
219 - }
220 - );
238 + });
239 + });
240 + }
221 241
222 - // Clean DOM in case of file download
223 - $( '#posts-filter' ).on(
224 - 'submit',
225 - function() {
226 - $( '.settings-error' ).remove();
227 - setTimeout(
228 - function() {
229 - $( 'input[type=checkbox]:checked' ).attr( 'checked', false );
230 - $( '#pll-translate' ).find( '.cancel' ).trigger( 'click' );
231 - },
232 - 500
233 - );
234 - }
235 - );
236 - }
237 -);
242 + init_translations();
243 +});