CalendarXP.net Support Forum Index CalendarXP.net Support
Most forums here are private and invisible to public.
 
 FAQFAQ   SearchSearch   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[FlatCalendarXP]How to keep the date selected across different pages?

 
Post new topic   Reply to topic    CalendarXP.net Support Forum Index -> CalendarXP F.A.Q.
View previous topic :: View next topic  
Author Message
calendarxp
Site Admin


Joined: 30 Jan 2005
Posts: 409

PostPosted: Sat Mar 19, 2005 9:06 pm    Post subject: [FlatCalendarXP]How to keep the date selected across different pages? Reply with quote

Although you could use server-side script to retrieve the selected date via form postback and restore it in the page onload event, using cookie is just a much easier solution - simply add the following code to the plugins.js:
Code:
function fOnChange(y,m,d,e) {
   if (d!=0) fCreateCookie(_cookieName, y+'-'+m+'-'+d);
   // ... other code, if any ...
}

var _cookieName="selectedDate";
var _sd=fReadCookie(_cookieName);
if (_sd) {
   _sd=_sd.split("-");
   gdSelect=[_sd[0],_sd[1],_sd[2]];
   gCurMonth=[_sd[0],_sd[1]];
}


function fCreateCookie(name,value)
{
   document.cookie = name+"="+value+"; path=/";
}

function fReadCookie(name)
{
   var nameEQ = name + "=";
   var ca = document.cookie.split(';');
   for(var i=0;i < ca.length;i++)
   {
      var c = ca[i];
      while (c.charAt(0)==' ') c = c.substring(1,c.length);
      if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
   }
   return null;
}

The mini calendar beneath the left navigation panel on calendarxp.net is a good example.

NOTE:
  • Do NOT use the fAfterSelected plugin to create cookie, because fAfterSelected may not get called if the event action of the selected date redirects the browser to another place.
  • The above code may not work with certain plugin - e.g. multi-select plugin will disable the regular fSetDate() call which in turn won't trigger the fOnChange() when a date is selected. In order to make it work with the MultiPickerDemo, you will have to append the following code to the end (must be placed after the multi-select plugin code) of plugins.js:
    Code:
    var _cookieName="selectedDate";
    var _cookieStr=fReadCookie(_cookieName);
    var _cds=(_cookieStr&&_cookieStr.length>0)?eval(_cookieStr):[];

    function fCreateCookie(name,value)
    {
       var valueStr="[";
       for (var i=0;i<value.length;i++)
         valueStr+=(i>0?",":"")+"["+value[i][0]+","+value[i][1]+"]";
       valueStr+="]";
       document.cookie = name+"="+valueStr+"; path=/";
    }

    function fReadCookie(name)
    {
       var nameEQ = name + "=";
       var ca = document.cookie.split(';');
       for(var i=0;i < ca.length;i++)
       {
          var c = ca[i];
          while (c.charAt(0)==' ') c = c.substring(1,c.length);
          if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
       }
       return null;
    }
    Then, prepend some code to the fOnload() in plugins.js so that it looks like following:
    Code:
    function fOnload() {
    // -- append code start --
       for (var i=0; i<_cds.length; i++) {
          var _dt0=new Date(_cds[i][0]), _dt1=new Date(_cds[i][1]);
          fAddRange(_dt0.getUTCFullYear(),_dt0.getUTCMonth()+1,_dt0.getUTCDate(),false);
          fAddRange(_dt1.getUTCFullYear(),_dt1.getUTCMonth()+1,_dt1.getUTCDate(),true);
       }
    // -- append code end --
       if (gContainer.fInitAgenda) gContainer.fInitAgenda();
    }
    Finally, append the following line to the bottom (last line in function) of both fAddRange() and fRemoveRange():
    Code:
    fCreateCookie(_cookieName,_pds);


_________________
Copyright 2003-2011 Idemfactor Solutions, Inc. All rights reserved.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    CalendarXP.net Support Forum Index -> CalendarXP F.A.Q. All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


Copyright 2003- Idemfactor Solutions, Inc. All rights reserved.
Powered by phpBB © 2001, 2005 phpBB Group