diff options
Diffstat (limited to 'static/js/pages/log_init.js')
| -rw-r--r-- | static/js/pages/log_init.js | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/static/js/pages/log_init.js b/static/js/pages/log_init.js new file mode 100644 index 0000000..93d27b0 --- /dev/null +++ b/static/js/pages/log_init.js @@ -0,0 +1,58 @@ +// Shared initializer for log-like pages (frontpage/log views) that include pichat.js. +// Keeps templates mostly data-only (Recips, MasonryColumnWidth). + +(function($){ + function initLogIfPresent() { + if (typeof window.Recips === 'undefined') { window.Recips = []; } + if (typeof window.initLog === 'function') { window.initLog(window.Recips); } + } + + function initMasonryIfPresent() { + var $posts = $('#posts'); + if (!$posts.length) { return; } + if (typeof $posts.masonry !== 'function') { return; } + + var colWidth = typeof window.MasonryColumnWidth !== 'undefined' ? window.MasonryColumnWidth : 275; + + $posts.masonry({ columnWidth: colWidth }); + $posts.masonry({ singleMode: true }); + $posts.masonry({ resizeable: true }); + $posts.masonry({ animate: true }); + } + + $(initLogIfPresent); + $(window).load(initMasonryIfPresent); +})(jQuery); + +if (typeof window.images_loading_bar !== 'function') { + window.images_loading_bar = function images_loading_bar() { + try { + var imgs = document.getElementsByTagName('img'); + var total = imgs.length; + + if (!total) { + var lb0 = document.getElementById('LB0'); + if (lb0) { lb0.style.display = 'none'; } + return; + } + + var loaded = 0; + for (var i = 0; i < total; i++) { + loaded += imgs[i].complete ? 1 : 0; + } + + var lb1 = document.getElementById('LB1'); + if (lb1) { lb1.style.width = Math.round((loaded / total) * 100) + 'px'; } + + if (loaded === total) { + setTimeout(function() { + var lb0Done = document.getElementById('LB0'); + if (lb0Done) { lb0Done.style.display = 'none'; } + }, 128); + } else { + setTimeout(images_loading_bar, 64); + } + } catch (e) {} + }; +} + |
