Reply
Can't get cookie to cap frequency
Old 04-15-2008, 08:01 PM Can't get cookie to cap frequency
Junior Talker

Posts: 4
I had a rather simple show hide using jquery with a cookie that worked. I want to replace it with a more elegant solution that swaps between a close and a replay gif depending on state and whether the hidden div has already been seen by a repeat visitor. I am tearing my hair out.

My demo

http://www.cincinnati.com/test/test.html

Code:
$(document).ready(function(){

if(!document.cookie.match("sbFirstSlide")){
  var oneDay = new Date();
  oneDay.setDate(oneDay.getDate()+1); 
  document.cookie="slidedToday=true;path=/;expires="+oneDay.toGMTString();
  }

 var slideTimeout // timer
   , sbTrigger = $('#slidebartrigger') // convenience
   , sbFirstSlide = true // indicates first time through
   ;
 function toggleSlideboxes(){

   if(slideTimeout) clearTimeout(slideTimeout);

   var isDown = sbTrigger.is('.closeSlide');
   
   $('#slidebar')['slide' + (isDown ? 'Up' : 'Down')]((isDown ? 3000 :
1000), function(){

       if(sbFirstSlide){ sbTrigger.removeClass('firstSlide'); sbFirstSlide
= false; }

       sbTrigger[(isDown ? 'remove' : 'add') +
'Class']('closeSlide').one('click', toggleSlideboxes);

       if(!isDown) slideTimeout = setTimeout(toggleSlideboxes, 4000);
     });
 }
 toggleSlideboxes();
});
somnamblst is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 04-16-2008, 12:30 PM Re: Can't get cookie to cap frequency
Junior Talker

Posts: 4
I have my cookie being set, it is capping the slide down of the slidebar div, but I now have a new issue. The cookie is preventing the slidebartrigger from showing and hiding slidebar on user initiated clicks.

http://www.cincinnati.com/test/testNew.html

Code:
$(document).ready(function()
{
 var slideTimeout, sbTrigger = $('#slidebartrigger'), sbFirstSlide = (document.cookie.indexOf('slidedToday') == -1);
    
 function toggleSlideboxes()
 {
  if(slideTimeout) clearTimeout(slideTimeout);
  
  var isDown = sbTrigger.is('.closeSlide');
  
  if(sbFirstSlide)
  {
   $('#slidebar')['slide' + (isDown ? 'Up' : 'Down')]((isDown ? 3000 : 1000), function()
   {
    sbTrigger.removeClass('firstSlide');
    
    if(!document.cookie.match("slidedToday"))
    {
     var oneDay = new Date();
     oneDay.setDate(oneDay.getDate()+1); 
     document.cookie="slidedToday=true;path=/;expires="+oneDay.toGMTString();
    }
    else
     sbFirstSlide = false;
   });
   
   sbTrigger[(isDown ? 'remove' : 'add') + 'Class']('closeSlide').one('click', toggleSlideboxes);
   
   if(!isDown) slideTimeout = setTimeout(toggleSlideboxes, 3000);
  }
 }
 
 toggleSlideboxes();
});

Last edited by somnamblst : 04-16-2008 at 12:35 PM.
somnamblst is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Can't get cookie to cap frequency
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.11058 seconds with 13 queries