-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresizer.js
More file actions
63 lines (59 loc) · 1.71 KB
/
resizer.js
File metadata and controls
63 lines (59 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
(function (window, document, VK) {
function Resizer() {
var resizer = {},
elements = [], lastHeight = null,
interval = 100, started = false,
offsetBottom = function(obj) {
if (!obj) return 0;
var offsetTop = 0,
offsetHeight = obj.offsetHeight || 0;
do {
offsetTop += obj.offsetTop;
} while (obj = obj.offsetParent)
return offsetTop + offsetHeight;
};
function setInterval(p) {
if (p>0) interval = p;
return resizer;
}
resizer.setInterval = setInterval;
function add(obj, extra) {
if (typeof obj === 'string') {
obj = document.getElementById(obj);
}
if (!obj) return resizer;
if (typeof obj.length === 'undefined') {
elements.push({o: obj, e: extra || 0});
} else {
for (var i = 0, l = obj.length; i < l; i++) {
add(obj[i], extra);
}
}
if (!started) {
started = true;
resize();
}
return resizer;
}
resizer.add = add;
function resize() {
if (elements.length) {
var bottom = [];
for (var i = 0, l = elements.length; i < l; i++) {
var elem = elements[i], obj = elem.o, extra = elem.e;
if (obj && obj.offsetHeight) {
bottom.push(offsetBottom(obj) + extra);
}
}
var height = Math.max.apply(window, bottom);
if (height != lastHeight) {
lastHeight = height;
VK.callMethod('resizeWindow', document.body.offsetWidth, height);
}
}
setTimeout(resize, interval);
}
return resizer;
}
window.Resizer = Resizer();
})(window, document, VK);