metanohi/prestatic/aesthetics.js

67 lines
2.4 KiB
JavaScript
Raw Normal View History

2011-07-08 15:32:28 +02:00
/*
To the extent possible under law, Niels Serup has waived all copyright and
related or neighboring rights to this file. This file is available under the
Creative Commons Zero 1.0 license, see
http://creativecommons.org/publicdomain/zero/1.0/
2011-07-08 15:32:28 +02:00
This JavaScript file contains trivial code. It is required for aesthetic
reasons only. Not loading it will not make a website depending on it less
functional.
*/
2011-07-08 15:32:28 +02:00
get_window_size = function() {
if (window.innerHeight)
return [window.innerHeight, window.innerWidth];
else if (self.innerHeight)
return [self.innerHeight, self.innerWidth];
2011-07-07 00:13:47 +02:00
else if (document.documentElement && document.documentElement.clientHeight)
return [document.documentElement.clientHeight,
document.documentElement.clientWidth];
2011-07-07 00:13:47 +02:00
else if (document.body)
return [document.body.clientHeight, document.body.clientWidth];
2011-07-08 15:32:28 +02:00
};
2011-07-07 00:13:47 +02:00
2011-07-08 15:32:28 +02:00
is_screen_media = function() {
return (document.getElementsByTagName('link')[1].getAttribute('media').indexOf(
'screen') != -1 || (document.styleSheets &&
(document.styleSheets[0].media.mediaText.indexOf(
'screen') != -1 || document.styleSheets[0].media.indexOf(
'screen') != -1)));
2011-07-08 15:32:28 +02:00
};
2011-07-07 00:13:47 +02:00
2011-07-08 15:32:28 +02:00
set_min_height = function() {
var ws, wh, ww, h;
ws = get_window_size();
wh = ws[0];
ww = ws[1];
if (metadiv.offsetTop > wh)
return;
h = metadiv.offsetHeight + 25;
metadiv.style.position = 'absolute';
metadiv.style.bottom = '5px';
metadiv.style.width = (contentdiv.offsetWidth - 42) + 'px';
contentdiv.style.paddingBottom = h + 'px';
h = wh - h - menudiv.offsetHeight - 146;
contentdiv.style.minHeight = h + 'px';
2011-07-26 03:04:17 +02:00
};
adjust_sizes = function() {
set_min_height();
2011-07-08 15:32:28 +02:00
};
2011-07-07 00:13:47 +02:00
window.addEventListener('load', function(event){
if (!is_screen_media())
return;
menudiv = document.getElementById('menu');
contentdiv = document.getElementById('content');
metadiv = document.getElementById('metadata');
window.addEventListener('resize', function(event){
adjust_sizes();
}, false);
adjust_sizes();
}, false);