| author | Edwin Razafimahatratra <edwin@robotalismsoft.com> |
| Wed, 16 Jan 2013 21:26:15 +0100 | |
| changeset 80 | 46b897524cc4 |
| parent 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; |
|
|
78
8c3f0b94d056
big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
42
diff
changeset
|
11 |
this.considerFooterToCenter; |
|
8c3f0b94d056
big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
42
diff
changeset
|
12 |
this.callbacks; |
| 36 | 13 |
|
|
78
8c3f0b94d056
big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
42
diff
changeset
|
14 |
this.init = function(contentId, topId, middleId, bottomId, footerId, minTopBottomHeight, ratio, considerFooterToCenter, callbacks) |
| 36 | 15 |
{ |
|
78
8c3f0b94d056
big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
42
diff
changeset
|
16 |
// Content |
|
8c3f0b94d056
big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
42
diff
changeset
|
17 |
this.content = $('#' + contentId); |
|
8c3f0b94d056
big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
42
diff
changeset
|
18 |
|
|
8c3f0b94d056
big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
42
diff
changeset
|
19 |
// Top |
| 36 | 20 |
if (topId != null) { |
21 |
this.top = $('#' + topId); |
|
22 |
} |
|
|
78
8c3f0b94d056
big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
42
diff
changeset
|
23 |
|
|
8c3f0b94d056
big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
42
diff
changeset
|
24 |
// Middle |
| 36 | 25 |
this.middle = $('#' + middleId); |
26 |
this.middleContainer = $(this.middle).parent(); |
|
|
78
8c3f0b94d056
big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
42
diff
changeset
|
27 |
|
|
8c3f0b94d056
big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
42
diff
changeset
|
28 |
// Bottom |
|
8c3f0b94d056
big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
42
diff
changeset
|
29 |
if (bottomId !== null) { |
| 36 | 30 |
this.bottom = $('#' + bottomId); |
31 |
} |
|
|
78
8c3f0b94d056
big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
42
diff
changeset
|
32 |
|
|
8c3f0b94d056
big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
42
diff
changeset
|
33 |
// Footer |
|
8c3f0b94d056
big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
42
diff
changeset
|
34 |
if (footerId !== null) { |
|
42
01415303372e
écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
36
diff
changeset
|
35 |
this.footer = $('#' + footerId); |
|
01415303372e
écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
36
diff
changeset
|
36 |
} |
|
78
8c3f0b94d056
big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
42
diff
changeset
|
37 |
|
| 36 | 38 |
this.minTopBottomHeight = minTopBottomHeight; |
39 |
this.ratio = ratio; |
|
|
78
8c3f0b94d056
big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
42
diff
changeset
|
40 |
this.considerFooterToCenter = (considerFooterToCenter === undefined || footerId === null) ? false : considerFooterToCenter; |
|
8c3f0b94d056
big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
42
diff
changeset
|
41 |
this.callbacks = callbacks; |
| 36 | 42 |
|
43 |
$(window).resize(this.resizeElements); |
|
44 |
window.onorientationchange = function() { |
|
45 |
incResize.resizeElements(); |
|
46 |
} |
|
47 |
}; |
|
48 |
||
49 |
this.resizeElements = function() |
|
50 |
{ |
|
51 |
var self = incResize; |
|
52 |
||
53 |
// Compute maximun middle element height |
|
|
78
8c3f0b94d056
big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
42
diff
changeset
|
54 |
var heightForTopMiddleBottom = $(self.content).height(); |
|
42
01415303372e
écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
36
diff
changeset
|
55 |
if (self.footer !== undefined) { |
|
78
8c3f0b94d056
big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
42
diff
changeset
|
56 |
heightForTopMiddleBottom -= $(self.footer).height() |
|
42
01415303372e
écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
36
diff
changeset
|
57 |
} |
|
78
8c3f0b94d056
big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
42
diff
changeset
|
58 |
var maxMiddleHeight = heightForTopMiddleBottom - self.minTopBottomHeight * 2; |
| 36 | 59 |
|
|
42
01415303372e
écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
36
diff
changeset
|
60 |
// 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 | 61 |
var middleRatio = 1 / self.ratio; |
62 |
var newMiddleWidth = $(self.middleContainer).width(); |
|
63 |
var newMiddleHeight = newMiddleWidth * middleRatio; |
|
64 |
||
|
78
8c3f0b94d056
big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
42
diff
changeset
|
65 |
if (self.top !== undefined && self.bottom !== undefined && newMiddleHeight > maxMiddleHeight) { |
| 36 | 66 |
newMiddleHeight = maxMiddleHeight; |
67 |
newMiddleWidth = newMiddleHeight * 1 / middleRatio; |
|
68 |
} |
|
69 |
||
|
78
8c3f0b94d056
big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
42
diff
changeset
|
70 |
newMiddleWidth = Math.max(newMiddleWidth, 1); |
|
8c3f0b94d056
big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
42
diff
changeset
|
71 |
newMiddleHeight = Math.max(newMiddleHeight, 1); |
| 36 | 72 |
|
73 |
// Change middle element size and the height of its parent |
|
74 |
$(self.middle).attr('width', newMiddleWidth); |
|
75 |
$(self.middle).attr('height', newMiddleHeight); |
|
76 |
$(self.middleContainer).attr('width', newMiddleWidth); |
|
77 |
$(self.middleContainer).attr('height', newMiddleHeight); |
|
78 |
||
79 |
// Change children size of the middle element |
|
80 |
var children = $(self.middle).children(); |
|
81 |
if (children.length > 0) { |
|
82 |
children.attr('width', newMiddleWidth); |
|
83 |
children.attr('height', newMiddleHeight); |
|
84 |
} |
|
85 |
||
86 |
// Post register the middle element size change |
|
|
78
8c3f0b94d056
big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
42
diff
changeset
|
87 |
if (self.callbacks !== undefined) { |
|
8c3f0b94d056
big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
42
diff
changeset
|
88 |
for (var i = 0; i < self.callbacks.length; ++i) { |
|
8c3f0b94d056
big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
42
diff
changeset
|
89 |
self.callbacks[i](newMiddleWidth, newMiddleHeight); |
|
8c3f0b94d056
big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
42
diff
changeset
|
90 |
} |
| 36 | 91 |
} |
92 |
||
93 |
// Change top and bottom heights |
|
|
78
8c3f0b94d056
big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
42
diff
changeset
|
94 |
if (self.top !== undefined && self.bottom !== undefined) { |
|
8c3f0b94d056
big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
42
diff
changeset
|
95 |
|
| 36 | 96 |
// Get the full height and compute heigth for top and bottom |
|
78
8c3f0b94d056
big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
42
diff
changeset
|
97 |
var remainingHeight = heightForTopMiddleBottom - newMiddleHeight; |
|
8c3f0b94d056
big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
42
diff
changeset
|
98 |
var newTopHeight = remainingHeight / 2.0; |
|
8c3f0b94d056
big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
42
diff
changeset
|
99 |
if (newTopHeight < self.minTopBottomHeight) { |
|
8c3f0b94d056
big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
42
diff
changeset
|
100 |
newTopHeight = self.minTopBottomHeight; |
| 36 | 101 |
} |
|
78
8c3f0b94d056
big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
42
diff
changeset
|
102 |
|
|
8c3f0b94d056
big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
42
diff
changeset
|
103 |
var newBottomHeight = newTopHeight; |
|
8c3f0b94d056
big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
42
diff
changeset
|
104 |
|
|
8c3f0b94d056
big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
42
diff
changeset
|
105 |
if (self.considerFooterToCenter) { |
|
8c3f0b94d056
big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
42
diff
changeset
|
106 |
var halfFooterHeight = $(self.footer).height() / 2; |
|
8c3f0b94d056
big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
42
diff
changeset
|
107 |
newTopHeight += halfFooterHeight; |
|
8c3f0b94d056
big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
42
diff
changeset
|
108 |
newBottomHeight -= halfFooterHeight; |
|
8c3f0b94d056
big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
42
diff
changeset
|
109 |
} |
|
8c3f0b94d056
big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
42
diff
changeset
|
110 |
|
|
8c3f0b94d056
big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
42
diff
changeset
|
111 |
$(self.top).css({"height" : + newTopHeight +'px', "lineHeight" : + newTopHeight + 'px'}); |
|
8c3f0b94d056
big commit after problems
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
42
diff
changeset
|
112 |
$(self.bottom).css({"height" : + newBottomHeight + 'px', "lineHeight" : + newBottomHeight + 'px'}); |
| 36 | 113 |
} |
|
42
01415303372e
écran choix
Edwin Razafimahatratra <edwin@robotalismsoft.com>
parents:
36
diff
changeset
|
114 |
}; |
| 36 | 115 |
} |
116 |
||
117 |
var incResize = new IncResize(); |
|
118 |
||
119 |