web/wp-content/themes/newsworthy/tabber.js
author ymh <ymh.work@gmail.com>
Mon, 22 Mar 2010 16:36:28 +0100
changeset 5 ac511f1ccc8e
parent 1 0d28b7c10758
permissions -rw-r--r--
add hgignore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
0d28b7c10758 First commit
ymh
parents:
diff changeset
     1
/*==================================================
0d28b7c10758 First commit
ymh
parents:
diff changeset
     2
  $Id: tabber.js,v 1.9 2006/04/27 20:51:51 pat Exp $
0d28b7c10758 First commit
ymh
parents:
diff changeset
     3
  tabber.js by Patrick Fitzgerald pat@barelyfitz.com
0d28b7c10758 First commit
ymh
parents:
diff changeset
     4
0d28b7c10758 First commit
ymh
parents:
diff changeset
     5
  Documentation can be found at the following URL:
0d28b7c10758 First commit
ymh
parents:
diff changeset
     6
  http://www.barelyfitz.com/projects/tabber/
0d28b7c10758 First commit
ymh
parents:
diff changeset
     7
0d28b7c10758 First commit
ymh
parents:
diff changeset
     8
  License (http://www.opensource.org/licenses/mit-license.php)
0d28b7c10758 First commit
ymh
parents:
diff changeset
     9
0d28b7c10758 First commit
ymh
parents:
diff changeset
    10
  Copyright (c) 2006 Patrick Fitzgerald
0d28b7c10758 First commit
ymh
parents:
diff changeset
    11
0d28b7c10758 First commit
ymh
parents:
diff changeset
    12
  Permission is hereby granted, free of charge, to any person
0d28b7c10758 First commit
ymh
parents:
diff changeset
    13
  obtaining a copy of this software and associated documentation files
0d28b7c10758 First commit
ymh
parents:
diff changeset
    14
  (the "Software"), to deal in the Software without restriction,
0d28b7c10758 First commit
ymh
parents:
diff changeset
    15
  including without limitation the rights to use, copy, modify, merge,
0d28b7c10758 First commit
ymh
parents:
diff changeset
    16
  publish, distribute, sublicense, and/or sell copies of the Software,
0d28b7c10758 First commit
ymh
parents:
diff changeset
    17
  and to permit persons to whom the Software is furnished to do so,
0d28b7c10758 First commit
ymh
parents:
diff changeset
    18
  subject to the following conditions:
0d28b7c10758 First commit
ymh
parents:
diff changeset
    19
0d28b7c10758 First commit
ymh
parents:
diff changeset
    20
  The above copyright notice and this permission notice shall be
0d28b7c10758 First commit
ymh
parents:
diff changeset
    21
  included in all copies or substantial portions of the Software.
0d28b7c10758 First commit
ymh
parents:
diff changeset
    22
0d28b7c10758 First commit
ymh
parents:
diff changeset
    23
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
0d28b7c10758 First commit
ymh
parents:
diff changeset
    24
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
0d28b7c10758 First commit
ymh
parents:
diff changeset
    25
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
0d28b7c10758 First commit
ymh
parents:
diff changeset
    26
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
0d28b7c10758 First commit
ymh
parents:
diff changeset
    27
  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
0d28b7c10758 First commit
ymh
parents:
diff changeset
    28
  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
0d28b7c10758 First commit
ymh
parents:
diff changeset
    29
  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
0d28b7c10758 First commit
ymh
parents:
diff changeset
    30
  SOFTWARE.
0d28b7c10758 First commit
ymh
parents:
diff changeset
    31
  ==================================================*/
0d28b7c10758 First commit
ymh
parents:
diff changeset
    32
0d28b7c10758 First commit
ymh
parents:
diff changeset
    33
function tabberObj(argsObj)
0d28b7c10758 First commit
ymh
parents:
diff changeset
    34
{
0d28b7c10758 First commit
ymh
parents:
diff changeset
    35
  var arg; /* name of an argument to override */
0d28b7c10758 First commit
ymh
parents:
diff changeset
    36
0d28b7c10758 First commit
ymh
parents:
diff changeset
    37
  /* Element for the main tabber div. If you supply this in argsObj,
0d28b7c10758 First commit
ymh
parents:
diff changeset
    38
     then the init() method will be called.
0d28b7c10758 First commit
ymh
parents:
diff changeset
    39
  */
0d28b7c10758 First commit
ymh
parents:
diff changeset
    40
  this.div = null;
0d28b7c10758 First commit
ymh
parents:
diff changeset
    41
0d28b7c10758 First commit
ymh
parents:
diff changeset
    42
  /* Class of the main tabber div */
0d28b7c10758 First commit
ymh
parents:
diff changeset
    43
  this.classMain = "tabber";
0d28b7c10758 First commit
ymh
parents:
diff changeset
    44
0d28b7c10758 First commit
ymh
parents:
diff changeset
    45
  /* Rename classMain to classMainLive after tabifying
0d28b7c10758 First commit
ymh
parents:
diff changeset
    46
     (so a different style can be applied)
0d28b7c10758 First commit
ymh
parents:
diff changeset
    47
  */
0d28b7c10758 First commit
ymh
parents:
diff changeset
    48
  this.classMainLive = "tabberlive";
0d28b7c10758 First commit
ymh
parents:
diff changeset
    49
0d28b7c10758 First commit
ymh
parents:
diff changeset
    50
  /* Class of each DIV that contains a tab */
0d28b7c10758 First commit
ymh
parents:
diff changeset
    51
  this.classTab = "tabbertab";
0d28b7c10758 First commit
ymh
parents:
diff changeset
    52
0d28b7c10758 First commit
ymh
parents:
diff changeset
    53
  /* Class to indicate which tab should be active on startup */
0d28b7c10758 First commit
ymh
parents:
diff changeset
    54
  this.classTabDefault = "tabbertabdefault";
0d28b7c10758 First commit
ymh
parents:
diff changeset
    55
0d28b7c10758 First commit
ymh
parents:
diff changeset
    56
  /* Class for the navigation UL */
0d28b7c10758 First commit
ymh
parents:
diff changeset
    57
  this.classNav = "tabbernav";
0d28b7c10758 First commit
ymh
parents:
diff changeset
    58
0d28b7c10758 First commit
ymh
parents:
diff changeset
    59
  /* When a tab is to be hidden, instead of setting display='none', we
0d28b7c10758 First commit
ymh
parents:
diff changeset
    60
     set the class of the div to classTabHide. In your screen
0d28b7c10758 First commit
ymh
parents:
diff changeset
    61
     stylesheet you should set classTabHide to display:none.  In your
0d28b7c10758 First commit
ymh
parents:
diff changeset
    62
     print stylesheet you should set display:block to ensure that all
0d28b7c10758 First commit
ymh
parents:
diff changeset
    63
     the information is printed.
0d28b7c10758 First commit
ymh
parents:
diff changeset
    64
  */
0d28b7c10758 First commit
ymh
parents:
diff changeset
    65
  this.classTabHide = "tabbertabhide";
0d28b7c10758 First commit
ymh
parents:
diff changeset
    66
0d28b7c10758 First commit
ymh
parents:
diff changeset
    67
  /* Class to set the navigation LI when the tab is active, so you can
0d28b7c10758 First commit
ymh
parents:
diff changeset
    68
     use a different style on the active tab.
0d28b7c10758 First commit
ymh
parents:
diff changeset
    69
  */
0d28b7c10758 First commit
ymh
parents:
diff changeset
    70
  this.classNavActive = "tabberactive";
0d28b7c10758 First commit
ymh
parents:
diff changeset
    71
0d28b7c10758 First commit
ymh
parents:
diff changeset
    72
  /* Elements that might contain the title for the tab, only used if a
0d28b7c10758 First commit
ymh
parents:
diff changeset
    73
     title is not specified in the TITLE attribute of DIV classTab.
0d28b7c10758 First commit
ymh
parents:
diff changeset
    74
  */
0d28b7c10758 First commit
ymh
parents:
diff changeset
    75
  this.titleElements = ['h2','h3','h4','h5','h6'];
0d28b7c10758 First commit
ymh
parents:
diff changeset
    76
0d28b7c10758 First commit
ymh
parents:
diff changeset
    77
  /* Should we strip out the HTML from the innerHTML of the title elements?
0d28b7c10758 First commit
ymh
parents:
diff changeset
    78
     This should usually be true.
0d28b7c10758 First commit
ymh
parents:
diff changeset
    79
  */
0d28b7c10758 First commit
ymh
parents:
diff changeset
    80
  this.titleElementsStripHTML = true;
0d28b7c10758 First commit
ymh
parents:
diff changeset
    81
0d28b7c10758 First commit
ymh
parents:
diff changeset
    82
  /* If the user specified the tab names using a TITLE attribute on
0d28b7c10758 First commit
ymh
parents:
diff changeset
    83
     the DIV, then the browser will display a tooltip whenever the
0d28b7c10758 First commit
ymh
parents:
diff changeset
    84
     mouse is over the DIV. To prevent this tooltip, we can remove the
0d28b7c10758 First commit
ymh
parents:
diff changeset
    85
     TITLE attribute after getting the tab name.
0d28b7c10758 First commit
ymh
parents:
diff changeset
    86
  */
0d28b7c10758 First commit
ymh
parents:
diff changeset
    87
  this.removeTitle = true;
0d28b7c10758 First commit
ymh
parents:
diff changeset
    88
0d28b7c10758 First commit
ymh
parents:
diff changeset
    89
  /* If you want to add an id to each link set this to true */
0d28b7c10758 First commit
ymh
parents:
diff changeset
    90
  this.addLinkId = false;
0d28b7c10758 First commit
ymh
parents:
diff changeset
    91
0d28b7c10758 First commit
ymh
parents:
diff changeset
    92
  /* If addIds==true, then you can set a format for the ids.
0d28b7c10758 First commit
ymh
parents:
diff changeset
    93
     <tabberid> will be replaced with the id of the main tabber div.
0d28b7c10758 First commit
ymh
parents:
diff changeset
    94
     <tabnumberzero> will be replaced with the tab number
0d28b7c10758 First commit
ymh
parents:
diff changeset
    95
       (tab numbers starting at zero)
0d28b7c10758 First commit
ymh
parents:
diff changeset
    96
     <tabnumberone> will be replaced with the tab number
0d28b7c10758 First commit
ymh
parents:
diff changeset
    97
       (tab numbers starting at one)
0d28b7c10758 First commit
ymh
parents:
diff changeset
    98
     <tabtitle> will be replaced by the tab title
0d28b7c10758 First commit
ymh
parents:
diff changeset
    99
       (with all non-alphanumeric characters removed)
0d28b7c10758 First commit
ymh
parents:
diff changeset
   100
   */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   101
  this.linkIdFormat = '<tabberid>nav<tabnumberone>';
0d28b7c10758 First commit
ymh
parents:
diff changeset
   102
0d28b7c10758 First commit
ymh
parents:
diff changeset
   103
  /* You can override the defaults listed above by passing in an object:
0d28b7c10758 First commit
ymh
parents:
diff changeset
   104
     var mytab = new tabber({property:value,property:value});
0d28b7c10758 First commit
ymh
parents:
diff changeset
   105
  */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   106
  for (arg in argsObj) { this[arg] = argsObj[arg]; }
0d28b7c10758 First commit
ymh
parents:
diff changeset
   107
0d28b7c10758 First commit
ymh
parents:
diff changeset
   108
  /* Create regular expressions for the class names; Note: if you
0d28b7c10758 First commit
ymh
parents:
diff changeset
   109
     change the class names after a new object is created you must
0d28b7c10758 First commit
ymh
parents:
diff changeset
   110
     also change these regular expressions.
0d28b7c10758 First commit
ymh
parents:
diff changeset
   111
  */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   112
  this.REclassMain = new RegExp('\\b' + this.classMain + '\\b', 'gi');
0d28b7c10758 First commit
ymh
parents:
diff changeset
   113
  this.REclassMainLive = new RegExp('\\b' + this.classMainLive + '\\b', 'gi');
0d28b7c10758 First commit
ymh
parents:
diff changeset
   114
  this.REclassTab = new RegExp('\\b' + this.classTab + '\\b', 'gi');
0d28b7c10758 First commit
ymh
parents:
diff changeset
   115
  this.REclassTabDefault = new RegExp('\\b' + this.classTabDefault + '\\b', 'gi');
0d28b7c10758 First commit
ymh
parents:
diff changeset
   116
  this.REclassTabHide = new RegExp('\\b' + this.classTabHide + '\\b', 'gi');
0d28b7c10758 First commit
ymh
parents:
diff changeset
   117
0d28b7c10758 First commit
ymh
parents:
diff changeset
   118
  /* Array of objects holding info about each tab */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   119
  this.tabs = new Array();
0d28b7c10758 First commit
ymh
parents:
diff changeset
   120
0d28b7c10758 First commit
ymh
parents:
diff changeset
   121
  /* If the main tabber div was specified, call init() now */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   122
  if (this.div) {
0d28b7c10758 First commit
ymh
parents:
diff changeset
   123
0d28b7c10758 First commit
ymh
parents:
diff changeset
   124
    this.init(this.div);
0d28b7c10758 First commit
ymh
parents:
diff changeset
   125
0d28b7c10758 First commit
ymh
parents:
diff changeset
   126
    /* We don't need the main div anymore, and to prevent a memory leak
0d28b7c10758 First commit
ymh
parents:
diff changeset
   127
       in IE, we must remove the circular reference between the div
0d28b7c10758 First commit
ymh
parents:
diff changeset
   128
       and the tabber object. */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   129
    this.div = null;
0d28b7c10758 First commit
ymh
parents:
diff changeset
   130
  }
0d28b7c10758 First commit
ymh
parents:
diff changeset
   131
}
0d28b7c10758 First commit
ymh
parents:
diff changeset
   132
0d28b7c10758 First commit
ymh
parents:
diff changeset
   133
0d28b7c10758 First commit
ymh
parents:
diff changeset
   134
/*--------------------------------------------------
0d28b7c10758 First commit
ymh
parents:
diff changeset
   135
  Methods for tabberObj
0d28b7c10758 First commit
ymh
parents:
diff changeset
   136
  --------------------------------------------------*/
0d28b7c10758 First commit
ymh
parents:
diff changeset
   137
0d28b7c10758 First commit
ymh
parents:
diff changeset
   138
0d28b7c10758 First commit
ymh
parents:
diff changeset
   139
tabberObj.prototype.init = function(e)
0d28b7c10758 First commit
ymh
parents:
diff changeset
   140
{
0d28b7c10758 First commit
ymh
parents:
diff changeset
   141
  /* Set up the tabber interface.
0d28b7c10758 First commit
ymh
parents:
diff changeset
   142
0d28b7c10758 First commit
ymh
parents:
diff changeset
   143
     e = element (the main containing div)
0d28b7c10758 First commit
ymh
parents:
diff changeset
   144
0d28b7c10758 First commit
ymh
parents:
diff changeset
   145
     Example:
0d28b7c10758 First commit
ymh
parents:
diff changeset
   146
     init(document.getElementById('mytabberdiv'))
0d28b7c10758 First commit
ymh
parents:
diff changeset
   147
   */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   148
0d28b7c10758 First commit
ymh
parents:
diff changeset
   149
  var
0d28b7c10758 First commit
ymh
parents:
diff changeset
   150
  childNodes, /* child nodes of the tabber div */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   151
  i, i2, /* loop indices */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   152
  t, /* object to store info about a single tab */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   153
  defaultTab=0, /* which tab to select by default */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   154
  DOM_ul, /* tabbernav list */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   155
  DOM_li, /* tabbernav list item */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   156
  DOM_a, /* tabbernav link */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   157
  aId, /* A unique id for DOM_a */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   158
  headingElement; /* searching for text to use in the tab */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   159
0d28b7c10758 First commit
ymh
parents:
diff changeset
   160
  /* Verify that the browser supports DOM scripting */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   161
  if (!document.getElementsByTagName) { return false; }
0d28b7c10758 First commit
ymh
parents:
diff changeset
   162
0d28b7c10758 First commit
ymh
parents:
diff changeset
   163
  /* If the main DIV has an ID then save it. */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   164
  if (e.id) {
0d28b7c10758 First commit
ymh
parents:
diff changeset
   165
    this.id = e.id;
0d28b7c10758 First commit
ymh
parents:
diff changeset
   166
  }
0d28b7c10758 First commit
ymh
parents:
diff changeset
   167
0d28b7c10758 First commit
ymh
parents:
diff changeset
   168
  /* Clear the tabs array (but it should normally be empty) */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   169
  this.tabs.length = 0;
0d28b7c10758 First commit
ymh
parents:
diff changeset
   170
0d28b7c10758 First commit
ymh
parents:
diff changeset
   171
  /* Loop through an array of all the child nodes within our tabber element. */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   172
  childNodes = e.childNodes;
0d28b7c10758 First commit
ymh
parents:
diff changeset
   173
  for(i=0; i < childNodes.length; i++) {
0d28b7c10758 First commit
ymh
parents:
diff changeset
   174
0d28b7c10758 First commit
ymh
parents:
diff changeset
   175
    /* Find the nodes where class="tabbertab" */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   176
    if(childNodes[i].className &&
0d28b7c10758 First commit
ymh
parents:
diff changeset
   177
       childNodes[i].className.match(this.REclassTab)) {
0d28b7c10758 First commit
ymh
parents:
diff changeset
   178
      
0d28b7c10758 First commit
ymh
parents:
diff changeset
   179
      /* Create a new object to save info about this tab */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   180
      t = new Object();
0d28b7c10758 First commit
ymh
parents:
diff changeset
   181
      
0d28b7c10758 First commit
ymh
parents:
diff changeset
   182
      /* Save a pointer to the div for this tab */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   183
      t.div = childNodes[i];
0d28b7c10758 First commit
ymh
parents:
diff changeset
   184
      
0d28b7c10758 First commit
ymh
parents:
diff changeset
   185
      /* Add the new object to the array of tabs */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   186
      this.tabs[this.tabs.length] = t;
0d28b7c10758 First commit
ymh
parents:
diff changeset
   187
0d28b7c10758 First commit
ymh
parents:
diff changeset
   188
      /* If the class name contains classTabDefault,
0d28b7c10758 First commit
ymh
parents:
diff changeset
   189
	 then select this tab by default.
0d28b7c10758 First commit
ymh
parents:
diff changeset
   190
      */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   191
      if (childNodes[i].className.match(this.REclassTabDefault)) {
0d28b7c10758 First commit
ymh
parents:
diff changeset
   192
	defaultTab = this.tabs.length-1;
0d28b7c10758 First commit
ymh
parents:
diff changeset
   193
      }
0d28b7c10758 First commit
ymh
parents:
diff changeset
   194
    }
0d28b7c10758 First commit
ymh
parents:
diff changeset
   195
  }
0d28b7c10758 First commit
ymh
parents:
diff changeset
   196
0d28b7c10758 First commit
ymh
parents:
diff changeset
   197
  /* Create a new UL list to hold the tab headings */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   198
  DOM_ul = document.createElement("ul");
0d28b7c10758 First commit
ymh
parents:
diff changeset
   199
  DOM_ul.className = this.classNav;
0d28b7c10758 First commit
ymh
parents:
diff changeset
   200
  
0d28b7c10758 First commit
ymh
parents:
diff changeset
   201
  /* Loop through each tab we found */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   202
  for (i=0; i < this.tabs.length; i++) {
0d28b7c10758 First commit
ymh
parents:
diff changeset
   203
0d28b7c10758 First commit
ymh
parents:
diff changeset
   204
    t = this.tabs[i];
0d28b7c10758 First commit
ymh
parents:
diff changeset
   205
0d28b7c10758 First commit
ymh
parents:
diff changeset
   206
    /* Get the label to use for this tab:
0d28b7c10758 First commit
ymh
parents:
diff changeset
   207
       From the title attribute on the DIV,
0d28b7c10758 First commit
ymh
parents:
diff changeset
   208
       Or from one of the this.titleElements[] elements,
0d28b7c10758 First commit
ymh
parents:
diff changeset
   209
       Or use an automatically generated number.
0d28b7c10758 First commit
ymh
parents:
diff changeset
   210
     */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   211
    t.headingText = t.div.title;
0d28b7c10758 First commit
ymh
parents:
diff changeset
   212
0d28b7c10758 First commit
ymh
parents:
diff changeset
   213
    /* Remove the title attribute to prevent a tooltip from appearing */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   214
    if (this.removeTitle) { t.div.title = ''; }
0d28b7c10758 First commit
ymh
parents:
diff changeset
   215
0d28b7c10758 First commit
ymh
parents:
diff changeset
   216
    if (!t.headingText) {
0d28b7c10758 First commit
ymh
parents:
diff changeset
   217
0d28b7c10758 First commit
ymh
parents:
diff changeset
   218
      /* Title was not defined in the title of the DIV,
0d28b7c10758 First commit
ymh
parents:
diff changeset
   219
	 So try to get the title from an element within the DIV.
0d28b7c10758 First commit
ymh
parents:
diff changeset
   220
	 Go through the list of elements in this.titleElements
0d28b7c10758 First commit
ymh
parents:
diff changeset
   221
	 (typically heading elements ['h2','h3','h4'])
0d28b7c10758 First commit
ymh
parents:
diff changeset
   222
      */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   223
      for (i2=0; i2<this.titleElements.length; i2++) {
0d28b7c10758 First commit
ymh
parents:
diff changeset
   224
	headingElement = t.div.getElementsByTagName(this.titleElements[i2])[0];
0d28b7c10758 First commit
ymh
parents:
diff changeset
   225
	if (headingElement) {
0d28b7c10758 First commit
ymh
parents:
diff changeset
   226
	  t.headingText = headingElement.innerHTML;
0d28b7c10758 First commit
ymh
parents:
diff changeset
   227
	  if (this.titleElementsStripHTML) {
0d28b7c10758 First commit
ymh
parents:
diff changeset
   228
	    t.headingText.replace(/<br>/gi," ");
0d28b7c10758 First commit
ymh
parents:
diff changeset
   229
	    t.headingText = t.headingText.replace(/<[^>]+>/g,"");
0d28b7c10758 First commit
ymh
parents:
diff changeset
   230
	  }
0d28b7c10758 First commit
ymh
parents:
diff changeset
   231
	  break;
0d28b7c10758 First commit
ymh
parents:
diff changeset
   232
	}
0d28b7c10758 First commit
ymh
parents:
diff changeset
   233
      }
0d28b7c10758 First commit
ymh
parents:
diff changeset
   234
    }
0d28b7c10758 First commit
ymh
parents:
diff changeset
   235
0d28b7c10758 First commit
ymh
parents:
diff changeset
   236
    if (!t.headingText) {
0d28b7c10758 First commit
ymh
parents:
diff changeset
   237
      /* Title was not found (or is blank) so automatically generate a
0d28b7c10758 First commit
ymh
parents:
diff changeset
   238
         number for the tab.
0d28b7c10758 First commit
ymh
parents:
diff changeset
   239
      */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   240
      t.headingText = i + 1;
0d28b7c10758 First commit
ymh
parents:
diff changeset
   241
    }
0d28b7c10758 First commit
ymh
parents:
diff changeset
   242
0d28b7c10758 First commit
ymh
parents:
diff changeset
   243
    /* Create a list element for the tab */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   244
    DOM_li = document.createElement("li");
0d28b7c10758 First commit
ymh
parents:
diff changeset
   245
0d28b7c10758 First commit
ymh
parents:
diff changeset
   246
    /* Save a reference to this list item so we can later change it to
0d28b7c10758 First commit
ymh
parents:
diff changeset
   247
       the "active" class */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   248
    t.li = DOM_li;
0d28b7c10758 First commit
ymh
parents:
diff changeset
   249
0d28b7c10758 First commit
ymh
parents:
diff changeset
   250
    /* Create a link to activate the tab */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   251
    DOM_a = document.createElement("a");
0d28b7c10758 First commit
ymh
parents:
diff changeset
   252
    DOM_a.appendChild(document.createTextNode(t.headingText));
0d28b7c10758 First commit
ymh
parents:
diff changeset
   253
    DOM_a.href = "javascript:void(null);";
0d28b7c10758 First commit
ymh
parents:
diff changeset
   254
    DOM_a.title = t.headingText;
0d28b7c10758 First commit
ymh
parents:
diff changeset
   255
    DOM_a.onclick = this.navClick;
0d28b7c10758 First commit
ymh
parents:
diff changeset
   256
0d28b7c10758 First commit
ymh
parents:
diff changeset
   257
    /* Add some properties to the link so we can identify which tab
0d28b7c10758 First commit
ymh
parents:
diff changeset
   258
       was clicked. Later the navClick method will need this.
0d28b7c10758 First commit
ymh
parents:
diff changeset
   259
    */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   260
    DOM_a.tabber = this;
0d28b7c10758 First commit
ymh
parents:
diff changeset
   261
    DOM_a.tabberIndex = i;
0d28b7c10758 First commit
ymh
parents:
diff changeset
   262
0d28b7c10758 First commit
ymh
parents:
diff changeset
   263
    /* Do we need to add an id to DOM_a? */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   264
    if (this.addLinkId && this.linkIdFormat) {
0d28b7c10758 First commit
ymh
parents:
diff changeset
   265
0d28b7c10758 First commit
ymh
parents:
diff changeset
   266
      /* Determine the id name */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   267
      aId = this.linkIdFormat;
0d28b7c10758 First commit
ymh
parents:
diff changeset
   268
      aId = aId.replace(/<tabberid>/gi, this.id);
0d28b7c10758 First commit
ymh
parents:
diff changeset
   269
      aId = aId.replace(/<tabnumberzero>/gi, i);
0d28b7c10758 First commit
ymh
parents:
diff changeset
   270
      aId = aId.replace(/<tabnumberone>/gi, i+1);
0d28b7c10758 First commit
ymh
parents:
diff changeset
   271
      aId = aId.replace(/<tabtitle>/gi, t.headingText.replace(/[^a-zA-Z0-9\-]/gi, ''));
0d28b7c10758 First commit
ymh
parents:
diff changeset
   272
0d28b7c10758 First commit
ymh
parents:
diff changeset
   273
      DOM_a.id = aId;
0d28b7c10758 First commit
ymh
parents:
diff changeset
   274
    }
0d28b7c10758 First commit
ymh
parents:
diff changeset
   275
0d28b7c10758 First commit
ymh
parents:
diff changeset
   276
    /* Add the link to the list element */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   277
    DOM_li.appendChild(DOM_a);
0d28b7c10758 First commit
ymh
parents:
diff changeset
   278
0d28b7c10758 First commit
ymh
parents:
diff changeset
   279
    /* Add the list element to the list */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   280
    DOM_ul.appendChild(DOM_li);
0d28b7c10758 First commit
ymh
parents:
diff changeset
   281
  }
0d28b7c10758 First commit
ymh
parents:
diff changeset
   282
0d28b7c10758 First commit
ymh
parents:
diff changeset
   283
  /* Add the UL list to the beginning of the tabber div */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   284
  e.insertBefore(DOM_ul, e.firstChild);
0d28b7c10758 First commit
ymh
parents:
diff changeset
   285
0d28b7c10758 First commit
ymh
parents:
diff changeset
   286
  /* Make the tabber div "live" so different CSS can be applied */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   287
  e.className = e.className.replace(this.REclassMain, this.classMainLive);
0d28b7c10758 First commit
ymh
parents:
diff changeset
   288
0d28b7c10758 First commit
ymh
parents:
diff changeset
   289
  /* Activate the default tab, and do not call the onclick handler */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   290
  this.tabShow(defaultTab);
0d28b7c10758 First commit
ymh
parents:
diff changeset
   291
0d28b7c10758 First commit
ymh
parents:
diff changeset
   292
  /* If the user specified an onLoad function, call it now. */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   293
  if (typeof this.onLoad == 'function') {
0d28b7c10758 First commit
ymh
parents:
diff changeset
   294
    this.onLoad({tabber:this});
0d28b7c10758 First commit
ymh
parents:
diff changeset
   295
  }
0d28b7c10758 First commit
ymh
parents:
diff changeset
   296
0d28b7c10758 First commit
ymh
parents:
diff changeset
   297
  return this;
0d28b7c10758 First commit
ymh
parents:
diff changeset
   298
};
0d28b7c10758 First commit
ymh
parents:
diff changeset
   299
0d28b7c10758 First commit
ymh
parents:
diff changeset
   300
0d28b7c10758 First commit
ymh
parents:
diff changeset
   301
tabberObj.prototype.navClick = function(event)
0d28b7c10758 First commit
ymh
parents:
diff changeset
   302
{
0d28b7c10758 First commit
ymh
parents:
diff changeset
   303
  /* This method should only be called by the onClick event of an <A>
0d28b7c10758 First commit
ymh
parents:
diff changeset
   304
     element, in which case we will determine which tab was clicked by
0d28b7c10758 First commit
ymh
parents:
diff changeset
   305
     examining a property that we previously attached to the <A>
0d28b7c10758 First commit
ymh
parents:
diff changeset
   306
     element.
0d28b7c10758 First commit
ymh
parents:
diff changeset
   307
0d28b7c10758 First commit
ymh
parents:
diff changeset
   308
     Since this was triggered from an onClick event, the variable
0d28b7c10758 First commit
ymh
parents:
diff changeset
   309
     "this" refers to the <A> element that triggered the onClick
0d28b7c10758 First commit
ymh
parents:
diff changeset
   310
     event (and not to the tabberObj).
0d28b7c10758 First commit
ymh
parents:
diff changeset
   311
0d28b7c10758 First commit
ymh
parents:
diff changeset
   312
     When tabberObj was initialized, we added some extra properties
0d28b7c10758 First commit
ymh
parents:
diff changeset
   313
     to the <A> element, for the purpose of retrieving them now. Get
0d28b7c10758 First commit
ymh
parents:
diff changeset
   314
     the tabberObj object, plus the tab number that was clicked.
0d28b7c10758 First commit
ymh
parents:
diff changeset
   315
  */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   316
0d28b7c10758 First commit
ymh
parents:
diff changeset
   317
  var
0d28b7c10758 First commit
ymh
parents:
diff changeset
   318
  rVal, /* Return value from the user onclick function */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   319
  a, /* element that triggered the onclick event */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   320
  self, /* the tabber object */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   321
  tabberIndex, /* index of the tab that triggered the event */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   322
  onClickArgs; /* args to send the onclick function */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   323
0d28b7c10758 First commit
ymh
parents:
diff changeset
   324
  a = this;
0d28b7c10758 First commit
ymh
parents:
diff changeset
   325
  if (!a.tabber) { return false; }
0d28b7c10758 First commit
ymh
parents:
diff changeset
   326
0d28b7c10758 First commit
ymh
parents:
diff changeset
   327
  self = a.tabber;
0d28b7c10758 First commit
ymh
parents:
diff changeset
   328
  tabberIndex = a.tabberIndex;
0d28b7c10758 First commit
ymh
parents:
diff changeset
   329
0d28b7c10758 First commit
ymh
parents:
diff changeset
   330
  /* Remove focus from the link because it looks ugly.
0d28b7c10758 First commit
ymh
parents:
diff changeset
   331
     I don't know if this is a good idea...
0d28b7c10758 First commit
ymh
parents:
diff changeset
   332
  */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   333
  a.blur();
0d28b7c10758 First commit
ymh
parents:
diff changeset
   334
0d28b7c10758 First commit
ymh
parents:
diff changeset
   335
  /* If the user specified an onClick function, call it now.
0d28b7c10758 First commit
ymh
parents:
diff changeset
   336
     If the function returns false then do not continue.
0d28b7c10758 First commit
ymh
parents:
diff changeset
   337
  */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   338
  if (typeof self.onClick == 'function') {
0d28b7c10758 First commit
ymh
parents:
diff changeset
   339
0d28b7c10758 First commit
ymh
parents:
diff changeset
   340
    onClickArgs = {'tabber':self, 'index':tabberIndex, 'event':event};
0d28b7c10758 First commit
ymh
parents:
diff changeset
   341
0d28b7c10758 First commit
ymh
parents:
diff changeset
   342
    /* IE uses a different way to access the event object */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   343
    if (!event) { onClickArgs.event = window.event; }
0d28b7c10758 First commit
ymh
parents:
diff changeset
   344
0d28b7c10758 First commit
ymh
parents:
diff changeset
   345
    rVal = self.onClick(onClickArgs);
0d28b7c10758 First commit
ymh
parents:
diff changeset
   346
    if (rVal === false) { return false; }
0d28b7c10758 First commit
ymh
parents:
diff changeset
   347
  }
0d28b7c10758 First commit
ymh
parents:
diff changeset
   348
0d28b7c10758 First commit
ymh
parents:
diff changeset
   349
  self.tabShow(tabberIndex);
0d28b7c10758 First commit
ymh
parents:
diff changeset
   350
0d28b7c10758 First commit
ymh
parents:
diff changeset
   351
  return false;
0d28b7c10758 First commit
ymh
parents:
diff changeset
   352
};
0d28b7c10758 First commit
ymh
parents:
diff changeset
   353
0d28b7c10758 First commit
ymh
parents:
diff changeset
   354
0d28b7c10758 First commit
ymh
parents:
diff changeset
   355
tabberObj.prototype.tabHideAll = function()
0d28b7c10758 First commit
ymh
parents:
diff changeset
   356
{
0d28b7c10758 First commit
ymh
parents:
diff changeset
   357
  var i; /* counter */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   358
0d28b7c10758 First commit
ymh
parents:
diff changeset
   359
  /* Hide all tabs and make all navigation links inactive */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   360
  for (i = 0; i < this.tabs.length; i++) {
0d28b7c10758 First commit
ymh
parents:
diff changeset
   361
    this.tabHide(i);
0d28b7c10758 First commit
ymh
parents:
diff changeset
   362
  }
0d28b7c10758 First commit
ymh
parents:
diff changeset
   363
};
0d28b7c10758 First commit
ymh
parents:
diff changeset
   364
0d28b7c10758 First commit
ymh
parents:
diff changeset
   365
0d28b7c10758 First commit
ymh
parents:
diff changeset
   366
tabberObj.prototype.tabHide = function(tabberIndex)
0d28b7c10758 First commit
ymh
parents:
diff changeset
   367
{
0d28b7c10758 First commit
ymh
parents:
diff changeset
   368
  var div;
0d28b7c10758 First commit
ymh
parents:
diff changeset
   369
0d28b7c10758 First commit
ymh
parents:
diff changeset
   370
  if (!this.tabs[tabberIndex]) { return false; }
0d28b7c10758 First commit
ymh
parents:
diff changeset
   371
0d28b7c10758 First commit
ymh
parents:
diff changeset
   372
  /* Hide a single tab and make its navigation link inactive */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   373
  div = this.tabs[tabberIndex].div;
0d28b7c10758 First commit
ymh
parents:
diff changeset
   374
0d28b7c10758 First commit
ymh
parents:
diff changeset
   375
  /* Hide the tab contents by adding classTabHide to the div */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   376
  if (!div.className.match(this.REclassTabHide)) {
0d28b7c10758 First commit
ymh
parents:
diff changeset
   377
    div.className += ' ' + this.classTabHide;
0d28b7c10758 First commit
ymh
parents:
diff changeset
   378
  }
0d28b7c10758 First commit
ymh
parents:
diff changeset
   379
  this.navClearActive(tabberIndex);
0d28b7c10758 First commit
ymh
parents:
diff changeset
   380
0d28b7c10758 First commit
ymh
parents:
diff changeset
   381
  return this;
0d28b7c10758 First commit
ymh
parents:
diff changeset
   382
};
0d28b7c10758 First commit
ymh
parents:
diff changeset
   383
0d28b7c10758 First commit
ymh
parents:
diff changeset
   384
0d28b7c10758 First commit
ymh
parents:
diff changeset
   385
tabberObj.prototype.tabShow = function(tabberIndex)
0d28b7c10758 First commit
ymh
parents:
diff changeset
   386
{
0d28b7c10758 First commit
ymh
parents:
diff changeset
   387
  /* Show the tabberIndex tab and hide all the other tabs */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   388
0d28b7c10758 First commit
ymh
parents:
diff changeset
   389
  var div;
0d28b7c10758 First commit
ymh
parents:
diff changeset
   390
0d28b7c10758 First commit
ymh
parents:
diff changeset
   391
  if (!this.tabs[tabberIndex]) { return false; }
0d28b7c10758 First commit
ymh
parents:
diff changeset
   392
0d28b7c10758 First commit
ymh
parents:
diff changeset
   393
  /* Hide all the tabs first */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   394
  this.tabHideAll();
0d28b7c10758 First commit
ymh
parents:
diff changeset
   395
0d28b7c10758 First commit
ymh
parents:
diff changeset
   396
  /* Get the div that holds this tab */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   397
  div = this.tabs[tabberIndex].div;
0d28b7c10758 First commit
ymh
parents:
diff changeset
   398
0d28b7c10758 First commit
ymh
parents:
diff changeset
   399
  /* Remove classTabHide from the div */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   400
  div.className = div.className.replace(this.REclassTabHide, '');
0d28b7c10758 First commit
ymh
parents:
diff changeset
   401
0d28b7c10758 First commit
ymh
parents:
diff changeset
   402
  /* Mark this tab navigation link as "active" */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   403
  this.navSetActive(tabberIndex);
0d28b7c10758 First commit
ymh
parents:
diff changeset
   404
0d28b7c10758 First commit
ymh
parents:
diff changeset
   405
  /* If the user specified an onTabDisplay function, call it now. */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   406
  if (typeof this.onTabDisplay == 'function') {
0d28b7c10758 First commit
ymh
parents:
diff changeset
   407
    this.onTabDisplay({'tabber':this, 'index':tabberIndex});
0d28b7c10758 First commit
ymh
parents:
diff changeset
   408
  }
0d28b7c10758 First commit
ymh
parents:
diff changeset
   409
0d28b7c10758 First commit
ymh
parents:
diff changeset
   410
  return this;
0d28b7c10758 First commit
ymh
parents:
diff changeset
   411
};
0d28b7c10758 First commit
ymh
parents:
diff changeset
   412
0d28b7c10758 First commit
ymh
parents:
diff changeset
   413
tabberObj.prototype.navSetActive = function(tabberIndex)
0d28b7c10758 First commit
ymh
parents:
diff changeset
   414
{
0d28b7c10758 First commit
ymh
parents:
diff changeset
   415
  /* Note: this method does *not* enforce the rule
0d28b7c10758 First commit
ymh
parents:
diff changeset
   416
     that only one nav item can be active at a time.
0d28b7c10758 First commit
ymh
parents:
diff changeset
   417
  */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   418
0d28b7c10758 First commit
ymh
parents:
diff changeset
   419
  /* Set classNavActive for the navigation list item */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   420
  this.tabs[tabberIndex].li.className = this.classNavActive;
0d28b7c10758 First commit
ymh
parents:
diff changeset
   421
0d28b7c10758 First commit
ymh
parents:
diff changeset
   422
  return this;
0d28b7c10758 First commit
ymh
parents:
diff changeset
   423
};
0d28b7c10758 First commit
ymh
parents:
diff changeset
   424
0d28b7c10758 First commit
ymh
parents:
diff changeset
   425
0d28b7c10758 First commit
ymh
parents:
diff changeset
   426
tabberObj.prototype.navClearActive = function(tabberIndex)
0d28b7c10758 First commit
ymh
parents:
diff changeset
   427
{
0d28b7c10758 First commit
ymh
parents:
diff changeset
   428
  /* Note: this method does *not* enforce the rule
0d28b7c10758 First commit
ymh
parents:
diff changeset
   429
     that one nav should always be active.
0d28b7c10758 First commit
ymh
parents:
diff changeset
   430
  */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   431
0d28b7c10758 First commit
ymh
parents:
diff changeset
   432
  /* Remove classNavActive from the navigation list item */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   433
  this.tabs[tabberIndex].li.className = '';
0d28b7c10758 First commit
ymh
parents:
diff changeset
   434
0d28b7c10758 First commit
ymh
parents:
diff changeset
   435
  return this;
0d28b7c10758 First commit
ymh
parents:
diff changeset
   436
};
0d28b7c10758 First commit
ymh
parents:
diff changeset
   437
0d28b7c10758 First commit
ymh
parents:
diff changeset
   438
0d28b7c10758 First commit
ymh
parents:
diff changeset
   439
/*==================================================*/
0d28b7c10758 First commit
ymh
parents:
diff changeset
   440
0d28b7c10758 First commit
ymh
parents:
diff changeset
   441
0d28b7c10758 First commit
ymh
parents:
diff changeset
   442
function tabberAutomatic(tabberArgs)
0d28b7c10758 First commit
ymh
parents:
diff changeset
   443
{
0d28b7c10758 First commit
ymh
parents:
diff changeset
   444
  /* This function finds all DIV elements in the document where
0d28b7c10758 First commit
ymh
parents:
diff changeset
   445
     class=tabber.classMain, then converts them to use the tabber
0d28b7c10758 First commit
ymh
parents:
diff changeset
   446
     interface.
0d28b7c10758 First commit
ymh
parents:
diff changeset
   447
0d28b7c10758 First commit
ymh
parents:
diff changeset
   448
     tabberArgs = an object to send to "new tabber()"
0d28b7c10758 First commit
ymh
parents:
diff changeset
   449
  */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   450
  var
0d28b7c10758 First commit
ymh
parents:
diff changeset
   451
    tempObj, /* Temporary tabber object */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   452
    divs, /* Array of all divs on the page */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   453
    i; /* Loop index */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   454
0d28b7c10758 First commit
ymh
parents:
diff changeset
   455
  if (!tabberArgs) { tabberArgs = {}; }
0d28b7c10758 First commit
ymh
parents:
diff changeset
   456
0d28b7c10758 First commit
ymh
parents:
diff changeset
   457
  /* Create a tabber object so we can get the value of classMain */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   458
  tempObj = new tabberObj(tabberArgs);
0d28b7c10758 First commit
ymh
parents:
diff changeset
   459
0d28b7c10758 First commit
ymh
parents:
diff changeset
   460
  /* Find all DIV elements in the document that have class=tabber */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   461
0d28b7c10758 First commit
ymh
parents:
diff changeset
   462
  /* First get an array of all DIV elements and loop through them */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   463
  divs = document.getElementsByTagName("div");
0d28b7c10758 First commit
ymh
parents:
diff changeset
   464
  for (i=0; i < divs.length; i++) {
0d28b7c10758 First commit
ymh
parents:
diff changeset
   465
    
0d28b7c10758 First commit
ymh
parents:
diff changeset
   466
    /* Is this DIV the correct class? */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   467
    if (divs[i].className &&
0d28b7c10758 First commit
ymh
parents:
diff changeset
   468
	divs[i].className.match(tempObj.REclassMain)) {
0d28b7c10758 First commit
ymh
parents:
diff changeset
   469
      
0d28b7c10758 First commit
ymh
parents:
diff changeset
   470
      /* Now tabify the DIV */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   471
      tabberArgs.div = divs[i];
0d28b7c10758 First commit
ymh
parents:
diff changeset
   472
      divs[i].tabber = new tabberObj(tabberArgs);
0d28b7c10758 First commit
ymh
parents:
diff changeset
   473
    }
0d28b7c10758 First commit
ymh
parents:
diff changeset
   474
  }
0d28b7c10758 First commit
ymh
parents:
diff changeset
   475
  
0d28b7c10758 First commit
ymh
parents:
diff changeset
   476
  return this;
0d28b7c10758 First commit
ymh
parents:
diff changeset
   477
}
0d28b7c10758 First commit
ymh
parents:
diff changeset
   478
0d28b7c10758 First commit
ymh
parents:
diff changeset
   479
0d28b7c10758 First commit
ymh
parents:
diff changeset
   480
/*==================================================*/
0d28b7c10758 First commit
ymh
parents:
diff changeset
   481
0d28b7c10758 First commit
ymh
parents:
diff changeset
   482
0d28b7c10758 First commit
ymh
parents:
diff changeset
   483
function tabberAutomaticOnLoad(tabberArgs)
0d28b7c10758 First commit
ymh
parents:
diff changeset
   484
{
0d28b7c10758 First commit
ymh
parents:
diff changeset
   485
  /* This function adds tabberAutomatic to the window.onload event,
0d28b7c10758 First commit
ymh
parents:
diff changeset
   486
     so it will run after the document has finished loading.
0d28b7c10758 First commit
ymh
parents:
diff changeset
   487
  */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   488
  var oldOnLoad;
0d28b7c10758 First commit
ymh
parents:
diff changeset
   489
0d28b7c10758 First commit
ymh
parents:
diff changeset
   490
  if (!tabberArgs) { tabberArgs = {}; }
0d28b7c10758 First commit
ymh
parents:
diff changeset
   491
0d28b7c10758 First commit
ymh
parents:
diff changeset
   492
  /* Taken from: http://simon.incutio.com/archive/2004/05/26/addLoadEvent */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   493
0d28b7c10758 First commit
ymh
parents:
diff changeset
   494
  oldOnLoad = window.onload;
0d28b7c10758 First commit
ymh
parents:
diff changeset
   495
  if (typeof window.onload != 'function') {
0d28b7c10758 First commit
ymh
parents:
diff changeset
   496
    window.onload = function() {
0d28b7c10758 First commit
ymh
parents:
diff changeset
   497
      tabberAutomatic(tabberArgs);
0d28b7c10758 First commit
ymh
parents:
diff changeset
   498
    };
0d28b7c10758 First commit
ymh
parents:
diff changeset
   499
  } else {
0d28b7c10758 First commit
ymh
parents:
diff changeset
   500
    window.onload = function() {
0d28b7c10758 First commit
ymh
parents:
diff changeset
   501
      oldOnLoad();
0d28b7c10758 First commit
ymh
parents:
diff changeset
   502
      tabberAutomatic(tabberArgs);
0d28b7c10758 First commit
ymh
parents:
diff changeset
   503
    };
0d28b7c10758 First commit
ymh
parents:
diff changeset
   504
  }
0d28b7c10758 First commit
ymh
parents:
diff changeset
   505
}
0d28b7c10758 First commit
ymh
parents:
diff changeset
   506
0d28b7c10758 First commit
ymh
parents:
diff changeset
   507
0d28b7c10758 First commit
ymh
parents:
diff changeset
   508
/*==================================================*/
0d28b7c10758 First commit
ymh
parents:
diff changeset
   509
0d28b7c10758 First commit
ymh
parents:
diff changeset
   510
0d28b7c10758 First commit
ymh
parents:
diff changeset
   511
/* Run tabberAutomaticOnload() unless the "manualStartup" option was specified */
0d28b7c10758 First commit
ymh
parents:
diff changeset
   512
0d28b7c10758 First commit
ymh
parents:
diff changeset
   513
if (typeof tabberOptions == 'undefined') {
0d28b7c10758 First commit
ymh
parents:
diff changeset
   514
0d28b7c10758 First commit
ymh
parents:
diff changeset
   515
    tabberAutomaticOnLoad();
0d28b7c10758 First commit
ymh
parents:
diff changeset
   516
0d28b7c10758 First commit
ymh
parents:
diff changeset
   517
} else {
0d28b7c10758 First commit
ymh
parents:
diff changeset
   518
0d28b7c10758 First commit
ymh
parents:
diff changeset
   519
  if (!tabberOptions['manualStartup']) {
0d28b7c10758 First commit
ymh
parents:
diff changeset
   520
    tabberAutomaticOnLoad(tabberOptions);
0d28b7c10758 First commit
ymh
parents:
diff changeset
   521
  }
0d28b7c10758 First commit
ymh
parents:
diff changeset
   522
0d28b7c10758 First commit
ymh
parents:
diff changeset
   523
}