PluginProbe
Polylang / 3.8.10
Polylang v3.8.10
3.8.10 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 All 234 releases
← All changes | js/build/block-editor.js +397 -293 3.0.1 → 3.8.10 View file →
@@ -1,143 +1,303 @@
1 -/******/ "use strict";
1 +/******/ (() => { // webpackBootstrap
2 +/******/ var __webpack_modules__ = ({
2 3
3 -;// CONCATENATED MODULE: ./js/lib/confirmation-modal.js
4 +/***/ 631
5 +(module) {
6 +
7 +module.exports = (function() { return this["wp"]["apiFetch"]; }());
8 +
9 +/***/ }
10 +
11 +/******/ });
12 +/************************************************************************/
13 +/******/ // The module cache
14 +/******/ const __webpack_module_cache__ = {};
15 +/******/
16 +/******/ // The require function
17 +/******/ function __webpack_require__(moduleId) {
18 +/******/ // Check if module is in cache
19 +/******/ const cachedModule = __webpack_module_cache__[moduleId];
20 +/******/ if (cachedModule !== undefined) {
21 +/******/ return cachedModule.exports;
22 +/******/ }
23 +/******/ // Create a new module (and put it into the cache)
24 +/******/ const module = __webpack_module_cache__[moduleId] = {
25 +/******/ // no module.id needed
26 +/******/ // no module.loaded needed
27 +/******/ exports: {}
28 +/******/ };
29 +/******/
30 +/******/ // Execute the module function
31 +/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
32 +/******/
33 +/******/ // Return the exports of the module
34 +/******/ return module.exports;
35 +/******/ }
36 +/******/
37 +/************************************************************************/
38 +/******/ /* webpack/runtime/compat get default export */
39 +/******/ // getDefaultExport function for compatibility with non-harmony modules
40 +/******/ __webpack_require__.n = (module) => {
41 +/******/ const getter = module && module.__esModule ?
42 +/******/ () => (module['default']) :
43 +/******/ () => (module);
44 +/******/ __webpack_require__.d(getter, { a: getter });
45 +/******/ return getter;
46 +/******/ };
47 +/******/
48 +/******/ /* webpack/runtime/define property getters */
49 +/******/ // define getter/value functions for harmony exports
50 +/******/ __webpack_require__.d = (exports, definition) => {
51 +/******/ for(var key in definition) {
52 +/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
53 +/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
54 +/******/ }
55 +/******/ }
56 +/******/ };
57 +/******/
58 +/******/ /* webpack/runtime/hasOwnProperty shorthand */
59 +/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop));
60 +/******/
61 +/************************************************************************/
62 +let __webpack_exports__ = {};
63 +// This entry needs to be wrapped in an IIFE because it needs to be in strict mode.
64 +(() => {
65 +"use strict";
66 +
67 +;// ./js/src/lib/confirmation-modal.js
4 68 /**
5 69 * @package Polylang
6 70 */
7 71
8 -const languagesList = jQuery( '.post_lang_choice' );
72 +const languagesList = jQuery('.post_lang_choice');
9 73
10 74 // Dialog box for alerting the user about a risky changing.
11 -const initializeConfimationModal = () => {
12 - // We can't use underscore or lodash in this common code because it depends of the context classic or block editor.
13 - // Classic editor underscore is loaded, Block editor lodash is loaded.
14 - const { __ } = wp.i18n;
75 +const initializeConfirmationModal = () => {
76 + // We can't use underscore or lodash in this common code because it depends of the context classic or block editor.
77 + // Classic editor underscore is loaded, Block editor lodash is loaded.
78 + const {
79 + __
80 + } = wp.i18n;
15 81
16 - // Create dialog container.
17 - const dialogContainer = jQuery(
18 - '<div/>',
19 - {
20 - id: 'pll-dialog',
21 - style: 'display:none;'
22 - }
23 - ).text( __( 'Are you sure you want to change the language of the current content?', 'polylang' ) );
82 + // Create dialog container.
83 + const dialogContainer = jQuery('<div/>', {
84 + id: 'pll-dialog',
85 + style: 'display:none;'
86 + }).text(__('Are you sure you want to change the language of the current content?', 'polylang'));
24 87
25 - // Put it after languages list dropdown.
26 - // PHPCS ignore dialogContainer is a new safe HTML code generated above.
27 - languagesList.after( dialogContainer ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.after
88 + // Put it after languages list dropdown.
89 + // PHPCS ignore dialogContainer is a new safe HTML code generated above.
90 + languagesList.after(dialogContainer); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.after
28 91
29 - const dialogResult = new Promise(
30 - ( confirm, cancel ) => {
31 - const confirmDialog = ( what ) => { // phpcs:ignore PEAR.Functions.FunctionCallSignature.Indent
32 - switch ( what ) { // phpcs:ignore PEAR.Functions.FunctionCallSignature.Indent
33 - case 'yes':
34 - // Confirm the new language.
35 - languagesList.data( 'old-value', languagesList.children( ':selected' )[0].value );
36 - confirm();
37 - break;
38 - case 'no':
39 - // Revert to the old language.
40 - languagesList.val( languagesList.data( 'old-value' ) );
41 - cancel( 'Cancel' );
42 - break;
43 - }
44 - dialogContainer.dialog( 'close' ); // phpcs:ignore PEAR.Functions.FunctionCallSignature.Indent
45 - } // phpcs:ignore PEAR.Functions.FunctionCallSignature.Indent
92 + const dialogResult = new Promise((confirm, cancel) => {
93 + const confirmDialog = what => {
94 + // phpcs:ignore PEAR.Functions.FunctionCallSignature.Indent
95 + switch (what) {
96 + // phpcs:ignore PEAR.Functions.FunctionCallSignature.Indent
97 + case 'yes':
98 + // Confirm the new language.
99 + languagesList.data('old-value', languagesList.children(':selected').first().val());
100 + confirm();
101 + break;
102 + case 'no':
103 + // Revert to the old language.
104 + languagesList.val(languagesList.data('old-value'));
105 + cancel('Cancel');
106 + break;
107 + }
108 + dialogContainer.dialog('close'); // phpcs:ignore PEAR.Functions.FunctionCallSignature.Indent
109 + }; // phpcs:ignore PEAR.Functions.FunctionCallSignature.Indent
46 110
47 - // Initialize dialog box in the case a language is selected but not added in the list.
48 - dialogContainer.dialog(
49 - {
50 - autoOpen: false,
51 - modal: true,
52 - draggable: false,
53 - resizable: false,
54 - title: __( 'Change language', 'polylang' ),
55 - minWidth: 600,
56 - maxWidth: '100%',
57 - classes: {
58 - 'ui-dialog': 'pll-confirmation-modal',
59 - },
60 - open: function( event, ui ) {
61 - // Change dialog box position for rtl language
62 - if ( jQuery( 'body' ).hasClass( 'rtl' ) ) {
63 - jQuery( this ).parent().css(
64 - {
65 - right: jQuery( this ).parent().css( 'left' ),
66 - left: 'auto'
67 - }
68 - );
69 - }
70 - },
71 - close: function( event, ui ) {
72 - // When we're closing the dialog box we need to cancel the language change as we click on Cancel button.
73 - confirmDialog( 'no' );
74 - },
75 - buttons: [
76 - {
77 - text: __( 'OK', 'polylang' ),
78 - click: function( event ) {
79 - confirmDialog( 'yes' );
80 - }
81 - },
82 - {
83 - text: __( 'Cancel', 'polylang' ),
84 - click: function( event ) {
85 - confirmDialog( 'no' );
86 - }
87 - } ]
88 - }
89 - );
90 - }
91 - );
92 - return { dialogContainer, dialogResult };
111 + // Initialize dialog box in the case a language is selected but not added in the list.
112 + const dialogOptions = {
113 + autoOpen: false,
114 + modal: true,
115 + draggable: false,
116 + resizable: false,
117 + title: __('Change language', 'polylang'),
118 + minWidth: 600,
119 + maxWidth: '100%',
120 + open: function (event, ui) {
121 + // Change dialog box position for rtl language
122 + if (jQuery('body').hasClass('rtl')) {
123 + jQuery(this).parent().css({
124 + right: jQuery(this).parent().css('left'),
125 + left: 'auto'
126 + });
127 + }
128 + },
129 + close: function (event, ui) {
130 + // When we're closing the dialog box we need to cancel the language change as we click on Cancel button.
131 + confirmDialog('no');
132 + },
133 + buttons: [{
134 + text: __('OK', 'polylang'),
135 + click: function (event) {
136 + confirmDialog('yes');
137 + }
138 + }, {
139 + text: __('Cancel', 'polylang'),
140 + click: function (event) {
141 + confirmDialog('no');
142 + }
143 + }]
144 + };
145 + if (jQuery.ui.version >= '1.12.0') {
146 + Object.assign(dialogOptions, {
147 + classes: {
148 + 'ui-dialog': 'pll-confirmation-modal'
149 + }
150 + });
151 + } else {
152 + Object.assign(dialogOptions, {
153 + dialogClass: 'pll-confirmation-modal'
154 + }); // jQuery UI 1.11.4 - WP < 5.6
155 + }
156 + dialogContainer.dialog(dialogOptions);
157 + });
158 + return {
159 + dialogContainer,
160 + dialogResult
161 + };
162 +};
163 +const initializeLanguageOldValue = () => {
164 + // Keep the old language value to be able to compare to the new one and revert to it if necessary.
165 + languagesList.attr('data-old-value', languagesList.children(':selected').first().val());
166 +};
167 +;// ./js/src/lib/metabox-autocomplete.js
168 +/**
169 + * @package Polylang
170 + */
171 +
172 +// Translations autocomplete input box.
173 +function initMetaboxAutoComplete() {
174 + jQuery('.tr_lang').each(function () {
175 + var tr_lang = jQuery(this).attr('id').substring(8);
176 + var td = jQuery(this).parent().parent().siblings('.pll-edit-column');
177 + jQuery(this).autocomplete({
178 + minLength: 0,
179 + source: ajaxurl + '?action=pll_posts_not_translated' + '&post_language=' + jQuery('.post_lang_choice').val() + '&translation_language=' + tr_lang + '&post_type=' + jQuery('#post_type').val() + '&_pll_nonce=' + jQuery('#_pll_nonce').val(),
180 + select: function (event, ui) {
181 + jQuery('#htr_lang_' + tr_lang).val(ui.item.id);
182 + // ui.item.link is built and come from server side and is well escaped when necessary
183 + td.html(ui.item.link); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.html
184 + }
185 + });
186 +
187 + // when the input box is emptied
188 + jQuery(this).on('blur', function () {
189 + if (!jQuery(this).val()) {
190 + jQuery('#htr_lang_' + tr_lang).val(0);
191 + // Value is retrieved from HTML already generated server side
192 + td.html(td.siblings('.hidden').children().clone()); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.html
193 + }
194 + });
195 + });
93 196 }
197 +// EXTERNAL MODULE: external {"this":["wp","apiFetch"]}
198 +var external_this_wp_apiFetch_ = __webpack_require__(631);
199 +var external_this_wp_apiFetch_default = /*#__PURE__*/__webpack_require__.n(external_this_wp_apiFetch_);
200 +;// ./node_modules/@wpsyntex/polylang-react-library/build/middlewares/filter-path.js
201 +/**
202 + * Filters requests for translatable entities.
203 + * This logic is shared across all Polylang plugins.
204 + *
205 + * @since 3.5
206 + *
207 + * @param {Object} options - API fetch options object.
208 + * @param {Array} filteredRoutes - Array of route paths to filter.
209 + * @param {Function} filter - Function to filter matching routes.
210 + * @return {Object} Modified REST request options.
211 + */
212 +const filterPathMiddleware = (options, filteredRoutes, filter) => {
213 + const cleanPath = options.path.split('?')[0].replace(/^\/+|\/+$/g, ''); // Get path without query parameters and trim '/'.
94 214
95 -const initializeLanguageOldValue = () => {
96 - // Keep the old language value to be able to compare to the new one and revert to it if necessary.
97 - languagesList.attr( 'data-old-value', languagesList.children( ':selected' )[0].value );
215 + return Object.values(filteredRoutes).find(path => cleanPath === path) ? filter(options) : options;
98 216 };
217 +/* harmony default export */ const filter_path = (filterPathMiddleware);
218 +;// ./node_modules/@wpsyntex/polylang-react-library/build/middlewares/editors-requests-filter.js
219 +/**
220 + * WordPress dependencies.
221 + */
99 222
100 -;// CONCATENATED MODULE: ./js/block-editor.js
223 +
224 +/*
225 + * Internal dependencies.
226 + */
227 +
228 +
101 229 /**
230 + * Safely filters requests for translatable entities in block editor type screens.
231 + * Ensures that `pllFilteredRoutes` has been well defined on server side and
232 + * that the filtered request is a REST one.
233 + *
234 + * @param {Function} filterCallback - Function to filter API fetch options.
235 + */
236 +const editorsRequestsFilter = filterCallback => {
237 + external_this_wp_apiFetch_default().use((options, next) => {
238 + /*
239 + * If options.url is defined, this is not a REST request but a direct call to post.php for legacy metaboxes.
240 + * If `filteredRoutes` is not defined, return early.
241 + */
242 + if ('undefined' !== typeof options.url || 'undefined' === typeof window.pllFilteredRoutes) {
243 + return next(options);
244 + }
245 + return next(filter_path(options, window.pllFilteredRoutes, filterCallback));
246 + });
247 +};
248 +/* harmony default export */ const editors_requests_filter = (editorsRequestsFilter);
249 +;// ./js/src/block-editor.js
250 +/**
102 251 * @package Polylang
103 252 */
104 253
105 254
106 255
256 +
257 +
107 258 /**
108 - * Filter REST API requests to add the language in the request
259 + * Gets the language of the currently edited post, fallback to default language if none is found.
109 260 *
110 261 * @since 2.5
262 + *
263 + * @return {Element.value}
111 264 */
112 -wp.apiFetch.use(
113 - function( options, next ) {
114 - // If options.url is defined, this is not a REST request but a direct call to post.php for legacy metaboxes.
115 - if ( 'undefined' === typeof options.url ) {
116 - if ( 'undefined' === typeof options.data || null === options.data ) {
117 - // GET
118 - options.path += ( ( options.path.indexOf( '?' ) >= 0 ) ? '&lang=' : '?lang=' ) + getCurrentLanguage();
119 - } else {
120 - // PUT, POST
121 - options.data.lang = getCurrentLanguage();
122 - }
123 - }
124 - return next( options );
125 - }
126 -);
265 +function getCurrentLanguage() {
266 + const lang = document.querySelector('[name=post_lang_choice]');
267 + if (null === lang) {
268 + return pllDefaultLanguage;
269 + }
270 + return lang.value;
271 +}
127 272
128 273 /**
129 - * Get the language from the HTML form
274 + * Adds language parameter according to the current one (query string for GET, body for PUT and POST).
130 275 *
131 - * @since 2.5
276 + * @since 3.5
132 277 *
133 - * @return {Element.value}
278 + * @param {APIFetchOptions} options
279 + * @returns {APIFetchOptions}
134 280 */
135 -function getCurrentLanguage() {
136 - return document.querySelector( '[name=post_lang_choice]' ).value;
281 +function addLanguageParameter(options) {
282 + if ('undefined' === typeof options.data || null === options.data) {
283 + // GET
284 + options.path += (options.path.indexOf('?') >= 0 ? '&lang=' : '?lang=') + getCurrentLanguage();
285 + } else {
286 + // PUT, POST
287 + options.data.lang = getCurrentLanguage();
288 + }
289 + return options;
137 290 }
138 291
139 292 /**
293 + * Filter REST API requests to add the language in the request
294 + *
295 + * @since 2.5
296 + */
297 +editors_requests_filter(addLanguageParameter);
298 +
299 +/**
140 300 * Handles internals of the metabox:
141 301 * Language select, autocomplete input field.
142 302 *
143 303 * @since 1.5
@@ -149,202 +309,146 @@
149 309 * Link post saving after refreshing the metabox.
150 310 *
151 311 * @since 3.0
152 312 */
153 -jQuery(
154 - function( $ ) {
155 - // Initialize current language to be able to compare if it changes.
156 - initializeLanguageOldValue();
313 +jQuery(function ($) {
314 + // Initialize current language to be able to compare if it changes.
315 + initializeLanguageOldValue();
157 316
317 + // Ajax for changing the post's language in the languages metabox
318 + $('.post_lang_choice').on('change', function (event) {
319 + const {
320 + select,
321 + dispatch,
322 + subscribe
323 + } = wp.data;
324 + const emptyPost = isEmptyPost();
325 + const {
326 + addQueryArgs
327 + } = wp.url;
158 328
159 - // Ajax for changing the post's language in the languages metabox
160 - $( '.post_lang_choice' ).on(
161 - 'change',
162 - function( event ) {
163 - const select = wp.data.select;
164 - const dispatch = wp.data.dispatch;
165 - const subscribe = wp.data.subscribe;
166 - const emptyPost = isEmptyPost();
329 + // Initialize the confirmation dialog box.
330 + const confirmationModal = initializeConfirmationModal();
331 + const {
332 + dialogContainer: dialog
333 + } = confirmationModal;
334 + let {
335 + dialogResult
336 + } = confirmationModal;
337 + const selectedOption = event.target; // The selected option in the dropdown list.
167 338
168 - // Initialize the confirmation dialog box.
169 - const confirmationModal = initializeConfimationModal();
170 - const { dialogContainer : dialog } = confirmationModal;
171 - let { dialogResult } = confirmationModal;
172 - // The selected option in the dropdown list.
173 - const selectedOption = event.target;
339 + // Specific case for empty posts.
340 + // Place at the beginning because window.location change triggers automatically page reloading.
341 + if (location.pathname.match(/post-new.php/gi) && emptyPost) {
342 + reloadPageForEmptyPost(selectedOption.value);
343 + }
174 344
175 - // Specific case for empty posts.
176 - // Place at the beginning because window.location changing triggers automatically page reloading.
177 - if ( location.pathname.match( /post-new.php/gi ) && emptyPost ) {
178 - reloadPageForEmptyPost( selectedOption.value );
179 - }
345 + // Otherwise send an ajax request to refresh the legacy metabox and set the post language with the new language.
346 + // It needs a confirmation of the user before changing the language.
347 + // Need to wait the ajax response before triggering the block editor post save action.
348 + if ($(this).data('old-value') !== selectedOption.value && !emptyPost) {
349 + dialog.dialog('open');
350 + } else {
351 + // Update the old language with the new one to be able to compare it in the next change.
352 + // Because the page isn't reloaded in this case.
353 + initializeLanguageOldValue();
354 + dialogResult = Promise.resolve();
355 + }
356 + dialogResult.then(() => {
357 + let data = {
358 + // phpcs:ignore PEAR.Functions.FunctionCallSignature.Indent
359 + action: 'post_lang_choice',
360 + lang: selectedOption.value,
361 + post_type: $('#post_type').val(),
362 + post_id: $('#post_ID').val(),
363 + _pll_nonce: $('#_pll_nonce').val()
364 + };
180 365
181 - // Otherwise send an ajax request to refresh the legacy metabox and set the post language with the new language.
182 - // It needs a confirmation of the user before changing the language.
183 - // Need to wait the ajax response before triggering the block editor post save action.
184 - if ( $( this ).data( 'old-value' ) !== selectedOption.value && ! emptyPost ) {
185 - dialog.dialog( 'open' );
186 - } else {
187 - // Update the old language with the new one to be able to compare it in the next changing.
188 - // Because the page isn't reloaded in this case.
189 - initializeLanguageOldValue();
190 - dialogResult = Promise.resolve();
191 - }
366 + // Update post language in database as soon as possible.
367 + // Because, in addition of the block editor save process, the legacy metabox uses a post.php process to update the language and is too late compared to the page reload.
368 + $.post(ajaxurl, data, function () {
369 + blockEditorSavePostAndReloadPage();
370 + });
371 + }, () => {} // Do nothing when promise is rejected by clicking the Cancel dialog button.
372 + );
373 + function isEmptyPost() {
374 + const editor = select('core/editor');
375 + return !editor.getEditedPostAttribute('title')?.trim() && !editor.getEditedPostContent() && !editor.getEditedPostAttribute('excerpt')?.trim();
376 + }
192 377
193 - dialogResult.then(
194 - () => {
195 - var data = { // phpcs:ignore PEAR.Functions.FunctionCallSignature.Indent
196 - action: 'post_lang_choice',
197 - lang: selectedOption.value,
198 - post_type: $( '#post_type' ).val(),
199 - post_id: $( '#post_ID' ).val(),
200 - _pll_nonce: $( '#_pll_nonce' ).val()
201 - }
378 + /**
379 + * Reload the block editor page for empty posts.
380 + *
381 + * @param {string} lang The target language code.
382 + */
383 + function reloadPageForEmptyPost(lang) {
384 + // Change the new_lang parameter with the new language value for reloading the page
385 + // WPCS location.search is never written in the page, just used to reload page with the right value of new_lang
386 + // new_lang input is controlled server side in PHP. The value come from the dropdown list of language returned and escaped server side.
387 + // Notice that window.location changing triggers automatically page reloading.
388 + if (-1 != location.search.indexOf('new_lang')) {
389 + // use regexp non capturing group to replace new_lang parameter no matter where it is and capture other parameters which can be behind it
390 + window.location.search = window.location.search.replace(/(?:new_lang=[^&]*)(&)?(.*)/, 'new_lang=' + lang + '$1$2'); // phpcs:ignore WordPressVIPMinimum.JS.Window.location, WordPressVIPMinimum.JS.Window.VarAssignment
391 + } else {
392 + window.location.search = window.location.search + (-1 != window.location.search.indexOf('?') ? '&' : '?') + 'new_lang=' + lang; // phpcs:ignore WordPressVIPMinimum.JS.Window.location, WordPressVIPMinimum.JS.Window.VarAssignment
393 + }
394 + }
395 + ;
202 396
203 - $.post(
204 - ajaxurl,
205 - data,
206 - function( response ) {
207 - var res = wpAjax.parseAjaxResponse( response, 'ajax-response' );
208 - $.each(
209 - res.responses,
210 - function() {
211 - switch ( this.what ) {
212 - case 'translations': // Translations fields
213 - // Data is built and come from server side and is well escaped when necessary
214 - $( '.translations' ).html( this.data ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.html
215 - init_translations();
216 - break;
217 - case 'flag': // Flag in front of the select dropdown
218 - // Data is built and come from server side and is well escaped when necessary
219 - $( '.pll-select-flag' ).html( this.data ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.html
220 - break;
221 - }
222 - }
223 - );
224 - blockEditorSavePostAndReloadPage();
225 - }
226 - );
227 - },
228 - () => {} // Do nothing when promise is rejected by clicking the Cancel dialog button.
229 - );
397 + /**
398 + * Triggers block editor post save and reload the block editor page when everything is ok.
399 + */
400 + function blockEditorSavePostAndReloadPage() {
401 + let unsubscribe = null;
402 + const previousPost = select('core/editor').getCurrentPost();
230 403
231 - function isEmptyPost() {
232 - const editor = wp.data.select( 'core/editor' );
233 - const title = editor.getEditedPostAttribute( 'title' ).trim();
234 - const content = editor.getEditedPostAttribute( 'content' ).trim();
235 - const excerpt = editor.getEditedPostAttribute( 'excerpt' ).trim();
404 + // Listen if the savePost is completely done by subscribing to its events.
405 + const savePostIsDone = new Promise(function (resolve, reject) {
406 + unsubscribe = subscribe(function () {
407 + const post = select('core/editor').getCurrentPost();
408 + const {
409 + id,
410 + status,
411 + type
412 + } = post;
413 + const error = select('core').getLastEntitySaveError('postType', type, id);
414 + if (error) {
415 + reject();
416 + }
417 + if (previousPost.modified !== post.modified) {
418 + if (location.pathname.match(/post-new.php/gi) && status !== 'auto-draft' && id) {
419 + window.history.replaceState({
420 + id
421 + }, 'Post ' + id, addQueryArgs('post.php', {
422 + post: id,
423 + action: 'edit'
424 + }));
425 + }
426 + resolve();
427 + }
428 + });
429 + });
236 430
237 - return ! title && ! content && ! excerpt;
238 - }
431 + // Triggers the post save.
432 + dispatch('core/editor').savePost();
239 433
240 - /**
241 - * Reload the block editor page for empty posts.
242 - *
243 - * @param {string} lang The target language code.
244 - */
245 - function reloadPageForEmptyPost( lang ) {
246 - // Change the new_lang parameter with the new language value for reloading the page
247 - // WPCS location.search is never written in the page, just used to reload page with the right value of new_lang
248 - // new_lang input is controlled server side in PHP. The value come from the dropdown list of language returned and escaped server side.
249 - // Notice that window.location changing triggers automatically page reloading.
250 - if ( -1 != location.search.indexOf( 'new_lang' ) ) {
251 - // use regexp non capturing group to replace new_lang parameter no matter where it is and capture other parameters which can be behind it
252 - window.location.search = window.location.search.replace( /(?:new_lang=[^&]*)(&)?(.*)/, 'new_lang=' + lang + '$1$2' ); // phpcs:ignore WordPressVIPMinimum.JS.Window.location, WordPressVIPMinimum.JS.Window.VarAssignment
253 - } else {
254 - window.location.search = window.location.search + ( ( -1 != window.location.search.indexOf( '?' ) ) ? '&' : '?' ) + 'new_lang=' + lang; // phpcs:ignore WordPressVIPMinimum.JS.Window.location, WordPressVIPMinimum.JS.Window.VarAssignment
255 - }
256 - };
434 + // Process
435 + savePostIsDone.then(function () {
436 + // If the post is well saved, we can reload the page
437 + window.location.reload();
438 + }, function () {
439 + // If the post save failed
440 + unsubscribe();
441 + }).catch(function () {
442 + // If an exception is thrown
443 + unsubscribe();
444 + });
445 + }
446 + ;
447 + });
448 + initMetaboxAutoComplete();
449 +});
450 +})();
257 451
258 - /**
259 - * Triggers block editor post save and reload the block editor page when everything is ok.
260 - */
261 - function blockEditorSavePostAndReloadPage() {
262 -
263 - let unsubscribe = null;
264 -
265 - // Listen if the savePost is completely done by subscribing to its events.
266 - const savePostIsDone = new Promise(
267 - function( resolve, reject ) {
268 - unsubscribe = subscribe(
269 - function() {
270 - const isSavePostSucceeded = select( 'core/editor' ).didPostSaveRequestSucceed();
271 - const isSavePostFailed = select( 'core/editor' ).didPostSaveRequestFail();
272 - if ( isSavePostSucceeded || isSavePostFailed ) {
273 - if ( isSavePostFailed ) {
274 - reject();
275 - } else {
276 - resolve();
277 - }
278 - }
279 - }
280 - );
281 - }
282 - );
283 -
284 - // Triggers the post save.
285 - dispatch( 'core/editor' ).savePost();
286 -
287 - // Process
288 - savePostIsDone.then(
289 - function() {
290 - // If the post is well saved, we can reload the page
291 - window.location.reload();
292 - },
293 - function() {
294 - // If the post save failed
295 - unsubscribe();
296 - }
297 - ).catch(
298 - function() {
299 - // If an exception is thrown
300 - unsubscribe();
301 - }
302 - );
303 - };
304 - }
305 - );
306 -
307 - // Translations autocomplete input box
308 - function init_translations() {
309 - $( '.tr_lang' ).each(
310 - function(){
311 - var tr_lang = $( this ).attr( 'id' ).substring( 8 );
312 - var td = $( this ).parent().parent().siblings( '.pll-edit-column' );
313 -
314 - $( this ).autocomplete(
315 - {
316 - minLength: 0,
317 -
318 - source: ajaxurl + '?action=pll_posts_not_translated' +
319 - '&post_language=' + $( '.post_lang_choice' ).val() +
320 - '&translation_language=' + tr_lang +
321 - '&post_type=' + $( '#post_type' ).val() +
322 - '&_pll_nonce=' + $( '#_pll_nonce' ).val(),
323 -
324 - select: function( event, ui ) {
325 - $( '#htr_lang_' + tr_lang ).val( ui.item.id );
326 - // ui.item.link is built and come from server side and is well escaped when necessary
327 - td.html( ui.item.link ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.html
328 - },
329 - }
330 - );
331 -
332 - // When the input box is emptied
333 - $( this ).on(
334 - 'blur',
335 - function() {
336 - if ( ! $( this ).val() ) {
337 - $( '#htr_lang_' + tr_lang ).val( 0 );
338 - // Value is retrieved from HTML already generated server side
339 - td.html( td.siblings( '.hidden' ).children().clone() ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.html
340 - }
341 - }
342 - );
343 - }
344 - );
345 - }
346 -
347 - init_translations();
348 - }
349 -);
350 -
452 +this.polylang = __webpack_exports__;
453 +/******/ })()
454 +;