Updated the resizing functionallity of the preview panel. Now it can be used in any other position in webapp

This commit is contained in:
Christoph Haas 2015-06-02 23:40:34 +02:00
parent 466b83f398
commit 19e503842b
2 changed files with 38 additions and 4 deletions

View File

@ -29,7 +29,9 @@ Zarafa.plugins.fileviewer.ViewerPanel = Ext.extend(Ext.Panel, {
title: '',
/**
* @cfg {Boolean} autoResize This flag specifies if the panel gets automatically resized if the window size has changed.
* @cfg {Boolean|Ext.Component} autoResize This flag specifies if the panel gets automatically resized if the window size has changed.
* If it is set to true the panel will listen on the Window update event. Otherwise it will listen to the component
* resize event.
* Defaults to false.
*/
autoResize: false,
@ -57,6 +59,14 @@ Zarafa.plugins.fileviewer.ViewerPanel = Ext.extend(Ext.Panel, {
if (Ext.isDefined(config.autoResize)) {
this.autoResize = config.autoResize;
} else {
this.autoResize = false;
}
if (Ext.isDefined(config.defaultScale)) {
this.defaultScale = config.defaultScale;
} else {
this.defaultScale = 0.8;
}
Ext.applyIf(config, {
@ -90,8 +100,16 @@ Zarafa.plugins.fileviewer.ViewerPanel = Ext.extend(Ext.Panel, {
* @private
*/
initEvents: function () {
if (this.autoResize) {
if (this.autoResize === true) {
Ext.EventManager.onWindowResize(this.resizePanel, this);
} else if(this.autoResize !== false) {
this.autoResize.on('resize', this.resizePanel, this);
// save old autoscroll value and disable autoscrolling
if(Ext.isDefined(this.autoResize.autoScroll)) {
this.autoResize.initialAutoScrollValue = this.autoResize.autoScroll;
this.autoResize.setAutoScroll(false);
}
}
},
@ -100,19 +118,35 @@ Zarafa.plugins.fileviewer.ViewerPanel = Ext.extend(Ext.Panel, {
* @private
*/
onDestroy: function () {
if (this.autoResize) {
if (this.autoResize === true) {
Ext.EventManager.removeResizeListener(this.resizePanel, this);
} else if(this.autoResize !== false) {
this.autoResize.un('resize', this.resizePanel, this);
// re-enable autoscrolling if it was enabled before
if(Ext.isDefined(this.autoResize.autoScroll)) {
this.autoResize.setAutoScroll(this.autoResize.initialAutoScrollValue);
}
}
Zarafa.plugins.fileviewer.ViewerPanel.superclass.onDestroy.call(this, arguments);
},
/**
* This functions resizes the panel to the given width. It will be called on the resize event if autoResize is enabled.
*
* @param {Number} width The window width.
* @param {Number} height The window height.
* @private
*/
resizePanel: function (width, height) {
// the element event will pass more arguments
// than the window resize event
if(arguments.length > 2) {
var autoResizeElement = arguments[0];
width = autoResizeElement.getInnerWidth();
height = autoResizeElement.getInnerHeight();
}
this.setWidth(width * this.defaultScale);
this.setHeight(height * this.defaultScale);

View File

@ -2,7 +2,7 @@
<!DOCTYPE plugin SYSTEM "manifest.dtd">
<plugin version="2">
<info>
<version>1.0</version>
<version>1.0.1</version>
<name>fileviewer</name>
<title>PDF and ODF attachments preview</title>
<author>Christoph Haas</author>