Updated jquery(+ui) to latest stable versions
[mailer.git] / js / menu-common.js
1 /**
2  * JavaScript for folding/unfolding menus
3  * --------------------------------------------------------------------
4  * $Revision::                                                        $
5  * $Date::                                                            $
6  * $Tag:: 0.2.1-FINAL                                                 $
7  * $Author::                                                          $
8  * --------------------------------------------------------------------
9  * Copyright (c) 2003 - 2009 by Roland Haeder
10  * Copyright (c) 2009 - 2012 by Mailer Developer Team
11  * For more information visit: http://mxchange.org
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 2 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
26  * MA  02110-1301  USA
27  */
28
29 // Init variables
30 var menuStates = new Array();
31 var id         = null;
32
33 /**
34  * Function to fold all menus and unfold current (mainAction) one
35  *
36  * @param       mode                    Unused ATM, is the menu 'mode' and will be 'admin','guest','member' or 'sponsor')
37  * @param       currentAction   Currently selected (clicked) 'action'
38  * @param       action                  Unused ATM, 'action' of menu block
39  * @param       what                    Unused ATM, 'what' of menu entry
40  */
41 function changeMenuFoldState (mode, currentAction, action, what) {
42         // Get all li-tags
43         var li = document.getElementsByTagName('li');
44
45         // Generate tag id
46         id = 'action_menu_' + currentAction;
47
48         // Get element
49         var current = document.getElementById(id);
50
51         // Is it displayed?
52         if (menuStates[id] == true) {
53                 // Then hide it
54                 hideMenu(current, id);
55         } else {
56                 // Else display it
57                 showMenu(current, id);
58         }
59
60         // Stop click
61         return false;
62 }
63
64 // Hide given menu
65 function hideMenu (current, id) {
66         // Change CSS and state
67         current.style.cssText = 'display: none;';
68         menuStates[id] = false;
69 }
70
71 // Show given menu and hide all others
72 function showMenu (current, id) {
73         // Hide all menus first
74         for (id2 in menuStates) {
75                 // Hide this
76                 hideMenu(document.getElementById(id2), id2);
77         } // END - for
78
79         // Last make given menu visible
80         current.style.cssText = 'display: visible;';
81         menuStates[id] = true;
82 }
83
84 // Init all folding states
85 function initMenuFoldStates () {
86         // Init variables
87         var style  = null;
88         var style2 = null;
89
90         // Get all li-tags
91         var li = document.getElementsByTagName('li');
92
93         // Search for all menus
94         for (var i = 0; i < li.length; i++) {
95                 // Skip login/logout
96                 if ((li[i].id.substr(-5, 5) == 'login') || (li[i].id.substr(-6, 6) == 'logout')) {
97                         // Skip this entry
98                         continue;
99                 } // END - if
100
101                 // We only want to look for 'action_menu_foo'
102                 if (li[i].id.substr(0, 12) == 'action_menu_') {
103                         // Okay, found one, so copy it
104                         style = li[i].style.cssText;
105
106                         // Is last char a semicolon
107                         if (style.substr(-1, 1) == ';') {
108                                 // Then cut it off
109                                 style = style.substr(0, (style.length - 1));
110                         } // END - if
111
112                         // Is first part 'display' and last 'none'?
113                         menuStates[li[i].id] = ((style.substr(0, 7) == 'display') && (style.substr((style.length - 4), 4) != 'none'));
114                         //* DEBUG */ document.write('DEBUG: id=' + li[i].id + ',style=' + style + ',' + style.substr(0, 7) + '/' + style.substr((style.length - 4), 4) + '=' + menuStates[li[i].id] + '<br />');
115                 } // END - if
116         } // END - for
117 }