HEX
Server: Apache/2.4.68 (Debian)
System: Linux as-cs-widget-demo-us-central1 6.1.0-44-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.164-1 (2026-03-09) x86_64
User: root (0)
PHP: 8.2.32
Disabled: NONE
Upload Files
File: /var/www/html/wp-content/plugins/wp-recipe-maker/assets/js/admin/editor.js
window.WPRecipeMaker = typeof window.WPRecipeMaker === "undefined" ? {} : window.WPRecipeMaker;

window.WPRecipeMaker.classicEditor = {
	init: () => {
		document.addEventListener( 'click', function(e) {
			for ( var target = e.target; target && target != this; target = target.parentNode ) {
				if ( target.matches( '.wprm-modal-menu-button' ) ) {
					window.WPRecipeMaker.classicEditor.onClickNew( target, e );
					break;
				}
				if ( target.matches( '.wprm-modal-edit-button' ) ) {
					window.WPRecipeMaker.classicEditor.onClickEdit( target, e );
					break;
				}
			}
        }, false );
    },
	onClickNew: ( el, e ) => {
		e.preventDefault();

        let insertedRecipe = false;

        WPRM_Modal.open( 'menu', {
            insertCallback: ( shortcode ) => {
                const editorId = el.dataset.editor;
                
                if ( editorId ) {
                    WPRM_Modal.addTextToEditor( shortcode, editorId );
                }
            },
            saveCallback: ( recipe ) => {
                const editorId = el.dataset.editor;

                if ( editorId ) {
                    if ( ! insertedRecipe ) {
                        WPRM_Modal.addTextToEditor( '[wprm-recipe id="' + recipe.id + '"]', editorId );
                        insertedRecipe = true;
                    } else {
                        WPRM_Modal.refreshEditor( editorId );
                    }
                }
            },
        } );
    },
    onClickEdit: ( el, e ) => {
		e.preventDefault();

        const recipeId = el.dataset.recipe;

        WPRM_Modal.open( 'recipe', {
            recipeId,
            saveCallback: ( recipe ) => {
                const editorId = el.dataset.editor;

                if ( editorId ) {
                    WPRM_Modal.refreshEditor( editorId );
                }
            },
        } );
    },
};

ready(() => {
	window.WPRecipeMaker.classicEditor.init();
});

function ready( fn ) {
    if (document.readyState != 'loading'){
        fn();
    } else {
        document.addEventListener('DOMContentLoaded', fn);
    }
}