• Resolved mapsmarketing

    (@mapsmarketing)


    
    /***
     * Runs Custom JS in preview mode
     *
     * Activating Elementor 'safe mode' auto-disables Custom JS (in case of faulty JS)
     */
    function wp_ea_custom_js() {
        $post_id = get_the_ID();
    
        if ( ! $post_id || ! \Elementor\Plugin::instance()->preview->is_preview_mode( $post_id ) ) {
          return;
        }
    
        $custom_js = get_post_meta( $post_id, '_eael_custom_js', true );
        if ( $custom_js ) {
          $localize_objects = apply_filters( 'eael/localize_objects', [
            'ajaxurl'            => admin_url( 'admin-ajax.php' ),
            'nonce'              => wp_create_nonce( 'essential-addons-elementor' ),
            'i18n'               => [
        	    'added'   => __( 'Added ', 'essential-addons-for-elementor-lite' ),
        	    'compare' => __( 'Compare', 'essential-addons-for-elementor-lite' ),
        	    'loading' => esc_html__( 'Loading...', 'essential-addons-for-elementor-lite' )
            ],
            'page_permalink'     => get_the_permalink(),
            'cart_redirectition' => get_option( 'woocommerce_cart_redirect_after_add' ),
            'cart_page_url'      => function_exists( 'wc_get_cart_url' ) ? wc_get_cart_url() : '',
            'el_breakpoints'     => method_exists( \Elementor\Plugin::$instance->breakpoints, 'get_breakpoints_config' ) ? \Elementor\Plugin::$instance->breakpoints->get_breakpoints_config() : '',
          ] );
        
          printf( '<script>%1$s</script>', 'var localize =' . wp_json_encode( $localize_objects ) );
          printf( '<script id="eael-inline-js">%s</script>', $custom_js );
        }
    }
    add_action( 'wp_footer', 'wp_ea_custom_js', 100 );
    
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Abid Hasan

    (@abidhasan112)

    Hi @mapsmarketing ,

    Thanks for your solution regarding Custom JS execution on Elementor Editor.
    We’re looking into this.

    Cheers!

    Plugin Author Rafin

    (@rafinkhan)

    Hi @mapsmarketing,

    We have found a way to allow Custom JS to run inside Elementor Editor. You can check out the development version from here and try it out.

    Note: You will just have to reload the page to see the changes inside your Elementor Editor.

    Let me know if you have any other feedback, Thank you.

    Thread Starter mapsmarketing

    (@mapsmarketing)

    Great work @rafinkhan ! Much appreciated.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Allow Custom JS to run in preview’ is closed to new replies.