| author | Edwin Razafimahatratra <edwin@robotalismsoft.com> |
| Wed, 12 Dec 2012 15:54:57 +0100 | |
| changeset 48 | d92196482ad9 |
| parent 42 | 01415303372e |
| child 78 | 8c3f0b94d056 |
| permissions | -rw-r--r-- |
| 36 | 1 |
function IncResize() |
2 |
{ |
|
3 |
this.content; |
|
4 |
this.top; |
|
5 |
this.middle; |
|
6 |
this.middleContainer; |
|
7 |
this.bottom; |
|
8 |
this.footer; |
|
9 |
this.minTopBottomHeight; |
|
10 |
this.ratio; |
|
11 |
this.preMiddleSizeFunc; |
|
12 |
this.postMiddleSizeFunc; |
|
13 |
||
14 |
this.init = function(contantId, topId, middleId, bottomId, footerId, minTopBottomHeight, ratio, preMiddleSizeFunc, postMiddleSizeFunc) |
|
15 |
{ |
|
16 |
this.content = $('#' + contantId); |
|
17 |
if (topId != null) { |
|
18 |
this.top = $('#' + topId); |
|
19 |
} |
|
20 |
this.middle = $('#' + middleId); |
|
21 |
this.middleContainer = $(this.middle).parent(); |
|
22 |
if (bottomId != null) { |
|
23 |
this.bottom = $('#' + bottomId); |
|
24 |
} |
|
|
42
01415303372e
écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
36
diff
changeset
|
25 |
if (footerId != null) { |
|
01415303372e
écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
36
diff
changeset
|
26 |
this.footer = $('#' + footerId); |
|
01415303372e
écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
36
diff
changeset
|
27 |
} |
| 36 | 28 |
this.minTopBottomHeight = minTopBottomHeight; |
29 |
this.ratio = ratio; |
|
30 |
this.preMiddleSizeFunc = preMiddleSizeFunc; |
|
31 |
this.postMiddleSizeFunc = postMiddleSizeFunc; |
|
32 |
||
33 |
$(window).resize(this.resizeElements); |
|
34 |
window.onorientationchange = function() { |
|
35 |
incResize.resizeElements(); |
|
36 |
} |
|
37 |
}; |
|
38 |
||
39 |
this.resizeElements = function() |
|
40 |
{ |
|
41 |
var self = incResize; |
|
42 |
||
43 |
// Compute maximun middle element height |
|
|
42
01415303372e
écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
36
diff
changeset
|
44 |
var heightForTopMiddleBotom = $(self.content).height() - 70; |
|
01415303372e
écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
36
diff
changeset
|
45 |
if (self.footer !== undefined) { |
|
01415303372e
écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
36
diff
changeset
|
46 |
heightForTopMiddleBotom -= $(self.footer).height() |
|
01415303372e
écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
36
diff
changeset
|
47 |
} |
| 36 | 48 |
var maxMiddleHeight = heightForTopMiddleBotom - self.minTopBottomHeight * 2; |
49 |
||
|
42
01415303372e
écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
36
diff
changeset
|
50 |
// 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) |
| 36 | 51 |
var middleRatio = 1 / self.ratio; |
52 |
var newMiddleWidth = $(self.middleContainer).width(); |
|
53 |
var newMiddleHeight = newMiddleWidth * middleRatio; |
|
54 |
||
55 |
/* |
|
56 |
if (newMiddleHeight > maxMiddleHeight) { |
|
57 |
newMiddleHeight = maxMiddleHeight; |
|
58 |
newMiddleWidth = newMiddleHeight * 1 / middleRatio; |
|
59 |
} |
|
60 |
*/ |
|
61 |
||
62 |
// Pre register the middle element size change |
|
63 |
if (self.preMiddleSizeFunc !== undefined && self.preMiddleSizeFunc !== null) { |
|
64 |
self.preMiddleSizeFunc(newMiddleWidth, newMiddleHeight); |
|
65 |
} |
|
66 |
||
67 |
// Change middle element size and the height of its parent |
|
68 |
$(self.middle).attr('width', newMiddleWidth); |
|
69 |
$(self.middle).attr('height', newMiddleHeight); |
|
70 |
$(self.middleContainer).attr('width', newMiddleWidth); |
|
71 |
$(self.middleContainer).attr('height', newMiddleHeight); |
|
72 |
||
73 |
// Change children size of the middle element |
|
74 |
var children = $(self.middle).children(); |
|
75 |
if (children.length > 0) { |
|
76 |
children.attr('width', newMiddleWidth); |
|
77 |
children.attr('height', newMiddleHeight); |
|
78 |
} |
|
79 |
||
80 |
// Post register the middle element size change |
|
81 |
if (self.postMiddleSizeFunc !== undefined && self.postMiddleSizeFunc !== null) { |
|
82 |
self.postMiddleSizeFunc(newMiddleWidth, newMiddleHeight); |
|
83 |
} |
|
84 |
||
85 |
// Change top and bottom heights |
|
86 |
if (this.top != undefined && this.bottom != undefined) { |
|
87 |
// Get the full height and compute heigth for top and bottom |
|
|
42
01415303372e
écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
36
diff
changeset
|
88 |
var remainingHeight = heightForTopMiddleBotom - newMiddleHeight; |
| 36 | 89 |
var newOtherHeight = remainingHeight / 2.0; |
90 |
if (newOtherHeight < self.minTopBottomHeight) { |
|
91 |
newOtherHeight = self.minTopBottomHeight; |
|
92 |
} |
|
93 |
$(self.top).css({"height" : +newOtherHeight+'px', "lineHeight" : +newOtherHeight+'px'}); |
|
94 |
$(self.bottom).css({"height" : +newOtherHeight+'px', "lineHeight" : +newOtherHeight+'px'}); |
|
95 |
} |
|
|
42
01415303372e
écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
36
diff
changeset
|
96 |
}; |
| 36 | 97 |
} |
98 |
||
99 |
var incResize = new IncResize(); |
|
100 |
||
101 |