0

I have this function which works fine except for updating the gallery information... but when i paste the code snippet in the console (chrome developer tool) it works just fine.. Here is what i paste in the console:

var obj = $('.item_info'),
arr = $.makeArray(obj);
$(".gallery-info").html(arr[0]);

Here is the complete function.

setTimeout(function() { 
// If it is the about us page
if($(".page-id-7").length < 1) {
// if it has bullets
    if($(".rsBullets").length) {
        // move the bullets html
        $(".slider_down .pull-right").addClass("rsUni").prepend($(".rsNav"));       
    }
}
// if page has thumbnails
if($(".rsThumbs").length) {
    // get the slider
    var slider = $(".royalSlider").data('royalSlider');
    // move the thumbnail html
    $(".footer .container-fluid").addClass("rsUni").prepend($(".rsNav"));
    $(".rsNav").toggle();
    // get all divs with the class item-info in an array
    var obj = $('.item_info'),
        arr = $.makeArray(obj);
    // set the gallery-info html to the first item in the array
    $(".gallery-info").html(arr[0]);
    $("#slider_prev").click(function() {
        slider.prev();
    });
    $("#slider_next").click(function() {
        slider.next();
    });
    var curId, totalSlides = slider.numSlides;
    $("#slide_count").html("1 OF "+totalSlides);
    // after slider change
    slider.ev.on('rsAfterSlideChange', function(event) {
        curId = slider.currSlideId + 1;
        // update the count
        $("#slide_count").html(curId+" OF "+totalSlides);
        // update the gallery info to the current item
        $(".gallery-info").html(arr[slider.currSlideId]);
    });
    $(".royalSlider").height("640");
}
}, 0);

$(".gallery-info").html(arr[0]); just below this line i tried to alert(arr[0]) which gives undefined.

Also any performance tips will be appreciated. Thanks

8
  • 1
    What happens exactly, and what should it do? Have you tried using alert() or similar to see in which point the variable has an unexpected content? Commented Mar 13, 2013 at 13:30
  • $(".gallery-info").html(arr[0]); just below this line i tried alert(arr[0]) which is undefined Commented Mar 13, 2013 at 13:35
  • try an alert on $('.item_info').length to see if it's empty. Why are you using a setTimeout with a 0 delay? Commented Mar 13, 2013 at 13:43
  • @Jackopo thanks.. alert($('.item_info').length); returns 0 but i know that there are 2 elements with this class.. Commented Mar 13, 2013 at 13:46
  • I added the timeout function because without it was trying to get slider instance before it was initialized. jQuery fires ready event synchronously to all handlers and as i wanted to fire this instantly i set the timeout to 0 Commented Mar 13, 2013 at 13:49

1 Answer 1

1

I just tried to use another timeout function inside the first one.. not sure if this is the best thing to do but for now it works for me.. i wont make this as the correct answer yet and wait for any better answers.

setTimeout(function() { 
    var obj = $('.item_info'),
            arr = $.makeArray(obj);
            $(".gallery-info").html(arr[0]);
            slider.ev.on('rsAfterSlideChange', function(event) {
             curId = slider.currSlideId + 1;
                $("#slide_count").html(curId+" OF "+totalSlides);
                $(".gallery-info").html(arr[slider.currSlideId]);
            });
        }, 700);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.