Guest User

Untitled

a guest
May 21st, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var ContentHeight = 1;
  2. var TimeToSlide = 50.0;
  3.  
  4. var openAccordion = '';
  5.  
  6. function runAccordion(index)
  7. {
  8.     var nID = "Accordion" + index + "Content";
  9.     if(openAccordion == nID)
  10.         nID = '';
  11.  
  12.     setTimeout("animate(" + new Date().getTime() + "," + TimeToSlide + ",'"
  13.             + openAccordion + "','" + nID + "')", 33);
  14.  
  15.     openAccordion = nID;
  16.    
  17.     /*** new code ***/
  18.     eraseCookie('menu');
  19.     createCookie('menu', nID);
  20. }
  21.  
  22. function animate(lastTick, timeLeft, closingId, openingId)
  23. {  
  24.     var curTick = new Date().getTime();
  25.     var elapsedTicks = curTick - lastTick;
  26.  
  27.     var opening = (openingId == '') ? null : document.getElementById(openingId);
  28.     var closing = (closingId == '') ? null : document.getElementById(closingId);
  29.  
  30.     if(timeLeft <= elapsedTicks)
  31.     {
  32.         if(opening != null)
  33.             opening.style.height = 'auto';
  34.  
  35.         if(closing != null)
  36.         {
  37.             closing.style.display = 'none';
  38.             closing.style.height = '0px';
  39.         }
  40.         return;
  41.     }
  42.  
  43.     timeLeft -= elapsedTicks;
  44.     var newClosedHeight = Math.round((timeLeft/TimeToSlide) * ContentHeight);
  45.  
  46.     if(opening != null)
  47.     {
  48.         if(opening.style.display != 'block')
  49.             opening.style.display = 'block';
  50.         opening.style.height = (ContentHeight - newClosedHeight) + 'px';
  51.     }
  52.  
  53.     if(closing != null)
  54.         closing.style.height = newClosedHeight + 'px';
  55.  
  56.     setTimeout("animate(" + curTick + "," + timeLeft + ",'"
  57.             + closingId + "','" + openingId + "')", 33);
  58. }
  59.  
  60. /*** new code ***/
  61.  
  62. $(function() {
  63.     var nID = readCookie('menu');
  64.     if (nID) {
  65.         $('#' + nID).css({
  66.             height: 'auto',
  67.             display: 'block'
  68.         });
  69.         openAccordion = nID;
  70.     }
  71. });
  72.  
  73. function createCookie(name,value,days) {
  74.     if (days) {
  75.         var date = new Date();
  76.         date.setTime(date.getTime()+(days*24*60*60*1000));
  77.         var expires = "; expires="+date.toGMTString();
  78.     }
  79.     else var expires = "";
  80.     document.cookie = name+"="+value+expires+"; path=/";
  81. }
  82.  
  83. function readCookie(name) {
  84.     var nameEQ = name + "=";
  85.     var ca = document.cookie.split(';');
  86.     for(var i=0;i < ca.length;i++) {
  87.         var c = ca[i];
  88.         while (c.charAt(0)==' ') c = c.substring(1,c.length);
  89.         if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  90.     }
  91.     return null;
  92. }
  93.  
  94. function eraseCookie(name) {
  95.     createCookie(name,"",-1);
  96. }
Add Comment
Please, Sign In to add comment