Skip to content

JS Error "base.navWidth[i-1] is undefined #209

Closed

Description

@clicktravel-sukhwant

Hi All,

I have constructed an anythingSlider with 4 tabs contain 4 embedded youtube videos and a bit of text below them.
Everything seems to be working fine, the slides all work, the videos pause and play when a tab is slide too, etc

However I've noticed a js error occuring whenever I slide a tab...

base.navWidth[i-1] is undefined (Line 308) in jquery.anythingslider.js

This is my setup:-

js/jquery-1.6.4.min.js

<script>$j = jQuery.noConflict();</script>

js/jquery.easing.1.2.js
js/swfobject.js
js/jquery.anythingslider.js
js/jquery.anythingslider.video.min.js

My anythingSlider definition is

     <script type="text/javascript">

        if ( window.XMLHttpRequest )    // Dont do this for IE6          
        {
          $j(function(){

            $j('#sliderFeatures').anythingSlider({ 
              toggleArrows        : true,
              infiniteSlides      : false,
              navigationFormatter : function(index, panel){
                return ['test feature 1', 'test feature 2', 'test feature 3', 'test feature 4'][index - 1];
              },
              navigationSize      : 4,                
              onSlideComplete: function(slider) {
                // keep the current navigation tab in view
                slider.navWindow( slider.currentPage ); 
              }                                                            
            });
          });
        }
      </script>

I've currently suppressed the error by adding this into jquery.anythingslider.js

    base.navWidth = function(x,y){
        var i, s = Math.min(x,y),
            e = Math.max(x,y),
            w = 0;
        for (i = s; i < e; i++) {
          if (typeof base.navWidth[i-1] != "undefined")  // <= check if it's defined first
          {
            w += base.navWidths[i-1] || 0;
          }
        }
        return w;
    };

On initialisation the JS seems to run through

  • base.buildNavigation function,
  • into the (o.buildNavigation && (base.pages > 1)) IF,
  • skips the (o.navigationSize !== false && parseInt(o.navigationSize,10) < base.pages) IF - this is where base.navWidths variable is defined!?

During a slide

base.navWidth is called from base.navWindow and errors on the w += base.navWidths[i-1] || 0; statement. The anythingSlider still works I just keep getting the js errors. Seems to me it's running through code it doesn't need to?

Don't know enough about how everything else works in anythingSlider to get to the bottom of it.

Any help appreciated! :)

Activity

  1. clicktravel-sukhwant commented on Nov 3, 2011

    @clicktravel-sukhwant
    Author

    Tried importing my anythingSlider into JSFiddle and I'm getting exactly the same JS error.

  2. Mottie commented on Nov 3, 2011

    @Mottie
    Contributor

    So four tabs with four videos in each? I haven't had a chance to test this issue yet, but why are you setting the navigationSize to 4? Are there more than four tabs? That option is meant to be used if there are too many tabs to show, so it adds navigation arrows to the tabs.

    I will look into fixing the error and get back with you.

  3. clicktravel-sukhwant commented on Nov 3, 2011

    @clicktravel-sukhwant
    Author

    1 video in four tabs....

    my JSFiddle setting are...

    HTML

    <ul id="slider">
    
        <li>
            <div>                                                         <object width="665" height="350">                       <param name="movie" value="http://www.youtube.com/v/beCYGm1vMJ0?version=3&amp;hl=en_US"></param>                       <param name="allowFullScreen" value="true"></param>                       <param name="allowscriptaccess" value="always"></param>                       <embed allowfullscreen="true" width="665" height="350" allowscriptaccess="always" type="application/x-shockwave-flash" src="http://www.youtube.com/v/beCYGm1vMJ0?version=3&amp;hl=en_US"></embed>                     </object>                                                               <div class="sliderDescPanel">                      <h5>test</h5>                                        <p>test</p>                     <p>Release Date: 2011-10-08</p>                   </div>                 </div>
        </li>
    
        <li>
            <div>                                                         <object width="665" height="350">                       <param name="movie" value="http://www.youtube.com/v/BcgDzWR19iA?version=3&amp;hl=en_US"></param>                       <param name="allowFullScreen" value="true"></param>                       <param name="allowscriptaccess" value="always"></param>                       <embed allowfullscreen="true" width="665" height="350" allowscriptaccess="always" type="application/x-shockwave-flash" src="http://www.youtube.com/v/BcgDzWR19iA?version=3&amp;hl=en_US"></embed>                     </object>                                                               <div class="sliderDescPanel">                      <h5>Staging test feature</h5>                                        <p>Staging test feature</p>                     <p>Release Date: 2011-10-08</p>                   </div>                 </div>
        </li>
    
        <li>
            <div>                                                         <object width="665" height="350">                       <param name="movie" value="http://www.youtube.com/v/nxA0a5G6ccg?version=3&amp;hl=en_US"></param>                       <param name="allowFullScreen" value="true"></param>                       <param name="allowscriptaccess" value="always"></param>                       <embed allowfullscreen="true" width="665" height="350" allowscriptaccess="always" type="application/x-shockwave-flash" src="http://www.youtube.com/v/nxA0a5G6ccg?version=3&amp;hl=en_US"></embed>                     </object>                                                               <div class="sliderDescPanel">                      <h5>test feature 2</h5>                                        <p>test feature 2</p>                     <p>Release Date: 2011-10-08</p>                   </div>                 </div>
        </li>
    
        <li>
            <div>                                                         <object width="665" height="350">                       <param name="movie" value="http://www.youtube.com/v/hOSYiT2iG08?version=3&amp;hl=en_US"></param>                       <param name="allowFullScreen" value="true"></param>                       <param name="allowscriptaccess" value="always"></param>                       <embed allowfullscreen="true" width="665" height="350" allowscriptaccess="always" type="application/x-shockwave-flash" src="http://www.youtube.com/v/hOSYiT2iG08?version=3&amp;hl=en_US"></embed>                     </object>                                                               <div class="sliderDescPanel">                      <h5>test feature 1</h5>                                        <p>test feature 1</p>                     <p>Release Date: 2011-10-08</p>                   </div>                 </div>   
        </li>   
    </ul>
    
    <!-- Add stylesheets here -->
    <link rel="stylesheet" href="http://proloser.github.com/AnythingSlider/css/theme-metallic.css">
    
    <!-- Older IE stylesheet, to reposition navigation arrows, added AFTER the theme stylesheet above -->
    <!--[if lte IE 7]>
    <link rel="stylesheet" href="http://proloser.github.com/AnythingSlider/css/anythingslider-ie.css" type="text/css" media="screen" />
    <![endif]-->

    JS settings

    $('#slider').anythingSlider({
    
        // *********** Appearance ***********
        // Theme name; choose from: minimalist-round, minimalist-square, metallic, construction, cs-portfolio
        theme: 'default',
        // If true, the entire slider will expand to fit the parent element
        expand: false,
        // If true, solitary images/objects in the panel will expand to fit the viewport
        resizeContents: true,
        // If true, all panels will slide vertically; they slide horizontally otherwise
        vertical: false,
        // Set this value to a number and it will show that many slides at once
        showMultiple: false,
        // Anything other than "linear" or "swing" requires the easing plugin
        easing: "swing",
    
        // If true, builds the forwards and backwards buttons
        buildArrows: true,
        // If true, builds a list of anchor links to link to each panel
        buildNavigation: true,
        // If true, builds the start/stop button
        buildStartStop: true,
    
        // Append forward arrow to a HTML element (jQuery Object, selector or HTMLNode), if not null
        appendFowardTo: null,
        // Append back arrow to a HTML element (jQuery Object, selector or HTMLNode), if not null
        appendBackTo: null,
        // Append controls (navigation + start-stop) to a HTML element (jQuery Object, selector or HTMLNode), if not null
        appendControlsTo: null,
        // Append navigation buttons to a HTML element (jQuery Object, selector or HTMLNode), if not null
        appendNavigationTo: null,
        // Append start-stop button to a HTML element (jQuery Object, selector or HTMLNode), if not null
        appendStartStopTo: null,
    
        // If true, side navigation arrows will slide out on hovering & hide @ other times
        toggleArrows: true,
        // if true, slide in controls (navigation + play/stop button) on hover and slide change, hide @ other times
        toggleControls: false,
    
        // Start button text
        startText: "Start",
        // Stop button text
        stopText: "Stop",
        // Link text used to move the slider forward (hidden by CSS, replaced with arrow image)
        forwardText: "&raquo;",
        // Link text used to move the slider back (hidden by CSS, replace with arrow image)
        backText: "&laquo;",
        // Class added to navigation & start/stop button (text copied to title if it is hidden by a negative text indent)
        tooltipClass: 'tooltip',
    
        // if false, arrows will be visible, but not clickable.
        enableArrows: true,
        // if false, navigation links will still be visible, but not clickable.
        enableNavigation: true,
        // if false, the play/stop button will still be visible, but not clickable. Previously "enablePlay"
        enableStartStop: true,
        // if false, keyboard arrow keys will not work for this slider.
        enableKeyboard: true,
    
        // *********** Navigation ***********
        // This sets the initial panel
        startPanel: 1,
        // Amount to go forward or back when changing panels.
        changeBy: 1,
        // Should links change the hashtag in the URL?
        hashTags: true,
        // if false, the slider will not wrap
        infiniteSlides: false,
        // Details at the top of the file on this use (advanced use)
        navigationFormatter: function(index, panel) {
            // This is the default format (show just the panel index number)
            return ['test', 'Staging test feature', 'test feature 2', 'test feature 1'][index - 1];
        },
        // Set this to the maximum number of visible navigation tabs; false to disable
        navigationSize: 4,
    
        // *********** Slideshow options ***********
        // If true, the slideshow will start running; replaces "startStopped" option
        autoPlay: false,
        // If true, user changing slides will not stop the slideshow
        autoPlayLocked: false,
        // If true, starting a slideshow will delay advancing slides; if false, the slider will immediately advance to the next slide when slideshow starts
        autoPlayDelayed: false,
        // If true & the slideshow is active, the slideshow will pause on hover
        pauseOnHover: true,
        // If true & the slideshow is active, the  slideshow will stop on the last page. This also stops the rewind effect  when infiniteSlides is false.
        stopAtEnd: false,
        // If true, the slideshow will move right-to-left
        playRtl: false,
    
        // *********** Times ***********
        // How long between slideshow transitions in AutoPlay mode (in milliseconds)
        delay: 3000,
        // Resume slideshow after user interaction, only if autoplayLocked is true (in milliseconds).
        resumeDelay: 15000,
        // How long the slideshow transition takes (in milliseconds)
        animationTime: 600,
        // How long to pause slide animation before going to the desired slide (used if you want your "out" FX to show).
        delayBeforeAnimate: 0,
    
        // *********** Callbacks ***********
        // Callback before the plugin initializes
        onBeforeInitialize: function(e, slider) {},
        // Callback when the plugin finished initializing
        onInitialized: function(e, slider) {},
        // Callback on slideshow start
        onShowStart: function(e, slider) {},
        // Callback after slideshow stops
        onShowStop: function(e, slider) {},
        // Callback when slideshow pauses
        onShowPause: function(e, slider) {},
        // Callback when slideshow unpauses - may not trigger properly if user clicks on any controls
        onShowUnpause: function(e, slider) {},
        // Callback when slide initiates, before control animation
        onSlideInit: function(e, slider) {},
        // Callback before slide animates
        onSlideBegin: function(e, slider) {},
        // Callback when slide completes - no event variable!
        onSlideComplete: function(slider) {
            // keep the current navigation tab in view       
            slider.navWindow(slider.currentPage);
        },
    
        // *********** Interactivity ***********
        // Event used to activate forward arrow functionality (e.g. add jQuery mobile's "swiperight")
        clickForwardArrow: "click",
        // Event used to activate back arrow functionality (e.g. add jQuery mobile's "swipeleft")
        clickBackArrow: "click",
        // Events used to activate navigation control functionality
        clickControls: "click focusin",
        // Event used to activate slideshow play/stop button
        clickSlideshow: "click",
    
        // *********** Video ***********
        // If true & the slideshow is active & a  youtube video is playing, it will pause the autoplay until the video is  complete
        resumeOnVideoEnd: true,
        // If your slider has an embedded object, the script will automatically add a wmode parameter with this setting
        addWmodeToObject: "opaque",
        // return true if video is playing or false if not - used by video extension
        isVideoPlaying: function(base) {
            return false;
        }
    
    });

    CSS

    /*** Set Slider dimensions here! Version 1.7+ ***/
    /* added #slider li to make panels the same size in case "resizeContents" is false */
    #slider, #slider li {
        width: 665px;
        height: 500px;
        list-style: none;
    }

    Click the slides...what the JS errors (Firefox Error Console)

  4. added a commit that references this issue on Nov 3, 2011
  5. Mottie commented on Nov 3, 2011

    @Mottie
    Contributor

    Ok, I've fixed the issue. But just so you know. The settings you are using don't activate the navigation tab window code because the navigationSize and the number of tabs is the same (4, in this case). So trying to set the navigation window position in the slide complete callback is what was causing the problem:

    onSlideComplete: function(slider) {
        // keep the current navigation tab in view       
        slider.navWindow(slider.currentPage);
    },
    

    It won't cause an error now, but I wanted to let you know that that code isn't necessary unless you plan on having a lot more tabs.

    Also, I've updated the navigationSize wiki docs to include a method to scroll the navigation window while the slider is animating instead of after it has completed.

  6. clicktravel-sukhwant commented on Nov 3, 2011

    @clicktravel-sukhwant
    Author

    Wow thanks! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions