Guest User

Untitled

a guest
May 24th, 2024
603
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ( function( $ ) {
  2.  
  3.     let previewBtn = $( '#preview-action .preview' );
  4.  
  5.     if ( previewBtn.length ) {
  6.  
  7.         let previewIntercept = $( '<span class="preview-action--trigger" style="position: absolute; left: -1px; right: -1px; top: -1px; bottom: -1px;"></span>' ),
  8.             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>' );
  9.  
  10.         previewBtn.css( { position: 'relative', transition: '.25s' } ).append( previewIntercept );
  11.         previewIntercept.click( ( e ) => {
  12.  
  13.             let formData = new FormData( $( '#post' )[0] );
  14.            
  15.             formData.set( 'action', 'create-preview-autosave' );
  16.  
  17.             previewBtn.css( 'color', 'rgb(34 113 177 / 20%)' );
  18.             loadingIcon.hide().appendTo( previewBtn ).fadeIn( 150 );
  19.  
  20.             $.ajax( {
  21.                 url: ajaxurl,
  22.                 method: 'post',
  23.                 data: formData,
  24.                 cache: false,
  25.                 contentType: false,
  26.                 processData: false,
  27.                 success: () => {
  28.                     previewIntercept.remove();
  29.                     previewBtn.css( 'color', '' ).trigger( 'click' );
  30.                     loadingIcon.stop().fadeOut( 150, function() {
  31.                         $( this ).remove();
  32.                     } );
  33.                 },
  34.             } );
  35.  
  36.             e.preventDefault();
  37.             e.stopPropagation();
  38.  
  39.         } );
  40.  
  41.     }
  42.  
  43. } )( jQuery );
Advertisement
Add Comment
Please, Sign In to add comment