1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Don't work after reload (script js)

Discussion in 'XenForo Development Discussions' started by Allan, Jun 28, 2014.

  1. Allan

    Allan Well-Known Member

    Hey, i test this script:

    Code:
    <!--
    $('.categoryNodeInfo').prepend("<div class='showhideNodes hideNodes'>{xen:phrase showhideNodes_collapse}</div>");
    var showhideNodesCookie = $.getCookie('showhideNodes');
    var showhideNodesArray=new Array();
    if (showhideNodesCookie) {
    showhideNodesArray = showhideNodesCookie.split(",");
    $.each(showhideNodesArray,function(){
            var selector = 'li[id='+this+']';
            $(selector+' ol.nodeList').hide();
            $(selector+' .showhideNodes').toggleClass('showNodes');
            $(selector+' .showhideNodes').toggleClass('hideNodes');
            $(selector+' .showhideNodes').text('{xen:phrase showhideNodes_expand}');
    });
    }
    $('.showhideNodes').click(
    function() {
    if ($(this).text() == '{xen:phrase showhideNodes_collapse}') {
        $(this).parent().next().slideUp();
        $(this).text('{xen:phrase showhideNodes_expand}');
        //if($.inArray(this,showhideNodesArray) != -1){
            showhideNodesArray.push($(this).parent().parent().attr('id'));
            $.setCookie('showhideNodes',showhideNodesArray.join(","));
        //}
    }
    else if ($(this).text() == '{xen:phrase showhideNodes_expand}') {
        $(this).parent().next().slideDown();
        $(this).text('{xen:phrase showhideNodes_collapse}');
            var remove = $(this).parent().parent().attr('id');
            showhideNodesArray.splice($.inArray(remove,showhideNodesArray),1);
            $.setCookie('showhideNodes',showhideNodesArray.join(","));
    }
    $(this).toggleClass('showNodes');
    $(this).toggleClass('hideNodes');
    });
    //-->
    It works once and after reloading the page doesn't work.

    I have this error in console:

    Screenshot_1.png

    What about you?
     
  2. Chris D

    Chris D XenForo Developer Staff Member

    This line is wrong:

    Code:
    var selector = 'li[id='+this+']';
    The correct way to specfy an element with an ID would be:

    Code:
    var selector = 'li#' + this;
     
    Allan likes this.
  3. Allan

    Allan Well-Known Member

    The reload work now ! Thank you Chris :)

    But don't keeps the user preferences (cookies) :(
     
  4. Allan

    Allan Well-Known Member

    Why cookies don't work ?
     
  5. Chris D

    Chris D XenForo Developer Staff Member

    No idea. You'll maybe need to be specific. Are they not setting? Not getting? Some other issue?
     
  6. Allan

    Allan Well-Known Member

    Difficult to explain, here is a screen of the console errors:

    Screenshot_2.png
     
  7. Chris D

    Chris D XenForo Developer Staff Member

    Do you think it might be something to do with the line that says:

     
  8. Allan

    Allan Well-Known Member

    I corrected this error now, but the problem is still present, the cookies don't work.
     
  9. Allan

    Allan Well-Known Member

    I wonder if it does not lack a parameter "expire" ?
     

Share This Page