Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ( function( $ ) {
- let previewBtn = $( '#preview-action .preview' );
- if ( previewBtn.length ) {
- let previewIntercept = $( '<span class="preview-action--trigger" style="position: absolute; left: -1px; right: -1px; top: -1px; bottom: -1px;"></span>' ),
- loadingIcon = $( '<svg class="preview-action--loading" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);" width="20px" height="20px" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid"><circle cx="50" cy="50" fill="none" stroke="#2271b1" stroke-width="10" r="35" stroke-dasharray="164.93361431346415 56.97787143782138" style="animation-play-state: running; animation-delay: 0s;"><animateTransform attributeName="transform" type="rotate" repeatCount="indefinite" dur="1s" values="0 50 50;360 50 50" keyTimes="0;1" style="animation-play-state: running; animation-delay: 0s;"></animateTransform></circle></svg>' );
- previewBtn.css( { position: 'relative', transition: '.25s' } ).append( previewIntercept );
- previewIntercept.click( ( e ) => {
- let formData = new FormData( $( '#post' )[0] );
- formData.set( 'action', 'create-preview-autosave' );
- previewBtn.css( 'color', 'rgb(34 113 177 / 20%)' );
- loadingIcon.hide().appendTo( previewBtn ).fadeIn( 150 );
- $.ajax( {
- url: ajaxurl,
- method: 'post',
- data: formData,
- cache: false,
- contentType: false,
- processData: false,
- success: () => {
- previewIntercept.remove();
- previewBtn.css( 'color', '' ).trigger( 'click' );
- loadingIcon.stop().fadeOut( 150, function() {
- $( this ).remove();
- } );
- },
- } );
- e.preventDefault();
- e.stopPropagation();
- } );
- }
- } )( jQuery );
Advertisement
Add Comment
Please, Sign In to add comment