summaryrefslogtreecommitdiff
path: root/static/js/pages/log_init.js
diff options
context:
space:
mode:
authoryo momma <shutup@oops.wtf>2026-02-03 02:19:19 +0000
committeryo momma <shutup@oops.wtf>2026-02-03 02:19:19 +0000
commit8004c1fc7957397577f51a409ec2c504c81d7e85 (patch)
tree299f62c7512e45d491dc282784031a770f04abad /static/js/pages/log_init.js
parentc69b6626358052f175543cad0daa3f4aa54046b8 (diff)
Refactor main pages: extract inline JS
Diffstat (limited to 'static/js/pages/log_init.js')
-rw-r--r--static/js/pages/log_init.js58
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) {}
+ };
+}
+