#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    2
    Rep Power
    0

    JS Debugging Help


    I need help debugging some Javascript from my WordPress site. I'm not a JS coder, so not sure what to do. I'm told there is an error on line 77: offset undefined. Can anyone help?

    Code:
    /* ==========================================================================
       Initiator Scripts
       ========================================================================== */
    
    $(function() {
        // Initiate standard slider
        if ($('.flexslider').length > 0) {
            $('.flexslider').flexslider({
                animation: "slide",
                controlNav: false,
                directionNav: true,
                prevText: "<",
                nextText: ">",
                controlsContainer: ".flex-container"
            });
        }
    
        // Initiate Lifestyle page slider
        if ($('.location-slider').length > 0) {
            $('.location-slider').flexslider({
                animation: "slide",
                controlNav: true,
                directionNav: true,
                prevText: "<",
                nextText: ">",
                controlsContainer: ".location-slider-container"
            });
    
            // Append location description below link
            $('#location-slider .slide-1 a').css('background', 'url(../wp-content/themes/roots/assets/img/btn_slide1.jpg) top left');
            $('#location-slider .slide-2 a').css('background', 'url(../wp-content/themes/roots/assets/img/btn_slide2.jpg) top left');
            $('#location-slider .slide-3 a').css('background', 'url(../wp-content/themes/roots/assets/img/btn_slide3.jpg) top left');
            $('#location-slider .slide-4 a').css('background', 'url(../wp-content/themes/roots/assets/img/btn_slide4.jpg) top left');
            $('#location-slider .slide-5 a').css('background', 'url(../wp-content/themes/roots/assets/img/btn_slide5.jpg) top left');
    
            // Append location description below link
            $('#location-slider .slide-1').append('<span>Robina Town Centre</span>');
            $('#location-slider .slide-2').append('<span>Skilled Park Stadium</span>');
            $('#location-slider .slide-3').append('<span>Commercial Precinct</span>');
            $('#location-slider .slide-4').append('<span>Medical Precinct</span>');
            $('#location-slider .slide-5').append('<span>Transport Hub</span>');
        }
    
        // Initiate Fancybox popup
        if ($('.fancybox').length > 0) {
            $('.fancybox').fancybox();
        }
    });
    
    
    
    /* ==========================================================================
       Custom Scripts
       ========================================================================== */
    
    // Mobile dropdown menu functionality
    $(function() {
        $('.mobile-menu').on('click', function(){
            $('.nav-main ul').slideToggle();
        });
    });
    
    
    // Anchor links smooth scrolling
    $(function($) {
        $(".scroll").click(function(event){
            event.preventDefault();
            $('html,body').animate({scrollTop:$(this.hash).offset().top}, 500);
        });
    });
    
    
    // Fixed sub-menu
    var GblTop;
    
    function GetVertOffset (srchStr) {
        GblTop = $(srchStr).offset().top - parseFloat($(srchStr).css('marginTop').replace(/auto/, 0));
    }
    
    $(function () {
    
        GetVertOffset ('.floating-sub-menu'); // -- Sets GblTop
    
        $(window).scroll (function() {
            // what is the y position of the scroll?
            var y = $(window).scrollTop();
    
            // whether that's below the start of article?
            if (y >= GblTop) {
                // if so, add the fixed class
                $('.floating-sub-menu').addClass('fixed-nav');
            } else {
                // otherwise, remove it
                $('.floating-sub-menu').removeClass('fixed-nav');
            }
        });
    });
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    22
    Rep Power
    0
    Originally Posted by ShumaKun
    I need help debugging some Javascript from my WordPress site. I'm not a JS coder, so not sure what to do. I'm told there is an error on line 77: offset undefined. Can anyone help?

    #77 line of your code

    Code:
    function GetVertOffset (srchStr) {
        GblTop = $(srchStr).offset().top - parseFloat($(srchStr).css('marginTop').replace(/auto/, 0));
    }
    it looks like $(srchStr) might be null or does not have offset() function for some case. you can add error checking code to prevent it. Like this

    Code:
    function GetVertOffset (srchStr) {
        var srcStrDom = $(srchStr);
        if (!srcStrDom && !srcStrDom.offset()) {
            GblTop = $(srchStr).offset().top - parseFloat($(srchStr).css('marginTop').replace(/auto/, 0));
           }
    }

IMN logo majestic logo threadwatch logo seochat tools logo