| 1 |
/** |
| 2 |
* XXX: Please remove this once this issue is resolved: https://github.com/WordPress/gutenberg/issues/13998 |
| 3 |
*/ |
| 4 |
|
| 5 |
window.addEventListener('DOMContentLoaded', function () { |
| 6 |
jQuery(document).ready(function () { |
| 7 |
// Get the correct preview link via wp_localize_script |
| 8 |
const previewLink = window._faustwp_preview_link |
| 9 |
? window._faustwp_preview_link._preview_link |
| 10 |
: undefined; |
| 11 |
|
| 12 |
/** |
| 13 |
* Check to make sure there is a preview link before continuing, as there may not be a preview link |
| 14 |
* for every instance the block editor is enqueued (e.g. /wp-admin/widgets.php) |
| 15 |
*/ |
| 16 |
if (!previewLink) { |
| 17 |
return; |
| 18 |
} |
| 19 |
|
| 20 |
const intervalId = setInterval(function () { |
| 21 |
const previewButton = jQuery( |
| 22 |
'button[class~="block-editor-post-preview__button-toggle"]', |
| 23 |
); |
| 24 |
|
| 25 |
if (!previewButton.length) { |
| 26 |
return; |
| 27 |
} |
| 28 |
|
| 29 |
clearInterval(intervalId); |
| 30 |
previewButton.first().one('click', function () { |
| 31 |
setTimeout(function () { |
| 32 |
const links = jQuery('a[target*="wp-preview"]'); |
| 33 |
|
| 34 |
if (!links.length) { |
| 35 |
return; |
| 36 |
} |
| 37 |
|
| 38 |
links.each((i, link) => { |
| 39 |
link.href = previewLink; |
| 40 |
|
| 41 |
var copy = link.cloneNode(true); |
| 42 |
copy.addEventListener('click', function () { |
| 43 |
previewButton[0].click(); |
| 44 |
|
| 45 |
wp.data.dispatch('core/editor').autosave(); |
| 46 |
}); |
| 47 |
|
| 48 |
link.parentElement.insertBefore(copy, link); |
| 49 |
link.style.display = 'none'; |
| 50 |
}); |
| 51 |
}, 100); |
| 52 |
}); |
| 53 |
}, 100); |
| 54 |
}); |
| 55 |
}); |
| 56 |
|