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/classic-editor.js +119 -167 2.8.2 → 2.5 View file →
@@ -1,17 +1,11 @@
1 -/**
2 - * @package Polylang
3 - */
4 -
5 1 // tag suggest in metabox
6 2 (function( $ ){
7 - $.ajaxPrefilter(
8 - function( options, originalOptions, jqXHR ) {
9 - if ( 'string' === typeof options.data && -1 !== options.url.indexOf( 'action=ajax-tag-search' ) && ( lang = $( '.post_lang_choice' ).val() ) ) {
10 - options.data = 'lang=' + lang + '&' + options.data;
11 - }
3 + $.ajaxPrefilter(function( options, originalOptions, jqXHR ) {
4 + if ( 'string' === typeof options.data && -1 !== options.url.indexOf( 'action=ajax-tag-search' ) && ( lang = $( '.post_lang_choice' ).val() ) ) {
5 + options.data = 'lang=' + lang + '&' + options.data;
12 6 }
13 - );
7 + });
14 8 })( jQuery );
15 9
16 10 // overrides tagBox.get
17 11 (function( $ ){
@@ -25,181 +19,139 @@
25 19 lang: $( '.post_lang_choice' ).val(),
26 20 tax: tax
27 21 }
28 22
29 - $.post(
30 - ajaxurl,
31 - data,
32 - function( r, stat ) {
33 - if ( 0 == r || 'success' != stat ) {
34 - r = wpAjax.broken;
35 - }
23 + $.post( ajaxurl, data, function( r, stat ) {
24 + if ( 0 == r || 'success' != stat ) {
25 + r = wpAjax.broken;
26 + }
36 27
37 - // @see code from WordPress core https://github.com/WordPress/WordPress/blob/5.2.2/wp-admin/js/tags-box.js#L291
38 - // @see wp_generate_tag_cloud function which generate the escaped HTML https://github.com/WordPress/WordPress/blob/a02b5cc2a8eecb8e076fbb7cf4de7bd2ec8a8eb1/wp-includes/category-template.php#L966-L975
39 - r = $( '<div />' ).addClass( 'the-tagcloud' ).attr( 'id', 'tagcloud-' + tax ).html( r ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.html
40 - $( 'a', r ).click(
41 - function(){
42 - tagBox.flushTags( $( this ).closest( '.inside' ).children( '.tagsdiv' ), this );
43 - return false;
44 - }
45 - );
28 + r = $( '<div id="tagcloud-' + tax + '" class="the-tagcloud">' + r + '</div>' );
29 + $( 'a', r ).click(function(){
30 + tagBox.flushTags( $( this ).closest( '.inside' ).children( '.tagsdiv' ), this );
31 + return false;
32 + });
46 33
47 - // add an if else condition to allow modifying the tags outputed when switching the language
48 - if ( v = $( '#tagcloud-' + tax ).css( 'display' ) ) {
49 - // See the comment above when r variable is created.
50 - $( '#tagcloud-' + tax ).replaceWith( r ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.replaceWith
51 - $( '#tagcloud-' + tax ).css( 'display', v );
52 - }
53 - else {
54 - // See the comment above when r variable is created.
55 - $( '#' + id ).after( r ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.after
56 - }
34 + // add an if else condition to allow modifying the tags outputed when switching the language
35 + if ( v = $( '.the-tagcloud' ).css( 'display' ) ) {
36 + $( '.the-tagcloud' ).replaceWith( r );
37 + $( '.the-tagcloud' ).css( 'display', v );
57 38 }
58 - );
39 + else {
40 + $( '#' + id ).after( r );
41 + }
42 + });
59 43 }
60 44 })( jQuery );
61 45
62 -jQuery( document ).ready(
63 - function( $ ) {
64 - // collect taxonomies - code partly copied from WordPress
65 - var taxonomies = new Array();
66 - $( '.categorydiv' ).each(
67 - function(){
68 - var this_id = $( this ).attr( 'id' ), taxonomyParts, taxonomy;
46 +jQuery( document ).ready(function( $ ) {
47 + // collect taxonomies - code partly copied from WordPress
48 + var taxonomies = new Array();
49 + $( '.categorydiv' ).each(function(){
50 + var this_id = $( this ).attr( 'id' ), taxonomyParts, taxonomy;
69 51
70 - taxonomyParts = this_id.split( '-' );
71 - taxonomyParts.shift();
72 - taxonomy = taxonomyParts.join( '-' );
73 - taxonomies.push( taxonomy ); // store the taxonomy for future use
52 + taxonomyParts = this_id.split( '-' );
53 + taxonomyParts.shift();
54 + taxonomy = taxonomyParts.join( '-' );
55 + taxonomies.push( taxonomy ); // store the taxonomy for future use
74 56
75 - // add our hidden field in the new category form - for each hierarchical taxonomy
76 - // to set the language when creating a new category
77 - // html code inserted come from html code itself.
78 - $( '#' + taxonomy + '-add-submit' ).before( // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.before
79 - $( '<input />' ).attr( 'type', 'hidden' )
80 - .attr( 'id', taxonomy + '-lang' )
81 - .attr( 'name', 'term_lang_choice' )
82 - .attr( 'value', $( '.post_lang_choice' ).val() )
83 - );
84 - }
57 + // add our hidden field in the new category form - for each hierarchical taxonomy
58 + // to set the language when creating a new category
59 + $( '#' + taxonomy + '-add-submit' ).before( $( '<input />' )
60 + .attr( 'type', 'hidden' )
61 + .attr( 'id', taxonomy + '-lang' )
62 + .attr( 'name', 'term_lang_choice' )
63 + .attr( 'value', $( '.post_lang_choice' ).val() )
85 64 );
65 + });
86 66
87 - // ajax for changing the post's language in the languages metabox
88 - $( '.post_lang_choice' ).change(
89 - function() {
90 - var value = $( this ).val();
91 - var lang = $( this ).children( 'option[value="' + value + '"]' ).attr( 'lang' );
92 - var dir = $( '.pll-translation-column > span[lang="' + lang + '"]' ).attr( 'dir' );
67 + // ajax for changing the post's language in the languages metabox
68 + $( '.post_lang_choice' ).change(function() {
69 + var value = $( this ).val();
70 + var lang = $( this ).children( 'option[value="' + value + '"]' ).attr( 'lang' );
71 + var dir = $( '.pll-translation-column > span[lang="' + lang + '"]' ).attr( 'dir' );
93 72
94 - var data = {
95 - action: 'post_lang_choice',
96 - lang: value,
97 - post_type: $( '#post_type' ).val(),
98 - taxonomies: taxonomies,
99 - post_id: $( '#post_ID' ).val(),
100 - _pll_nonce: $( '#_pll_nonce' ).val()
73 + var data = {
74 + action: 'post_lang_choice',
75 + lang: value,
76 + post_type: $( '#post_type' ).val(),
77 + taxonomies: taxonomies,
78 + post_id: $( '#post_ID' ).val(),
79 + _pll_nonce: $( '#_pll_nonce' ).val()
80 + }
81 +
82 + $.post( ajaxurl, data , function( response ) {
83 + var res = wpAjax.parseAjaxResponse( response, 'ajax-response' );
84 + $.each( res.responses, function() {
85 + switch ( this.what ) {
86 + case 'translations': // translations fields
87 + $( '.translations' ).html( this.data );
88 + init_translations();
89 + break;
90 + case 'taxonomy': // categories metabox for posts
91 + var tax = this.data;
92 + $( '#' + tax + 'checklist' ).html( this.supplemental.all );
93 + $( '#' + tax + 'checklist-pop' ).html( this.supplemental.populars );
94 + $( '#new' + tax + '_parent' ).replaceWith( this.supplemental.dropdown );
95 + $( '#' + tax + '-lang' ).val( $( '.post_lang_choice' ).val() ); // hidden field
96 + break;
97 + case 'pages': // parent dropdown list for pages
98 + $( '#parent_id' ).html( this.data );
99 + break;
100 + case 'flag': // flag in front of the select dropdown
101 + $( '.pll-select-flag' ).html( this.data );
102 + break;
103 + case 'permalink': // Sample permalink
104 + var div = $( '#edit-slug-box' );
105 + if ( '-1' != this.data && div.children().length ) {
106 + div.html( this.data );
107 + }
108 + break;
101 109 }
110 + });
102 111
103 - $.post(
104 - ajaxurl,
105 - data,
106 - function( response ) {
107 - var res = wpAjax.parseAjaxResponse( response, 'ajax-response' );
108 - $.each(
109 - res.responses,
110 - function() {
111 - switch ( this.what ) {
112 - case 'translations': // translations fields
113 - // Data is built and come from server side and is well escaped when necessary
114 - $( '.translations' ).html( this.data ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.html
115 - init_translations();
116 - break;
117 - case 'taxonomy': // categories metabox for posts
118 - var tax = this.data;
119 - // @see wp_terms_checklist https://github.com/WordPress/WordPress/blob/5.2.2/wp-admin/includes/template.php#L175
120 - // @see https://github.com/WordPress/WordPress/blob/5.2.2/wp-admin/includes/class-walker-category-checklist.php#L89-L111
121 - $( '#' + tax + 'checklist' ).html( this.supplemental.all ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.html
122 - // @see wp_popular_terms_checklist https://github.com/WordPress/WordPress/blob/5.2.2/wp-admin/includes/template.php#L236
123 - $( '#' + tax + 'checklist-pop' ).html( this.supplemental.populars ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.html
124 - // @see wp_dropdown_categories https://github.com/WordPress/WordPress/blob/5.5.1/wp-includes/category-template.php#L336
125 - // which is called by PLL_Admin_Classic_Editor::post_lang_choice to generate supplemental.dropdown
126 - $( '#new' + tax + '_parent' ).replaceWith( this.supplemental.dropdown ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.replaceWith
127 - $( '#' + tax + '-lang' ).val( $( '.post_lang_choice' ).val() ); // hidden field
128 - break;
129 - case 'pages': // parent dropdown list for pages
130 - // @see wp_dropdown_pages https://github.com/WordPress/WordPress/blob/5.2.2/wp-includes/post-template.php#L1186-L1208
131 - // @see https://github.com/WordPress/WordPress/blob/5.2.2/wp-includes/class-walker-page-dropdown.php#L88
132 - $( '#parent_id' ).html( this.data ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.html
133 - break;
134 - case 'flag': // flag in front of the select dropdown
135 - // Data is built and come from server side and is well escaped when necessary
136 - $( '.pll-select-flag' ).html( this.data ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.html
137 - break;
138 - case 'permalink': // Sample permalink
139 - var div = $( '#edit-slug-box' );
140 - if ( '-1' != this.data && div.children().length ) {
141 - // @see get_sample_permalink_html https://github.com/WordPress/WordPress/blob/5.2.2/wp-admin/includes/post.php#L1425-L1454
142 - div.html( this.data ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.html
143 - }
144 - break;
145 - }
146 - }
147 - );
112 + // modifies the language in the tag cloud
113 + $( '.tagcloud-link' ).each(function() {
114 + var id = $( this ).attr( 'id' );
115 + tagBox.get( id );
116 + });
148 117
149 - // modifies the language in the tag cloud
150 - $( '.tagcloud-link' ).each(
151 - function() {
152 - var id = $( this ).attr( 'id' );
153 - tagBox.get( id );
154 - }
155 - );
118 + // Modifies the text direction
119 + $( 'body' ).removeClass( 'pll-dir-rtl' ).removeClass( 'pll-dir-ltr' ).addClass( 'pll-dir-' + dir );
120 + $( '#content_ifr' ).contents().find( 'html' ).attr( 'lang', lang ).attr( 'dir', dir );
121 + $( '#content_ifr' ).contents().find( 'body' ).attr( 'dir', dir );
122 + });
123 + });
156 124
157 - // Modifies the text direction
158 - $( 'body' ).removeClass( 'pll-dir-rtl' ).removeClass( 'pll-dir-ltr' ).addClass( 'pll-dir-' + dir );
159 - $( '#content_ifr' ).contents().find( 'html' ).attr( 'lang', lang ).attr( 'dir', dir );
160 - $( '#content_ifr' ).contents().find( 'body' ).attr( 'dir', dir );
161 - }
162 - );
163 - }
164 - );
125 + // translations autocomplete input box
126 + function init_translations() {
127 + $( '.tr_lang' ).each(function(){
128 + var tr_lang = $( this ).attr( 'id' ).substring( 8 );
129 + var td = $( this ).parent().parent().siblings( '.pll-edit-column' );
165 130
166 - // translations autocomplete input box
167 - function init_translations() {
168 - $( '.tr_lang' ).each(
169 - function(){
170 - var tr_lang = $( this ).attr( 'id' ).substring( 8 );
171 - var td = $( this ).parent().parent().siblings( '.pll-edit-column' );
131 + $( this ).autocomplete({
132 + minLength: 0,
172 133
173 - $( this ).autocomplete(
174 - {
175 - minLength: 0,
176 - source: ajaxurl + '?action=pll_posts_not_translated' +
177 - '&post_language=' + $( '.post_lang_choice' ).val() +
178 - '&translation_language=' + tr_lang +
179 - '&post_type=' + $( '#post_type' ).val() +
180 - '&_pll_nonce=' + $( '#_pll_nonce' ).val(),
181 - select: function( event, ui ) {
182 - $( '#htr_lang_' + tr_lang ).val( ui.item.id );
183 - // ui.item.link is built and come from server side and is well escaped when necessary
184 - td.html( ui.item.link ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.html
185 - },
186 - }
187 - );
134 + source: ajaxurl + '?action=pll_posts_not_translated' +
135 + '&post_language=' + $( '.post_lang_choice' ).val() +
136 + '&translation_language=' + tr_lang +
137 + '&post_type=' + $( '#post_type' ).val() +
138 + '&_pll_nonce=' + $( '#_pll_nonce' ).val(),
188 139
189 - // when the input box is emptied
190 - $( this ).blur(
191 - function() {
192 - if ( ! $( this ).val() ) {
193 - $( '#htr_lang_' + tr_lang ).val( 0 );
194 - // Value is retrieved from HTML already generated server side
195 - td.html( td.siblings( '.hidden' ).children().clone() ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.html
196 - }
197 - }
198 - );
140 + select: function( event, ui ) {
141 + $( '#htr_lang_' + tr_lang ).val( ui.item.id );
142 + td.html( ui.item.link );
143 + },
144 + });
145 +
146 + // when the input box is emptied
147 + $( this ).blur(function() {
148 + if ( ! $( this ).val() ) {
149 + $( '#htr_lang_' + tr_lang ).val( 0 );
150 + td.html( td.siblings( '.hidden' ).children().clone() );
199 151 }
200 - );
201 - }
152 + });
153 + });
154 + }
202 155
203 - init_translations();
204 - }
205 -);
156 + init_translations();
157 +});