This code is responsible for folding / unfolding the block.

<script type="text/javascript" src=""></script> <script type="text/javascript" src=""></script> <script type="text/javascript"> function showhide(n){ if(n == 3){ $('#std'+n).slideToggle('slow'); if($("#openlink").html() == "<img src=\"/style/default/img/otdz.png\" alt=\"\" title=\"Свернуть\"/>"){ $("#openlink").html("<img src=\"/style/default/img/otdz.png\" alt=\"\" title=\"Развернуть\"/>"); $.cookie("filter_open", "0"); }else{ $("#openlink").html("<img src=\"/style/default/img/otdz.png\" alt=\"close\" title=\"Свернуть\"/>"); $.cookie("filter_open", "1"); } } } </script> 

But a little bit wrong. By default, my block is minimized. When I expand it, then I fold it back, I refresh the page, it will still be expanded from me until I clean the cookie.

    1 answer 1

    It is .slideToggle() execute .slideToggle() only in case of a mismatch between the set cookie and the state of the block. I would add a check before switching, like this:

     <script type="text/javascript"> function showhide(n){ if(n == 3) { if( ( $('#std'+n).is(':visible') && $.cookie('filter_open') == "0") || ( $('#std'+n).is(':hidden') && $.cookie('filter_open') == "1") ) $('#std'+n).slideToggle('slow'); if( $("#openlink").html() == "<img src=\"/style/default/img/otdz.png\" alt=\"\" title=\"Свернуть\"/>") { $("#openlink").html("<img src=\"/style/default/img/otdz.png\" alt=\"\" title=\"Развернуть\"/>"); $.cookie("filter_open", "0"); } else { $("#openlink").html("<img src=\"/style/default/img/otdz.png\" alt=\"close\" title=\"Свернуть\"/>"); $.cookie("filter_open", "1"); } } } </script> 

    The logic is not quite clear at all: what is n , and when the given function is called.

    • In general, everything stopped working with this code. Usage: <a href="javascript://" onclick="showhide(3)" id="openlink"> <img src = "/ style /'.$ setup ['skin']. '/ Img / otdz. png "alt =" "/> </a> if (isset ($ _ COOKIE ['filter_open']) && $ _COOKIE ['filter_open'] == 1) {echo '<div id =" std3 ">'; code echo '</ div>'; } - vitagame 2:01 pm
    • Those. if there is no cookie, or it is not "1", then your php does not display this block at all! :) What did you want. Print it anyway. I didn’t check and debug JS in the answer - it just demonstrates the idea. There are no ready-made decisions for you to write. - Sergiks pm
    • Displays Just did not finish. - vitagame
    • If the cookie is zero, the filter is minimized. Something does not work out to equal zero. - vitagame