My inelegant code for remembering position of panel :(

My inelegant code for remembering position of panel :(

Hi all,

I know someone will enjoy rewritting this chunk of code for me and the community! It's a simply cookie to remember the position of an animated panel so it stays open (or closed) after a page reload. It is working*, but I am sure it can be shorter! Please educate me!

*Actually it's not perfect, when you close the panel you lose the button altogether until another page refresh! Long code that doesn't work!

$(document).ready(function(){
  $("#AdvancedSearchButton").click(function(){
    $("#SearchResultsHeaderContainer").slideDown();
            $.cookie('SearchResultsHeaderContainer', 'opened');
            $("#AdvancedSearchButton").remove();      
            $("#AdvancedSearchButton2").show();   
                  });                                                                                                                                             
            return false;
  });


   $(document).ready(function($) {
var SearchResultsHeaderContainer = $.cookie('SearchResultsHeaderContainer');
if (SearchResultsHeaderContainer == 'opened') {
        $('#SearchResultsHeaderContainer').show();
                        $("#AdvancedSearchButton").remove();   
                        $("#AdvancedSearchButton2").show();
    };
    });
   
      $(document).ready(function($) {
  $("#AdvancedSearchButton2").click(function(){
    $("#SearchResultsHeaderContainer").slideUp();
            $.cookie('SearchResultsHeaderContainer', 'closed');
    });
            return false;
  });
    • Topic Participants

    • tom