4146287b1ed939b9ecd17eb8cbddedd8eeda2a17
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Resources / Public / JavaScript / Toolbar / UserMenu.js
1 /**
2 * This file is part of the TYPO3 CMS project.
3 *
4 * It is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU General Public License, either version 2
6 * of the License, or any later version.
7 *
8 * For the full copyright and license information, please read the
9 * LICENSE.txt file that was distributed with this source code.
10 *
11 * The TYPO3 project - inspiring people to share!
12 */
13
14 /**
15 * module to handle the User menu on the top
16 */
17 define('TYPO3/CMS/Backend/Toolbar/UserMenu', ['jquery'], function($) {
18
19 var UserMenu = {
20 options: {
21 containerSelector: '#topbar-user-menu'
22 , toolbarItemSelector: '.toolbar-item'
23 , menuSelector: '.toolbar-item-menu'
24 , menuItemSelector: '.toolbar-item-menu li'
25 }
26 };
27
28 /**
29 * initialize the events for opening and closing the menu on clicking the
30 * toolbarItem and on one of the menuItems
31 */
32 UserMenu.initializeEvents = function() {
33 $(UserMenu.options.toolbarItemSelector + ', ' + UserMenu.options.menuItemSelector, UserMenu.options.containerSelector).on('click', function() {
34 UserMenu.toggleMenu();
35 });
36 };
37
38 /**
39 * shows/hides the menu depending on the current state
40 */
41 UserMenu.toggleMenu = function() {
42 $(UserMenu.options.menuSelector, UserMenu.options.containerSelector).toggle();
43 };
44
45 /**
46 * initialize and return the Menu object
47 */
48 return function() {
49 $(document).ready(function() {
50 UserMenu.initializeEvents();
51 });
52
53 TYPO3.Toolbar = TYPO3.Toolbar || {};
54 TYPO3.Toolbar.UserMenu = UserMenu;
55 return UserMenu;
56 }();
57 });