PluginProbe
Polylang / 2.3
Polylang v2.3
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 +225 -134 2.82.3 View file →
@@ -1,161 +1,252 @@
1 -/**
2 - * @package Polylang
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
5 -/**
6 - * Tag suggest in quick edit
7 - */
11 +// overrides tagBox.get
8 12 (function( $ ){
9 - $.ajaxPrefilter(
10 - function( options, originalOptions, jqXHR ) {
11 - if ( 'string' === typeof options.data && -1 !== options.data.indexOf( 'action=ajax-tag-search' ) && ( lang = $( ':input[name="inline_lang_choice"]' ).val() ) ) {
12 - 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;
13 27 }
14 - }
15 - );
28 +
29 + r = $( '<div id="tagcloud-' + tax + '" class="the-tagcloud">' + r + '</div>' );
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 + }
16 45 })( jQuery );
17 46
18 -/**
19 - * Quick edit
20 - */
47 +// quick edit
21 48 (function( $ ) {
22 - $( document ).bind(
23 - 'DOMNodeInserted',
24 - function( e ) {
25 - var t = $( e.target );
49 + $( document ).bind( 'DOMNodeInserted', function( e ) {
50 + var t = $( e.target );
26 51
27 - // WP inserts the quick edit from
28 - if ( 'inline-edit' == t.attr( 'id' ) ) {
29 - 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-", "" );
30 55
31 - if ( post_id > 0 ) {
32 - // language dropdown
33 - var select = t.find( ':input[name="inline_lang_choice"]' );
34 - var lang = $( '#lang_' + post_id ).html();
35 - 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
36 61
37 - filter_terms( lang ); // initial filter for category checklist
38 - 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
39 64
40 - // modify category checklist an parent dropdown on language change
41 - select.change(
42 - function() {
43 - filter_terms( $( this ).val() );
44 - filter_pages( $( this ).val() );
45 - }
46 - );
47 - }
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 + });
48 70 }
71 + }
49 72
50 - // filter category checklist
51 - function filter_terms( lang ) {
52 - if ( "undefined" != typeof( pll_term_languages ) ) {
53 - $.each(
54 - pll_term_languages,
55 - function( lg, term_tax ) {
56 - $.each(
57 - term_tax,
58 - function( tax, terms ) {
59 - $.each(
60 - terms,
61 - function( i ) {
62 - id = '#' + tax + '-' + pll_term_languages[ lg ][ tax ][ i ];
63 - lang == lg ? $( id ).show() : $( id ).hide();
64 - }
65 - );
66 - }
67 - );
68 - }
69 - );
70 - }
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 + });
71 84 }
85 + }
72 86
73 - // filter parent page dropdown list
74 - function filter_pages( lang ) {
75 - if ( "undefined" != typeof( pll_page_languages ) ) {
76 - $.each(
77 - pll_page_languages,
78 - function( lg, pages ) {
79 - $.each(
80 - pages,
81 - function( i ) {
82 - v = $( '#post_parent option[value="' + pll_page_languages[ lg ][ i ] + '"]' );
83 - lang == lg ? v.show() : v.hide();
84 - }
85 - );
86 - }
87 - );
88 - }
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 + });
89 96 }
90 97 }
91 - );
98 + });
92 99 })( jQuery );
93 100
94 -/**
95 - * Update rows of translated posts when the language is modified in quick edit
96 - * Acts on ajaxSuccess event
97 - */
101 +// update rows of translated posts when the language is modified in quick edit
102 +// acts on ajaxSuccess event
98 103 (function( $ ) {
99 - $( document ).ajaxSuccess(
100 - function( event, xhr, settings ) {
101 - function update_rows( post_id ) {
102 - // collect old translations
103 - var translations = new Array();
104 - $( '.translation_' + post_id ).each(
105 - function() {
106 - translations.push( $( this ).parent().parent().attr( 'id' ).substring( 5 ) );
107 - }
108 - );
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 + });
109 111
110 - var data = {
111 - action: 'pll_update_post_rows',
112 - post_id: post_id,
113 - translations: translations.join( ',' ),
114 - post_type: $( "input[name='post_type']" ).val(),
115 - screen: $( "input[name='screen']" ).val(),
116 - _pll_nonce: $( "input[name='_inline_edit']" ).val() // reuse quick edit nonce
117 - };
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 + }
118 120
119 - // get the modified rows in ajax and update them
120 - $.post(
121 - ajaxurl,
122 - data,
123 - function( response ) {
124 - if ( response ) {
125 - var res = wpAjax.parseAjaxResponse( response, 'ajax-response' );
126 - $.each(
127 - res.responses,
128 - function() {
129 - if ( 'row' == this.what ) {
130 - $( "#post-" + this.supplemental.post_id ).replaceWith( this.data );
131 - }
132 - }
133 - );
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 );
134 128 }
135 - }
136 - );
137 - }
129 + });
130 + }
131 + });
132 + }
138 133
139 - if ( 'string' == typeof( settings.data ) ) { // Need to check the type due to block editor sometime sending FormData objects
140 - var data = wpAjax.unserialize( settings.data ); // what were the data sent by the ajax request?
141 - if ( 'undefined' != typeof( data['action'] ) && 'inline-save' == data['action'] ) {
142 - update_rows( data['post_ID'] );
143 - }
144 - }
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'] );
145 137 }
146 - );
138 + });
147 139 })( jQuery );
148 140
149 -/**
150 - * Media list table
151 - * When clicking on attach link, filters find post list per media language
152 - */
153 -(function( $ ){
154 - $.ajaxPrefilter(
155 - function ( options, originalOptions, jqXHR ) {
156 - if ( 'string' === typeof options.data && -1 !== options.data.indexOf( 'action=find_posts' ) ) {
157 - options.data = 'pll_post_id=' + $( '#affected' ).val() + '&' + options.data;
158 - }
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;
146 +
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() )
159 + );
160 + });
161 +
162 + // ajax for changing the post's language in the languages metabox
163 + $( '.post_lang_choice' ).change(function() {
164 + var value = $( this ).val();
165 + var lang = $( this ).children( 'option[value="' + value + '"]' ).attr( 'lang' );
166 + var dir = $( '.pll-translation-column > span[lang="' + lang + '"]' ).attr( 'dir' );
167 +
168 + var data = {
169 + action: 'post_lang_choice',
170 + lang: value,
171 + post_type: $( '#post_type' ).val(),
172 + taxonomies: taxonomies,
173 + post_id: $( '#post_ID' ).val(),
174 + _pll_nonce: $( '#_pll_nonce' ).val()
159 175 }
160 - );
161 -})( jQuery );
176 +
177 + $.post( ajaxurl, data , function( response ) {
178 + var res = wpAjax.parseAjaxResponse( response, 'ajax-response' );
179 + $.each( res.responses, function() {
180 + switch ( this.what ) {
181 + case 'translations': // translations fields
182 + $( '.translations' ).html( this.data );
183 + init_translations();
184 + break;
185 + case 'taxonomy': // categories metabox for posts
186 + var tax = this.data;
187 + $( '#' + tax + 'checklist' ).html( this.supplemental.all );
188 + $( '#' + tax + 'checklist-pop' ).html( this.supplemental.populars );
189 + $( '#new' + tax + '_parent' ).replaceWith( this.supplemental.dropdown );
190 + $( '#' + tax + '-lang' ).val( $( '.post_lang_choice' ).val() ); // hidden field
191 + break;
192 + case 'pages': // parent dropdown list for pages
193 + $( '#parent_id' ).html( this.data );
194 + break;
195 + case 'flag': // flag in front of the select dropdown
196 + $( '.pll-select-flag' ).html( this.data );
197 + break;
198 + case 'permalink': // Sample permalink
199 + var div = $( '#edit-slug-box' );
200 + if ( '-1' != this.data && div.children().length ) {
201 + div.html( this.data );
202 + }
203 + break;
204 + }
205 + });
206 +
207 + // modifies the language in the tag cloud
208 + $( '.tagcloud-link' ).each(function() {
209 + var id = $( this ).attr( 'id' );
210 + tagBox.get( id );
211 + });
212 +
213 + // Modifies the text direction
214 + $( 'body' ).removeClass( 'pll-dir-rtl' ).removeClass( 'pll-dir-ltr' ).addClass( 'pll-dir-' + dir );
215 + $( '#content_ifr' ).contents().find( 'html' ).attr( 'lang', lang ).attr( 'dir', dir );
216 + $( '#content_ifr' ).contents().find( 'body' ).attr( 'dir', dir );
217 + });
218 + });
219 +
220 + // translations autocomplete input box
221 + function init_translations() {
222 + $( '.tr_lang' ).each(function(){
223 + var tr_lang = $( this ).attr( 'id' ).substring( 8 );
224 + var td = $( this ).parent().parent().siblings( '.pll-edit-column' );
225 +
226 + $( this ).autocomplete({
227 + minLength: 0,
228 +
229 + source: ajaxurl + '?action=pll_posts_not_translated' +
230 + '&post_language=' + $( '.post_lang_choice' ).val() +
231 + '&translation_language=' + tr_lang +
232 + '&post_type=' + $( '#post_type' ).val() +
233 + '&_pll_nonce=' + $( '#_pll_nonce' ).val(),
234 +
235 + select: function( event, ui ) {
236 + $( '#htr_lang_' + tr_lang ).val( ui.item.id );
237 + td.html( ui.item.link );
238 + },
239 + });
240 +
241 + // when the input box is emptied
242 + $( this ).blur(function() {
243 + if ( ! $( this ).val() ) {
244 + $( '#htr_lang_' + tr_lang ).val( 0 );
245 + td.html( td.siblings( '.hidden' ).children().clone() );
246 + }
247 + });
248 + });
249 + }
250 +
251 + init_translations();
252 +});