86

How to Save Oxygen Builder Changes with Keyboard Shortcuts

Powered by WPCodeBox

This snippet allows you to save Oxygen builder changes with keyboard shortcuts like Ctrl + S or Command + S.


<?php
/**
 * 
 * Description: Save oxygen builder changes using Ctrl + S or Command + S
 * Version:     0.0.1
 * 
 */
add_action( 'wp_head', function() {
    
    if( isset( $_GET['ct_builder'] ) && !isset( $_GET['oxygen_iframe'] ) ) {
    
        $js = <<<EOD
        <script type="text/javascript">
            jQuery(document).ready(function(){
                    
                setTimeout(function() {
                
                    var isCtrl = false;
                    
                    var iframeDocument  = document.getElementById('ct-artificial-viewport').contentWindow.document;
                    
                    var keyUp = function(e){
                        if(e.keyCode == 17 || e.key === 'Meta') isCtrl=false;
                    }
                    
                    var keyDown = function(e){
                        
                        console.log('save');
                        
                        if(e.keyCode == 17 || e.key === 'Meta') isCtrl=true;
                        if(e.keyCode == 83 && isCtrl == true) {
                    
                        e.preventDefault();
                        
                        if(jQuery('#oxygen-ui').length) {
                            angular.element("#oxygen-ui").scope().iframeScope.savePage();
                        } else {
                            angular.element(parent.document.getElementById('oxygen-ui')).scope().iframeScope.savePage();
                        }
                        
                        
                        return false;
                        }
                    }
                    
                    document.onkeyup = keyUp;
                    document.onkeydown = keyDown;
                    
                    iframeDocument.onkeyup = keyUp;
                    iframeDocument.onkeydown = keyDown;
                }, 1000);
                
            });
        </script>
    
EOD; 
    
        echo $js;
    }
});

Other Snippets

WPCodeBox is a WordPress Code Snippets Manager that allows you to share your WordPress Code Snippets across your sites.