Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



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

Posts: 4
Trades: 0
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
 
 
Register now for full access!
Old 04-16-2008, 01:30 PM Re: Can't get cookie to cap frequency
Junior Talker

Posts: 4
Trades: 0
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 01:35 PM..
somnamblst is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Can't get cookie to cap frequency
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB 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.10692 seconds with 12 queries