javascript - jQuery cookie key value with case statement -
ok, code far:
$( document ).ready(function() { // setup initial display on page load var menu_state = $.cookie('atd_gridlist'); // listen clicks $('.gridselect').click(function() { $.cookie('atd_gridlist', 'grid'); // update (or set) cookie $(".grid").css("display", "block"); $(".list").css("display", "none"); }); $('.listselect').click(function() { $.cookie('atd_gridlist', 'list'); // update (or set) cookie $(".grid").css("display", "none"); $(".list").css("display", "block"); }); });
i need check see if cookie key has been set, think case statement work not sure how make case read cookie atd_gridlist key values...
if gridselect need show grid div , hide list div, if listselect need show list div , hide grid div, if not set @ all, want grid div loaded default , hide list. expire div every 7 days.
any in right direction appreciated. thanks!
would job?
$(function() { var grid = $('.grid'); var list = $('.list'); var statecookie = 'atd_gridlist'; var setstatecookie = function(value) { $.cookie(statecookie, value, { expires: 7, path: '/' }); } var showbystate = function(state) { state = state || 'grid'; setstatecookie(state); if ('grid' === state) { grid.show(); list.hide(); } else if ('list' === state) { grid.hide(); list.show(); } } $('.gridselect').click(function() { showbystate('grid'); }); $('.listselect').click(function() { showbystate('list'); }); showbystate($.cookie(statecookie)); });
Comments
Post a Comment