PluginProbe
Polylang / 2.6.7
Polylang v2.6.7
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 / post.js

post.js in Polylang 2.6.7, at js/post.js

175 lines 5.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Tag suggest in quick edit
3 */
4 (function( $ ){
5 $.ajaxPrefilter(function( options, originalOptions, jqXHR ) {
6 if ( 'string' === typeof options.data && -1 !== options.data.indexOf( 'action=ajax-tag-search' ) && ( lang = $( ':input[name="inline_lang_choice"]' ).val() ) ) {
7 options.data = 'lang=' + lang + '&' + options.data;
8 }
9 });
10 })( jQuery );
11
12 /**
13 * Quick edit
14 */
15 (function( $ ) {
16 $( document ).bind( 'DOMNodeInserted', function( e ) {
17 var t = $( e.target );
18
19 // WP inserts the quick edit from
20 if ( 'inline-edit' == t.attr( 'id' ) ) {
21 var post_id = t.prev().attr( 'id' ).replace( "post-", "" );
22
23 if ( post_id > 0 ) {
24 // language dropdown
25 var select = t.find( ':input[name="inline_lang_choice"]' );
26 var lang = $( '#lang_' + post_id ).html();
27 select.val( lang ); // populates the dropdown
28
29 filter_terms( lang ); // initial filter for category checklist
30 filter_pages( lang ); // initial filter for parent dropdown
31
32 // modify category checklist an parent dropdown on language change
33 select.change(function() {
34 filter_terms( $( this ).val() );
35 filter_pages( $( this ).val() );
36 });
37 }
38 }
39
40 // filter category checklist
41 function filter_terms( lang ) {
42 if ( "undefined" != typeof( pll_term_languages ) ) {
43 $.each( pll_term_languages, function( lg, term_tax ) {
44 $.each( term_tax, function( tax, terms ) {
45 $.each( terms, function( i ) {
46 id = '#' + tax + '-' + pll_term_languages[ lg ][ tax ][ i ];
47 lang == lg ? $( id ).show() : $( id ).hide();
48 });
49 });
50 });
51 }
52 }
53
54 // filter parent page dropdown list
55 function filter_pages( lang ) {
56 if ( "undefined" != typeof( pll_page_languages ) ) {
57 $.each( pll_page_languages, function( lg, pages ) {
58 $.each( pages, function( i ) {
59 v = $( '#post_parent option[value="' + pll_page_languages[ lg ][ i ] + '"]' );
60 lang == lg ? v.show() : v.hide();
61 });
62 });
63 }
64 }
65 });
66 })( jQuery );
67
68 /**
69 * Update rows of translated posts when the language is modified in quick edit
70 * Acts on ajaxSuccess event
71 */
72 (function( $ ) {
73 $( document ).ajaxSuccess(function( event, xhr, settings ) {
74 function update_rows( post_id ) {
75 // collect old translations
76 var translations = new Array;
77 $( '.translation_' + post_id ).each(function() {
78 translations.push( $( this ).parent().parent().attr( 'id' ).substring( 5 ) );
79 });
80
81 var data = {
82 action: 'pll_update_post_rows',
83 post_id: post_id,
84 translations: translations.join( ',' ),
85 post_type: $( "input[name='post_type']" ).val(),
86 screen: $( "input[name='screen']" ).val(),
87 _pll_nonce: $( "input[name='_inline_edit']" ).val() // reuse quick edit nonce
88 }
89
90 // get the modified rows in ajax and update them
91 $.post( ajaxurl, data, function( response ) {
92 if ( response ) {
93 var res = wpAjax.parseAjaxResponse( response, 'ajax-response' );
94 $.each( res.responses, function() {
95 if ( 'row' == this.what ) {
96 $( "#post-" + this.supplemental.post_id ).replaceWith( this.data );
97 }
98 });
99 }
100 });
101 }
102
103 if ( 'string' == typeof( settings.data ) ) { // Need to check the type due to block editor sometime sending FormData objects
104 var data = wpAjax.unserialize( settings.data ); // what were the data sent by the ajax request?
105 if ( 'undefined' != typeof( data['action'] ) && 'inline-save' == data['action'] ) {
106 update_rows( data['post_ID'] );
107 }
108 }
109 });
110 })( jQuery );
111
112 /**
113 * Media list table
114 * When clicking on attach link, filters find post list per media language
115 */
116 (function( $ ){
117 $.ajaxPrefilter( function ( options, originalOptions, jqXHR ) {
118 if ( 'string' === typeof options.data && -1 !== options.data.indexOf( 'action=find_posts' ) ) {
119 options.data = 'pll_post_id=' + $( '#affected' ).val() + '&' + options.data;
120 }
121 });
122 })( jQuery )
123
124
125 /**
126 * Bulk translate
127 */
128 jQuery( document ).ready( function( $ ) {
129 var t = this;
130
131 $( '.editinline' ).click( function(){
132 $( '#pll-translate' ).find( '.cancel' ).click(); // Close the form on quick edit
133 } );
134
135 $( '#doaction, #doaction2' ).click( function( e ){
136 t.whichBulkButtonId = $( this ).attr( 'id' );
137 var n = t.whichBulkButtonId.substr( 2 );
138
139 if ( 'pll_translate' === $( 'select[name="' + n + '"]' ).val() ) {
140 e.preventDefault();
141
142 if ( typeof inlineEditPost !== 'undefined' ) { // Not available for media.
143 inlineEditPost.revert(); // Close Bulk edit and Quick edit if open.
144 }
145
146 $( '#pll-translate td' ).attr( 'colspan', $( 'th:visible, td:visible', '.widefat:first thead' ).length );
147 $( 'table.widefat tbody' ).prepend( $( '#pll-translate' ) ).prepend( '<tr class="hidden"></tr>' ); // The hidden tr allows to keep the background color
148 } else {
149 $( '#pll-translate' ).find( '.cancel' ).click(); // Close the form on any other bulk action
150 }
151 } );
152
153 // Cancel
154 $( '#pll-translate' ).on( 'click', '.cancel', function(){
155 $( '#pll-translate' ).siblings( '.hidden' ).remove();
156 $( '#pll-bulk-translate' ).append( $( '#pll-translate' ) );
157
158 // Move focus back to the Bulk Action button that was activated.
159 $( '#' + t.whichBulkButtonId ).focus();
160 } );
161
162 // Act when pressing enter or esc
163 $( '#pll-translate' ).keydown( function( event ){
164 if ( 13 === event.keyCode && ! $( event.target ).hasClass( 'cancel' ) ) {
165 event.preventDefault();
166 $( this ).find( 'input[type=submit]' ).click();
167 }
168
169 if ( 27 === event.keyCode ) {
170 event.preventDefault();
171 $( this ).find( '.cancel' ).click();
172 }
173 } );
174 } );
175