75382df1f4b4a3d06fc69bfa614d1441160013e5
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Resources / Public / JavaScript / Viewport.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: TYPO3/CMS/Backend/Viewport
16 * Handles the main logic of the TYPO3 backend viewport
17 * @exports TYPO3/CMS/Backend/Viewport
18 */
19 define(
20 'TYPO3/CMS/Backend/Viewport',
21 [
22 'jquery'
23 ],
24 function ($) {
25 'use strict';
26
27 TYPO3.Backend = {
28 initialize: function() {
29 TYPO3.Backend.doLayout();
30 $(document).on('resize', TYPO3.Backend.doLayout);
31 },
32 /**
33 * This function is triggered whenever a re-layouting of component is needed
34 */
35 doLayout: function () {
36 TYPO3.Backend.NavigationContainer.cleanup();
37 TYPO3.Backend.NavigationContainer.calculateScrollbar();
38 $('.t3js-topbar-header').css('padding-right', $('.t3js-scaffold-toolbar').outerWidth());
39 if (typeof Ext.getCmp('typo3-pagetree') !== 'undefined') {
40 Ext.getCmp('typo3-pagetree').doLayout();
41 }
42 },
43 Loader: {
44 start: function() {
45 require(['nprogress'], function(NProgress) {
46 NProgress.configure({parent: '.t3js-scaffold-content-module', showSpinner: false});
47 NProgress.start();
48 });
49 },
50 finish: function() {
51 require(['nprogress'], function(NProgress) {
52 NProgress.done();
53 });
54 }
55 },
56 NavigationContainer: {
57 PageTree: {
58 refreshTree: function() {
59 if (typeof Ext.getCmp('typo3-pagetree') !== 'undefined') {
60 Ext.getCmp('typo3-pagetree').activeTree.refreshTree();
61 }
62 }
63 },
64 toggle: function () {
65 $('.t3js-scaffold').toggleClass('scaffold-content-navigation-expanded')
66 },
67 cleanup: function() {
68 $('.t3js-scaffold-modulemenu').removeAttr('style');
69 $('t3js-scaffold-content').removeAttr('style');
70 },
71 hide: function () {
72 $('.t3js-topbar-button-navigationcomponent').css('visibility', 'hidden');
73 $('.t3js-scaffold').removeClass('scaffold-content-navigation-expanded');
74 $('.t3js-scaffold-content-module').removeAttr('style');
75 },
76 show: function (component) {
77 $('.t3js-topbar-button-navigationcomponent').css('visibility', 'visible');
78 if(component !== undefined) {
79 $('.t3js-scaffold').addClass('scaffold-content-navigation-expanded');
80 }
81 $('.t3js-scaffold-content-navigation [data-component]').hide();
82 $('.t3js-scaffold-content-navigation [data-component=' + component + ']').show();
83 },
84 setUrl: function(urlToLoad) {
85 $('.t3js-scaffold').addClass('scaffold-content-navigation-expanded');
86 $('.t3js-scaffold-content-navigation-iframe').attr('src', urlToLoad);
87 },
88 getUrl: function() {
89 return $('.t3js-scaffold-content-navigation-iframe').attr('src');
90 },
91 refresh: function() {
92 $('.t3js-scaffold-content-navigation-iframe')[0].contentWindow.location.reload();
93 },
94 calculateScrollbar: function (){
95 TYPO3.Backend.NavigationContainer.cleanup();
96 var $scaffold = $('.t3js-scaffold');
97 var $moduleMenuContainer = $('.t3js-scaffold-modulemenu');
98 var $contentContainer = $('.t3js-scaffold-content');
99 var $moduleMenu = $('.t3js-modulemenu');
100 $moduleMenuContainer.css('overflow', 'auto');
101 var moduleMenuContainerWidth = $moduleMenuContainer.outerWidth();
102 var moduleMenuWidth = $moduleMenu.outerWidth();
103 $moduleMenuContainer.removeAttr('style').css('overflow', 'hidden');
104 if ($scaffold.hasClass('scaffold-modulemenu-expanded') === false) {
105 $moduleMenuContainer.width(moduleMenuContainerWidth + (moduleMenuContainerWidth - moduleMenuWidth));
106 $contentContainer.css('left', moduleMenuContainerWidth + (moduleMenuContainerWidth - moduleMenuWidth))
107 } else {
108 $moduleMenuContainer.removeAttr('style');
109 $contentContainer.removeAttr('style');
110 }
111 $moduleMenuContainer.css('overflow', 'auto');
112 }
113 },
114 /**
115 * Contentcontainer
116 */
117 ContentContainer: {
118 // @deprecated since TYPO3 v8, will be removed in v9.
119 // Use top.TYPO3.Backend.ContentContainer.get() instead of top.TYPO3.Backend.ContentContainer.iframe
120 'iframe': $('.t3js-scaffold-content-module-iframe')[0].contentWindow,
121 get: function() {
122 return $('.t3js-scaffold-content-module-iframe')[0].contentWindow;
123 },
124 setUrl: function (urlToLoad) {
125 TYPO3.Backend.Loader.start();
126 $('.t3js-scaffold-content-module-iframe')
127 .attr('src', urlToLoad)
128 .one('load', function() {
129 TYPO3.Backend.Loader.finish();
130 });
131 },
132 getUrl: function() {
133 return $('.t3js-scaffold-content-module-iframe').attr('src');
134 },
135 refresh: function() {
136 $('.t3js-scaffold-content-module-iframe')[0].contentWindow.location.reload();
137 },
138 getIdFromUrl: function() {
139 if(this.getUrl) {
140 return TYPO3.Utility.getParameterFromUrl(this.getUrl, 'id');
141 } else {
142 return 0;
143 }
144 }
145 },
146 Topbar: {
147 topbarSelector: '.t3js-scaffold-header',
148 refresh: function() {
149 $.ajax(TYPO3.settings.ajaxUrls['topbar']).done(function(data) {
150 $(TYPO3.Backend.Topbar.topbarSelector).html(data.topbar);
151 $(TYPO3.Backend.Topbar.topbarSelector).trigger('t3-topbar-update');
152 });
153 },
154 Toolbar: {
155 registerEvent: function (callback) {
156 $(callback);
157 $(TYPO3.Backend.Topbar.topbarSelector).on('t3-topbar-update', callback);
158 }
159 }
160 }
161 };
162
163 // start the module menu app
164 TYPO3.Backend.initialize();
165 return TYPO3.Backend;
166 }
167 );