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