source: trunk/expressoAdmin1_2/js/jscode/tabs.js @ 283

Revision 283, 6.5 KB checked in by wmerlotto, 16 years ago (diff)

Internacionalizacao do ExpressoAdmin

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1/**
2 * Tabs class for handling HTML/CSS tabs
3 *
4 * Copyright (C) 2003 Dipl.-Inform. Kai Hofmann and probusiness AG
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 *
20 * Contact information:
21 * Dipl.-Inform. Kai Hofmann
22 * Arberger Heerstr. 92
23 * 28307 Bremen
24 * Germany
25 *
26 *
27 * probusiness AG
28 * Expo-Plaza-Nr. 1
29 * 30539 Hannover
30 * Germany
31 *
32 *
33 * @version 1.0
34 * @author hofmann@hofmann-int.de
35 *
36 * @argument nrTabs Number of Tabs to handle
37 * @argument activeCSSclass CSS class name for active tabs (display:inline)
38 * @argument inactiveCSSclass CSS class name for inactive tabs (display:none)
39 * @argument HTMLtabID HTML ID name prefix that would be used with the tab number as tab name.
40 * @argument HTMLtabcontentID HTML ID prefix for the tab content used with the tab number
41 * @argument HTMLtabselectorID HTML ID prefix for a selectbox used to switch between the tabs
42 * @argument HTMLtabradioID HTML ID prefix for radio button input fields used to switch between the tabs
43 * @argument tabPageKey URL parameter name to use for setting/getting the actual tab
44 */
45 
46function Tabs(nrTabs,activeCSSclass,inactiveCSSclass,HTMLtabID,HTMLtabcontentID,HTMLtabselectorID,HTMLtabradioID,tabPageKey)
47 {
48  this.nrTabs            = nrTabs;
49  this.activeCSSclass    = activeCSSclass;
50  this.inactiveCSSclass  = inactiveCSSclass;
51  this.HTMLtabID         = HTMLtabID;
52  this.HTMLtabcontentID  = HTMLtabcontentID;
53  this.HTMLtabselectorID = HTMLtabselectorID;
54  this.HTMLtabradioID    = HTMLtabradioID;
55  this.tabPageKey        = tabPageKey;
56
57  if (typeof(_tabs_prototype_called) == 'undefined')
58   {
59    _tabs_prototype_called        = true;
60    Tabs.prototype.setActive      = setActive;
61    Tabs.prototype.setInactive    = setInactive;
62    Tabs.prototype.isActive       = isActive;
63    Tabs.prototype.getActive      = getActive;
64    Tabs.prototype.disableAll     = disableAll;
65    Tabs.prototype.display        = display;
66    Tabs.prototype.changeToActive = changeToActive;
67    Tabs.prototype.init           = init;
68   }
69
70
71  /**
72   * Set tab as active
73   *
74   * @argument tabnr The tab number (1-nrTabs) of the tab that should be active
75   */
76  function setActive(tabnr)
77   {
78    if ((tabnr > 0) && (tabnr <= this.nrTabs))
79     {
80      if(document.getElementById(this.HTMLtabID   + tabnr))
81        document.getElementById(this.HTMLtabID   + tabnr).className = this.activeCSSclass;
82      if(document.getElementById(this.HTMLtabcontentID + tabnr))
83        document.getElementById(this.HTMLtabcontentID + tabnr).className = this.activeCSSclass;
84
85      if(document.getElementById(this.HTMLtabselectorID))
86        document.getElementById(this.HTMLtabselectorID).selectedIndex = tabnr-1;
87      if(document.getElementById(this.HTMLtabradioID   + tabnr))
88        document.getElementById(this.HTMLtabradioID   + tabnr).checked = true;
89     }
90   }
91
92
93
94  /**
95   * Set tab as inactive
96   *
97   * @argument tabnr The tab number (1-nrTabs) of the tab that should be inactive
98   */
99  function setInactive(tabnr)
100   {
101    if ((tabnr > 0) && (tabnr <= this.nrTabs))
102     {
103      if(document.getElementById(this.HTMLtabID        + tabnr))
104        document.getElementById(this.HTMLtabID        + tabnr).className = this.inactiveCSSclass;
105      if(document.getElementById(this.HTMLtabcontentID + tabnr))
106        document.getElementById(this.HTMLtabcontentID + tabnr).className = this.inactiveCSSclass;
107     }
108   }
109
110
111  /**
112   * Test if tab is active
113   *
114   * @argument tabnr The tab number (1-nrTabs) of the tab that should be tested
115   * @returns boolean - true if tab is active, false otherwise
116   */
117  function isActive(tabnr)
118   {
119    return(document.getElementById(HTMLtabID + tabnr).className == this.activeCSSclass);
120   }
121
122
123  /**
124   * Get the active tab number
125   *
126   * @returns Tab (1-nrTabs) that is currently active or 0 if non is active.
127   */
128  function getActive()
129   {
130    for (i = 1; i <= this.nrTabs; ++i)
131     {
132      if (this.isActive(i))
133       {
134        return(i);
135       }
136     }
137    return(0);
138   }
139
140
141  /**
142   * Disable all tabs
143   */
144  function disableAll()
145   {
146    for (i = 1; i <= this.nrTabs; ++i)
147     {
148      this.setInactive(i);
149     }
150   }
151
152
153  /**
154   * Disable all tabs and then display the tab number given
155   *
156   * @argument tabnr Tab number to display
157   */
158  function display(tabnr)
159   {
160    this.disableAll(this.nrTabs);
161    this.setActive(tabnr);
162   }
163
164
165  /**
166   * Loop over all tabs - switch off currently active tabs and display the new tab
167   *
168   * @argument tabnr Tab number to display
169   */
170  function changeToActive(tabnr)
171   {
172    for (i = 1; i <= this.nrTabs; ++i)
173     {
174      if (i == tabnr)
175       {
176        if (!this.isActive(i))
177         {
178          this.setActive(i);
179         }
180       }
181      else
182       {
183        if (this.isActive(i))
184         {
185          this.setInactive(i);
186         }
187       }
188     }
189   }
190
191
192  /**
193   * Get url parameter for first tab and display it.
194   */
195  function init()
196   {
197    var tab = 0;
198    var url = document.URL;
199    var pos = url.indexOf("?");
200    if (pos > -1)
201     {
202      var urlparams = url.substr(pos + 1,url.length - (pos + 1));
203      var regexp = new RegExp('(^|&)' + this.tabPageKey + '=[0-9]{1,2}');
204      var urlparamstart = urlparams.search(regexp);
205      if (urlparamstart > -1)
206       {
207        urlparamstart = urlparamstart + ((urlparams[urlparamstart] == '&') ? 1 : 0);
208        var urlparam = urlparams.substr(urlparamstart,urlparams.length - urlparamstart);
209        pos = urlparam.indexOf("&");
210        if (pos > -1)
211         {
212          urlparam = urlparam.substr(0,pos);
213         }
214        pos = urlparam.indexOf("=");
215        if (pos > -1)
216         {
217          var urlparamvalue = urlparam.substr(pos + 1,urlparam.length - (pos + 1));
218          tab = urlparamvalue;
219         }
220       }
221      else
222       {
223        tab = 1;
224       }
225     }
226    else
227     {
228      tab = 1;
229     }
230    if ((tab <= 0) || (tab > this.nrTabs))
231     {
232      tab = 1;
233     }
234    this.display(tab);
235   }
236 }
Note: See TracBrowser for help on using the repository browser.