Repository navigation
JS Error "base.navWidth[i-1] is undefined #209
Description
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
clicktravel-sukhwant commentedon Nov 3, 2011
Tried importing my anythingSlider into JSFiddle and I'm getting exactly the same JS error.
Mottie commentedon Nov 3, 2011
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
navigationSizeto4? 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.
clicktravel-sukhwant commentedon Nov 3, 2011
1 video in four tabs....
my JSFiddle setting are...
HTML
JS settings
CSS
Click the slides...what the JS errors (Firefox Error Console)
navigationSize issue #209
Mottie commentedon Nov 3, 2011
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
navigationSizeand 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: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
navigationSizewiki docs to include a method to scroll the navigation window while the slider is animating instead of after it has completed.clicktravel-sukhwant commentedon Nov 3, 2011
Wow thanks! :)