--- a/web/static/res/js/incresize.js Tue Jan 15 17:17:14 2013 +0100
+++ b/web/static/res/js/incresize.js Wed Jan 16 08:26:00 2013 +0100
@@ -8,27 +8,37 @@
this.footer;
this.minTopBottomHeight;
this.ratio;
- this.preMiddleSizeFunc;
- this.postMiddleSizeFunc;
+ this.considerFooterToCenter;
+ this.callbacks;
- this.init = function(contantId, topId, middleId, bottomId, footerId, minTopBottomHeight, ratio, preMiddleSizeFunc, postMiddleSizeFunc)
+ this.init = function(contentId, topId, middleId, bottomId, footerId, minTopBottomHeight, ratio, considerFooterToCenter, callbacks)
{
- this.content = $('#' + contantId);
+ // Content
+ this.content = $('#' + contentId);
+
+ // Top
if (topId != null) {
this.top = $('#' + topId);
}
+
+ // Middle
this.middle = $('#' + middleId);
this.middleContainer = $(this.middle).parent();
- if (bottomId != null) {
+
+ // Bottom
+ if (bottomId !== null) {
this.bottom = $('#' + bottomId);
}
- if (footerId != null) {
+
+ // Footer
+ if (footerId !== null) {
this.footer = $('#' + footerId);
}
+
this.minTopBottomHeight = minTopBottomHeight;
this.ratio = ratio;
- this.preMiddleSizeFunc = preMiddleSizeFunc;
- this.postMiddleSizeFunc = postMiddleSizeFunc;
+ this.considerFooterToCenter = (considerFooterToCenter === undefined || footerId === null) ? false : considerFooterToCenter;
+ this.callbacks = callbacks;
$(window).resize(this.resizeElements);
window.onorientationchange = function() {
@@ -41,28 +51,24 @@
var self = incResize;
// Compute maximun middle element height
- var heightForTopMiddleBotom = $(self.content).height() - 70;
+ var heightForTopMiddleBottom = $(self.content).height();
if (self.footer !== undefined) {
- heightForTopMiddleBotom -= $(self.footer).height()
+ heightForTopMiddleBottom -= $(self.footer).height()
}
- var maxMiddleHeight = heightForTopMiddleBotom - self.minTopBottomHeight * 2;
+ var maxMiddleHeight = heightForTopMiddleBottom - self.minTopBottomHeight * 2;
// Get the middle element parent width and test if it is not to big (to let place for top and bottom without adding scroll bars)
var middleRatio = 1 / self.ratio;
var newMiddleWidth = $(self.middleContainer).width();
var newMiddleHeight = newMiddleWidth * middleRatio;
- /*
- if (newMiddleHeight > maxMiddleHeight) {
+ if (self.top !== undefined && self.bottom !== undefined && newMiddleHeight > maxMiddleHeight) {
newMiddleHeight = maxMiddleHeight;
newMiddleWidth = newMiddleHeight * 1 / middleRatio;
}
- */
- // Pre register the middle element size change
- if (self.preMiddleSizeFunc !== undefined && self.preMiddleSizeFunc !== null) {
- self.preMiddleSizeFunc(newMiddleWidth, newMiddleHeight);
- }
+ newMiddleWidth = Math.max(newMiddleWidth, 1);
+ newMiddleHeight = Math.max(newMiddleHeight, 1);
// Change middle element size and the height of its parent
$(self.middle).attr('width', newMiddleWidth);
@@ -78,20 +84,32 @@
}
// Post register the middle element size change
- if (self.postMiddleSizeFunc !== undefined && self.postMiddleSizeFunc !== null) {
- self.postMiddleSizeFunc(newMiddleWidth, newMiddleHeight);
+ if (self.callbacks !== undefined) {
+ for (var i = 0; i < self.callbacks.length; ++i) {
+ self.callbacks[i](newMiddleWidth, newMiddleHeight);
+ }
}
// Change top and bottom heights
- if (this.top != undefined && this.bottom != undefined) {
+ if (self.top !== undefined && self.bottom !== undefined) {
+
// Get the full height and compute heigth for top and bottom
- var remainingHeight = heightForTopMiddleBotom - newMiddleHeight;
- var newOtherHeight = remainingHeight / 2.0;
- if (newOtherHeight < self.minTopBottomHeight) {
- newOtherHeight = self.minTopBottomHeight;
+ var remainingHeight = heightForTopMiddleBottom - newMiddleHeight;
+ var newTopHeight = remainingHeight / 2.0;
+ if (newTopHeight < self.minTopBottomHeight) {
+ newTopHeight = self.minTopBottomHeight;
}
- $(self.top).css({"height" : +newOtherHeight+'px', "lineHeight" : +newOtherHeight+'px'});
- $(self.bottom).css({"height" : +newOtherHeight+'px', "lineHeight" : +newOtherHeight+'px'});
+
+ var newBottomHeight = newTopHeight;
+
+ if (self.considerFooterToCenter) {
+ var halfFooterHeight = $(self.footer).height() / 2;
+ newTopHeight += halfFooterHeight;
+ newBottomHeight -= halfFooterHeight;
+ }
+
+ $(self.top).css({"height" : + newTopHeight +'px', "lineHeight" : + newTopHeight + 'px'});
+ $(self.bottom).css({"height" : + newBottomHeight + 'px', "lineHeight" : + newBottomHeight + 'px'});
}
};
}