• Resolved Platinums

    (@platinums)


    I got error in this line:

    jQuery(document).ready(function() {
        document.querySelectorAll(".ez-toc-section").forEach(t=>{
            t.setAttribute("ez-toc-data-id", "#" + decodeURI(t.getAttribute("id")))
        }
        ),
        jQuery("a.ez-toc-link").click(function() {
            let t = jQuery(this).attr("href")
              , e = jQuery("#wpadminbar")
              , i = 0;
            30 > 30 && (i = 30),
            e.length && (i += e.height()),
            jQuery('[ez-toc-data-id="' + decodeURI(t) + '"]').length > 0 && (i = jQuery('[ez-toc-data-id="' + decodeURI(t) + '"]').offset().top - i),
            jQuery("html, body").animate({
                scrollTop: i
            }, 500)
        })
    });

    ReferenceError: jQuery is not defined

    I know this happen maybe because minify js using autoptimize.

    I’ve open the ETOC plugin folder and find this code:

    private static function inlineScrollEnqueueScripts()
            {
    
                $offset = wp_is_mobile() ? ezTOC_Option::get( 'mobile_smooth_scroll_offset', 0 ) : ezTOC_Option::get( 'smooth_scroll_offset', 30 );
                
                 $inlineScrollJS = <<<INLINESCROLLJS
    jQuery(document).ready(function(){document.querySelectorAll(".ez-toc-section").forEach(t=>{t.setAttribute("ez-toc-data-id","#"+decodeURI(t.getAttribute("id")))}),jQuery("a.ez-toc-link").click(function(){let t=jQuery(this).attr("href"),e=jQuery("#wpadminbar"),i=0;$offset>30&&(i=$offset),e.length&&(i+=e.height()),jQuery('[ez-toc-data-id="'+decodeURI(t)+'"]').length>0&&(i=jQuery('[ez-toc-data-id="'+decodeURI(t)+'"]').offset().top-i),jQuery("html, body").animate({scrollTop:i},500)})});
    INLINESCROLLJS;
                wp_register_script( 'ez-toc-scroll-scriptjs', '', array( 'jquery' ), ezTOC::VERSION );
                wp_enqueue_script( 'ez-toc-scroll-scriptjs', '', array( 'jquery' ), ezTOC::VERSION );
                wp_add_inline_script( 'ez-toc-scroll-scriptjs', $inlineScrollJS );
            }

    How can I fix this error with modify the php code?

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Magazine3

    (@magazine3)

    Hi, We are sorry for the inconvenience caused you. Can you please let us know it is happening after the recent update 2.0.47.1? Kindly do let us know, So that we will assist you accordingly to fix the issue.

    excluding jquery.min.js from being optimized in Autoptimize’s setting would also help (but it would make jQuery render-blocking off course).

    frank (ao dev)

    Thread Starter Platinums

    (@platinums)

    I’ve update to?2.0.47.1.

    I keep to optimize the jquery.min.js to avoid render-blocking.

    For now, I just delete this line:

    private static function inlineScrollEnqueueScripts()
            {
    
                $offset = wp_is_mobile() ? ezTOC_Option::get( 'mobile_smooth_scroll_offset', 0 ) : ezTOC_Option::get( 'smooth_scroll_offset', 30 );
                
                 $inlineScrollJS = <<<INLINESCROLLJS
    jQuery(document).ready(function(){document.querySelectorAll(".ez-toc-section").forEach(t=>{t.setAttribute("ez-toc-data-id","#"+decodeURI(t.getAttribute("id")))}),jQuery("a.ez-toc-link").click(function(){let t=jQuery(this).attr("href"),e=jQuery("#wpadminbar"),i=0;$offset>30&&(i=$offset),e.length&&(i+=e.height()),jQuery('[ez-toc-data-id="'+decodeURI(t)+'"]').length>0&&(i=jQuery('[ez-toc-data-id="'+decodeURI(t)+'"]').offset().top-i),jQuery("html, body").animate({scrollTop:i},500)})});
    INLINESCROLLJS;
                wp_register_script( 'ez-toc-scroll-scriptjs', '', array( 'jquery' ), ezTOC::VERSION );
                wp_enqueue_script( 'ez-toc-scroll-scriptjs', '', array( 'jquery' ), ezTOC::VERSION );
                wp_add_inline_script( 'ez-toc-scroll-scriptjs', $inlineScrollJS );
            }

    Still searching the solution to keep minify js without get error ReferenceError: jQuery is not defined at

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘ReferenceError: jQuery is not defined at’ is closed to new replies.