diff --git a/js/ViewerPanel.js b/js/ViewerPanel.js index 0e43d6a..d19424b 100644 --- a/js/ViewerPanel.js +++ b/js/ViewerPanel.js @@ -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); diff --git a/manifest.xml b/manifest.xml index 4d37869..d827941 100755 --- a/manifest.xml +++ b/manifest.xml @@ -2,7 +2,7 @@ - 1.0 + 1.0.1 fileviewer PDF and ODF attachments preview Christoph Haas