3f575fdb49a770af0098aa2326acd09d05baa885
[Packages/TYPO3.CMS.git] / typo3 / js / modulemenu.js
1 /***************************************************************
2 * Copyright notice
3 *
4 * (c) 2007 - 2008 Ingo Renner <ingo@typo3.org>
5 * All rights reserved
6 *
7 * This script is part of the TYPO3 project. The TYPO3 project is
8 * 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 * The GNU General Public License can be found at
14 * http://www.gnu.org/copyleft/gpl.html.
15 * A copy is found in the textfile GPL.txt and important notices to the license
16 * from the author is found in LICENSE.txt distributed with these scripts.
17 *
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27
28 /**
29 * observes clicks on menuHeader and toggles child ul
30 *
31 * @author Ingo Renner
32 * @author Steffen Kamper
33 */
34 var ModuleMenu = Class.create({
35
36 /**
37 * initially register event listeners
38 */
39 initialize: function() {
40
41 // initialize event listeners
42 Event.observe(document, 'dom:loaded', function(){
43 this.registerEventListeners();
44 }.bind(this));
45
46 // initialize some variables
47 this.currentlyHighLightedMainModule = '';
48 this.currentlyHighlightedModuleId = '';
49 },
50
51 /**
52 * registers the event listeners, can be used to re-register them after refreshing the menu
53 */
54 registerEventListeners: function() {
55 $$('#typo3-menu li.menuSection div').invoke('observe', 'click', this.toggleMenu);
56 },
57
58 /**
59 * toggles the associated submodule menu when clicking a main module header
60 */
61 toggleMenu: function(event) {
62 var mainModuleHeader = Event.element(event);
63
64 var mainMenuId = mainModuleHeader.up().identify();
65 var subModulesMenu = mainModuleHeader.next('ul');
66 var state = subModulesMenu.visible();
67
68 // save state
69 new Ajax.Request('ajax.php', {
70 parameters : 'ajaxID=ModuleMenu::saveMenuState&menuid=' + mainMenuId + '&state=' + state
71 });
72
73 if(state) {
74 Effect.BlindUp(subModulesMenu, {duration : 0.1});
75 $(mainModuleHeader).removeClassName('expanded');
76 $(mainModuleHeader).addClassName('collapsed');
77 } else {
78 Effect.BlindDown(subModulesMenu, {duration : 0.1});
79 $(mainModuleHeader).removeClassName('collapsed');
80 $(mainModuleHeader).addClassName('expanded');
81 }
82 },
83
84 /**
85 * refreshes the complete module menu
86 */
87 refreshMenu: function() {
88 new Ajax.Updater('typo3-menu', TS.PATH_typo3 + 'ajax.php', {
89 parameters : 'ajaxID=ModuleMenu::render',
90 asynchronous : false,
91 evalScripts : true
92 });
93
94 this.registerEventListeners();
95 this.highlightModule(this.currentlyHighlightedModuleId, this.currentlyHighLightedMainModule);
96 },
97
98 /**
99 * de-highlights the old menu item and highlights the new one
100 *
101 * @param string css module id to highlight
102 */
103 highlightModule: function(moduleId, mainModule) {
104 // reset the currently highlighted module
105 $$('#typo3-menu .highlighted').invoke('removeClassName', 'highlighted');
106
107 // highlight the new one
108 $(moduleId).addClassName('highlighted');
109
110 if(undefined != mainModule) {
111 this.currentlyHighLightedMainModule = mainModule;
112 }
113 this.currentlyHighlightedModuleId = moduleId;
114 }
115
116 });
117
118 var TYPO3ModuleMenu = new ModuleMenu();
119
120
121 /*******************************************************************************
122 *
123 * Backwards compatability handling down here
124 *
125 ******************************************************************************/
126
127 /**
128 * Highlight module:
129 */
130 var currentlyHighLightedId = '';
131 var currentlyHighLighted_restoreValue = '';
132 var currentlyHighLightedMain = '';
133 function highlightModuleMenuItem(trId, mainModule) {
134 TYPO3ModuleMenu.highlightModule(trId, mainModule);
135
136 currentlyHighLightedId = trId;
137 currentlyHighLightedMain = mainModule;
138 }
139
140
141
142
143
144
145
146
147