822dfd56cef2184db4107492e44b099574641034
[Packages/TYPO3.CMS.git] / typo3 / js / extjs / ux / Ext.ux.FitToParent.js
1 /* plugin for resize of grid in single container */
2 Ext.namespace('Ext.ux.plugins');
3
4 Ext.ux.plugins.FitToParent = Ext.extend(Object, {
5 constructor : function(parent) {
6 this.parent = parent;
7 },
8 init : function(c) {
9 c.on('render', function(c) {
10 c.fitToElement = Ext.get(this.parent
11 || c.getPositionEl().dom.parentNode);
12 if (!c.doLayout) {
13 this.fitSizeToParent();
14 Ext.EventManager.onWindowResize(this.fitSizeToParent, this);
15 }
16 }, this, {
17 single : true
18 });
19 if (c.doLayout) {
20 c.monitorResize = true;
21 c.doLayout = c.doLayout.createInterceptor(this.fitSizeToParent);
22 }
23 },
24
25 fitSizeToParent : function() {
26 // Uses the dimension of the current viewport, but removes the document header
27 // initial is the height of the TYPO3 Topbar which i 42. If Topbar is not rendered, set the height as default
28 var documentHeaderHeight = 42 || top.TYPO3.Backend.Topbar.getHeight();
29 var documentHeader = Ext.get('typo3-docheader');
30
31 if (Ext.isObject(documentHeader)) {
32 // use 5px bottom margin
33 documentHeaderHeight -= documentHeader.getHeight() + 5;
34 }
35
36 if (this.heightOffset && Ext.isNumber(this.heightOffset)) {
37 documentHeaderHeight -= parseInt(this.heightOffset, 10);
38 }
39
40 this.fitToElement.setHeight(
41 Ext.lib.Dom.getViewportHeight() - this.fitToElement.getTop() + documentHeaderHeight
42 );
43
44 var pos = this.getPosition(true), size = this.fitToElement.getViewSize();
45 this.setSize(size.width - pos[0], size.height - pos[1]);
46
47 }
48 });