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
Need to repeat a function to escape the cookie I think
Old 04-17-2008, 03:28 PM Need to repeat a function to escape the cookie I think
Junior Talker

Posts: 4
Trades: 0
I have a nonuser initiated show hide using jquery that also swaps images between blank, close & replay depending on the state of a div called slidebar. I have a cookie that caps this slide at once per 24 hrs. However my cookie is now preventing user initiated clicks on slidebarTrigger from showing and hiding the slidebar div. With my limited javascript logic I thought I could just duplicate the sbTrigger div that controls user initiated clicks as sbTrigger2 but have been unable to just paste my duplicate function after my cookie without generating syntax errors.

Working example with absolutely pathed everything
http://www.cincinnati.com/test/testNew.html

So looking at my function preCookied
http://www.cincinnati.com/test/testOld.html

I came up with the following, which may be close but close is only in horeshoes and hand grenades. Am I on the right track or is there a better way to aopproach this.

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);
  }
 }
 var slideTimeout // timer
   , sbTrigger2 = $('#slidebartrigger2') // convenience
   , sbFirstSlide = false // indicates first time through
   ;
 
 function toggleSlideboxes(){
   if(slideTimeout) clearTimeout(slideTimeout);
   var isDown = sbTrigger2.is('.closeSlide');
 
   $('#slidebar')['slide' + (isDown ? 'Up' : 'Down')]((isDown ? 3000 :
1000), function(){
       if(sbFirstSlide){ sbTrigger2.removeClass('firstSlide'); sbFirstSlide
= false; }
       sbTrigger2[(isDown ? 'remove' : 'add') +
'Class']('closeSlide').one('click', toggleSlideboxes);
       if(!isDown) slideTimeout = setTimeout(toggleSlideboxes, 4000);
     });
 }
 toggleSlideboxes();
});

Last edited by somnamblst; 04-17-2008 at 06:18 PM..
somnamblst is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Reply     « Reply to Need to repeat a function to escape the cookie I think
 

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