6a6551d970b68c9c02969fa4084880d90b3de829
[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 if (typeof Ext.getCmp('typo3-pagetree') !== 'undefined') {
39 Ext.getCmp('typo3-pagetree').doLayout();
40 }
41 },
42 Loader: {
43 start: function() {
44 require(['nprogress'], function(NProgress) {
45 NProgress.configure({parent: '.t3js-scaffold-content-module', showSpinner: false});
46 NProgress.start();
47 });
48 },
49 finish: function() {
50 require(['nprogress'], function(NProgress) {
51 NProgress.done();
52 });
53 }
54 },
55 NavigationContainer: {
56 PageTree: {
57 refreshTree: function() {
58 if (typeof Ext.getCmp('typo3-pagetree') !== 'undefined') {
59 Ext.getCmp('typo3-pagetree').activeTree.refreshTree();
60 }
61 }
62 },
63 toggle: function () {
64 $('.t3js-scaffold').toggleClass('scaffold-content-navigation-expanded')
65 },
66 cleanup: function() {
67 $('.t3js-scaffold-modulemenu').removeAttr('style');
68 $('t3js-scaffold-content').removeAttr('style');
69 },
70 hide: function () {
71 $('.t3js-scaffold').removeClass('scaffold-content-navigation-expanded');
72 $('.t3js-scaffold-content-module').removeAttr('style');
73 },
74 show: function (component) {
75 if(component !== undefined) {
76 $('.t3js-scaffold').addClass('scaffold-content-navigation-expanded');
77 }
78 $('.t3js-scaffold-content-navigation [data-component]').hide();
79 $('.t3js-scaffold-content-navigation [data-component=' + component + ']').show();
80 },
81 setUrl: function(urlToLoad) {
82 $('.t3js-scaffold').addClass('scaffold-content-navigation-expanded');
83 $('.t3js-scaffold-content-navigation-iframe').attr('src', urlToLoad);
84 },
85 getUrl: function() {
86 return $('.t3js-scaffold-content-navigation-iframe').attr('src');
87 },
88 refresh: function() {
89 console.log('refresh navi');
90 },
91 calculateScrollbar: function (){
92 TYPO3.Backend.NavigationContainer.cleanup();
93 var $scaffold = $('.t3js-scaffold');
94 var $moduleMenuContainer = $('.t3js-scaffold-modulemenu');
95 var $contentContainer = $('.t3js-scaffold-content');
96 var $moduleMenu = $('.t3js-modulemenu');
97 $moduleMenuContainer.css('overflow', 'auto');
98 var moduleMenuContainerWidth = $moduleMenuContainer.outerWidth();
99 var moduleMenuWidth = $moduleMenu.outerWidth();
100 $moduleMenuContainer.removeAttr('style').css('overflow', 'hidden');
101 if ($scaffold.hasClass('scaffold-modulemenu-expanded') === false) {
102 $moduleMenuContainer.width(moduleMenuContainerWidth + (moduleMenuContainerWidth - moduleMenuWidth));
103 $contentContainer.css('left', moduleMenuContainerWidth + (moduleMenuContainerWidth - moduleMenuWidth))
104 } else {
105 $moduleMenuContainer.removeAttr('style');
106 $contentContainer.removeAttr('style');
107 }
108 $moduleMenuContainer.css('overflow', 'auto');
109 }
110 },
111 /**
112 * Contentcontainer
113 */
114 ContentContainer: {
115 setUrl: function (urlToLoad) {
116 TYPO3.Backend.Loader.start();
117 $('.t3js-scaffold-content-module-iframe')
118 .attr('src', urlToLoad)
119 .one('load', function() {
120 TYPO3.Backend.Loader.finish();
121 });
122 },
123 getUrl: function() {
124 return $('.t3js-scaffold-content-module-iframe').attr('src');
125 },
126 refresh: function() {
127 console.log('refresh content');
128 },
129 getIdFromUrl: function() {
130 if(this.getUrl) {
131 return TYPO3.Utility.getParameterFromUrl(this.getUrl, 'id');
132 } else {
133 return 0;
134 }
135 }
136 }
137 };
138
139 // start the module menu app
140 TYPO3.Backend.initialize();
141 return TYPO3.Backend;
142 }
143 );
144
145