includes/clientside/static/sliders.js
author Dan
Fri, 21 Aug 2009 20:37:55 -0400
changeset 1100 aead4e1ce5df
parent 855 4f7521dd981f
child 1227 bdac73ed481e
permissions -rw-r--r--
Enanium: custom header now has an <a> floating above it that links to the main page.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     1
// Sliding drawers on the sidebar
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     2
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     3
// our global vars
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     4
// the delay between the slide in/out, and a little inertia
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     5
753
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
     6
/*
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
     7
pseudocode:
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
     8
  oninit():
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
     9
    i = 0
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    10
    for every div with class "slideblock", do
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    11
      if ( cookie['mdgSliderState_' || i] == 'closed' )
855
4f7521dd981f Change to search behavior for heading+link in sidebar collapse code
Dan
parents: 779
diff changeset
    12
        div.hide()
753
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    13
        
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    14
      div.trigger.addEvent onclick():
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    15
        if ( div.hidden )
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    16
          div.show()
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    17
          cookie['mdgSliderState_' || i] = 'open'
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    18
        else
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    19
          div.hide()
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    20
          cookie['mdgSliderState_' || i] = 'closed
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    21
          
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    22
      i++
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    23
    
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    24
*/
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    25
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    26
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    27
var sliders_initted = false;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    28
      
582
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 362
diff changeset
    29
var initSliders = function()
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    30
{
753
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    31
  if ( KILL_SWITCH || IE )
57
b354deeaa4c4 Vastly improved compatibility with older versions of IE, particularly 5.0, through the use of a kill switch that turns off all AJAX functions
Dan
parents: 1
diff changeset
    32
    return false;
753
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    33
  
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    34
  var divs = getElementsByClassName(document, "div", "slideblock");
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    35
  var divs2 = getElementsByClassName(document, "div", "slideblock2");
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    36
  for ( var i = 0; i < divs2.length; i++ )
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    37
  {
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    38
    divs.push(divs2[i]);
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    39
  }
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    40
  delete divs2;
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    41
  
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    42
  if ( divs.length < 1 )
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    43
    return false;
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    44
  
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    45
  for ( var i = 0; i < divs.length; i++ )
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    46
  {
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    47
    var div = divs[i];
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    48
    // set a unique id for this slider
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    49
    div.metaid = i;
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    50
    
753
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    51
    var cookiename = 'mdgSliderState_' + i;
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    52
    if ( readCookie(cookiename) == 'closed' )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    53
    {
753
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    54
      div.style.display = 'none';
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    55
    }
753
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    56
    
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    57
    var el = div.previousSibling;
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    58
    if ( !el )
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    59
      continue;
855
4f7521dd981f Change to search behavior for heading+link in sidebar collapse code
Dan
parents: 779
diff changeset
    60
    while ( el.tagName == undefined )
755
9b4cd3ef42f3 Fixed sliders not working right with non-Oxygen themes
Dan
parents: 753
diff changeset
    61
    {
753
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    62
      el = el.previousSibling;
755
9b4cd3ef42f3 Fixed sliders not working right with non-Oxygen themes
Dan
parents: 753
diff changeset
    63
      if ( !el )
9b4cd3ef42f3 Fixed sliders not working right with non-Oxygen themes
Dan
parents: 753
diff changeset
    64
        break;
9b4cd3ef42f3 Fixed sliders not working right with non-Oxygen themes
Dan
parents: 753
diff changeset
    65
    }
9b4cd3ef42f3 Fixed sliders not working right with non-Oxygen themes
Dan
parents: 753
diff changeset
    66
    if ( !el )
9b4cd3ef42f3 Fixed sliders not working right with non-Oxygen themes
Dan
parents: 753
diff changeset
    67
      continue;
753
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    68
    var toggler = el.getElementsByTagName('a')[0];
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    69
    if ( !toggler )
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    70
      continue;
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    71
    toggler.onclick = function()
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    72
    {
779
609e35845ec3 load_component() now accepts an array, and most JS components are loaded all in one request now. Totally modular baby. And failsafe too.
Dan
parents: 755
diff changeset
    73
      load_component(['jquery', 'jquery-ui']);
753
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    74
      
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    75
      var mydiv = this.parentNode.nextSibling;
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    76
      while ( mydiv.tagName != 'DIV' )
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    77
        mydiv = mydiv.nextSibling;
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    78
      if ( mydiv.style.display == 'none' )
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    79
      {
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    80
        $(mydiv).show('blind');
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    81
        var cookiename = 'mdgSliderState_' + mydiv.metaid;
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    82
        createCookie(cookiename, 'open', 365);
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    83
      }
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    84
      else
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    85
      {
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    86
        $(mydiv).hide('blind');
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    87
        var cookiename = 'mdgSliderState_' + mydiv.metaid;
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    88
        createCookie(cookiename, 'closed', 365);
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    89
      }
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    90
      
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    91
      return false;
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    92
    }
33ae51d7c685 Removed Slide-In-Slide-Out-Ala-Digg, replaced with jQuery
Dan
parents: 740
diff changeset
    93
  }
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    94
}
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    95
582
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 362
diff changeset
    96
addOnloadHook(initSliders);
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 362
diff changeset
    97