From 8004c1fc7957397577f51a409ec2c504c81d7e85 Mon Sep 17 00:00:00 2001 From: yo momma Date: Tue, 3 Feb 2026 02:19:19 +0000 Subject: Refactor main pages: extract inline JS --- static/js/pages/frontpage_refresh.js | 11 +++++ static/js/pages/fullscreen_front_init.js | 18 ++++++++ static/js/pages/fullscreen_init.js | 55 +++++++++++++++++++++++++ static/js/pages/log_init.js | 58 ++++++++++++++++++++++++++ template/frontpage.st | 50 +++++++---------------- template/fullscreen.st | 70 ++++++++------------------------ template/fullscreen_front.st | 9 +--- template/newlog.st | 4 +- template/simplerlog.st | 22 +++------- 9 files changed, 181 insertions(+), 116 deletions(-) create mode 100644 static/js/pages/frontpage_refresh.js create mode 100644 static/js/pages/fullscreen_front_init.js create mode 100644 static/js/pages/fullscreen_init.js create mode 100644 static/js/pages/log_init.js diff --git a/static/js/pages/frontpage_refresh.js b/static/js/pages/frontpage_refresh.js new file mode 100644 index 0000000..aa31cc2 --- /dev/null +++ b/static/js/pages/frontpage_refresh.js @@ -0,0 +1,11 @@ +// Frontpage-only helper. +// The legacy frontpage HTML calls `refreshing()` via . + +if (typeof window.refreshing !== 'function') { + window.refreshing = function refreshing() { + var el = document.getElementsByName('posts')[0]; + if (el) { el.src = el.src; } + setTimeout(refreshing, 300000); + }; +} + diff --git a/static/js/pages/fullscreen_front_init.js b/static/js/pages/fullscreen_front_init.js new file mode 100644 index 0000000..a1a87a5 --- /dev/null +++ b/static/js/pages/fullscreen_front_init.js @@ -0,0 +1,18 @@ +// Shared initializer for fullscreen feed pages. +// Keeps template inline JS mostly data-only (LoggedIn, Timestamp). + +(function($){ + function defaultPop(url) { + var newwindow = window.open( + url, + 'name', + 'height=50,width=400,left=20,top=20,location=0,status=0,scrollbar=0,resizable=0' + ); + if (window.focus && newwindow) { newwindow.focus(); } + return newwindow; + } + + if (typeof window.pop !== 'function') { window.pop = defaultPop; } + + if (typeof window.startChatUpdater === 'function') { $(window.startChatUpdater); } +})(jQuery); diff --git a/static/js/pages/fullscreen_init.js b/static/js/pages/fullscreen_init.js new file mode 100644 index 0000000..a7f8bb7 --- /dev/null +++ b/static/js/pages/fullscreen_init.js @@ -0,0 +1,55 @@ +// Initializer for `/fullscreen` (login/register overlays + fullscreen feed). +// Goal: reduce template inline JS without changing behavior. + +(function($){ + function choice(a) { return a[Math.floor(Math.random() * a.length)]; } + + function defaultPop(url) { + var newwindow = window.open( + url, + 'name', + 'height=50,width=400,left=20,top=20,location=0,status=0,scrollbar=0,resizable=0' + ); + if (window.focus && newwindow) { newwindow.focus(); } + return newwindow; + } + + if (typeof window.pop !== 'function') { window.pop = defaultPop; } + + var urls = [ + 'https://archive.hump.fm/images/20100601/1275428508049-dumpfm-foot-oie_oie_overlay-1.gif', + 'https://archive.hump.fm/images/20100928/1285728674225-dumpfm-timb-running.unicorn.gif', + 'https://archive.hump.fm/images/20100726/1280119193796-dumpfm-enso-human-condition.gif', + 'https://archive.hump.fm/images/20100521/1274415795577-dumpfm-ucnv-mx.gif', + 'https://archive.hump.fm/images/20100912/1284315873224-dumpfm-Neontoast-1283990707508-dumpfm-crunkus-crabtoon.gif', + 'https://archive.hump.fm/images/20110927/1317105622918-dumpfm-peachfist-test8scam.gif', + 'https://archive.hump.fm/images/20110323/1300915179773-dumpfm-blingscience-fishtank.gif', + 'https://archive.hump.fm/images/20110418/1303108538834-dumpfm-LAVARLAMAR-lettuce_lavarlamar.gif', + 'https://s3.amazonaws.com/i.asdf.us/im/84/gradient_horse_1318306378_1322355741_ryz_1337322355_ryz.gif', + 'https://archive.hump.fm/images/20110724/1311552093462-dumpfm-hologrampa-1291586335941-dumpfm-jeeeelings-cat_face_wink_hologrampa-lettuce.gif', + 'https://s3.amazonaws.com/i.asdf.us/im/be/tt7620731fltt_1315431978.gif' + ]; + + // Legacy behavior: register these on DOM-ready (historically done via `jQuery(initLogin)`). + if (typeof window.initLogin === 'function') { $(window.initLogin); } + if (typeof window.startChatUpdater === 'function') { $(window.startChatUpdater); } + + if (window.location && window.location.href.indexOf('nologin') !== -1) { + $('#loginbox').hide(); + } + + var bigImage = document.getElementById('big-image'); + if (bigImage) { bigImage.innerHTML = ""; } + + if (typeof window.initFullscreen === 'function') { window.initFullscreen(); } + if (typeof window.initRegister === 'function') { window.initRegister(); } + + $('#reglink').click(function(e){ + e.preventDefault(); + $('#loginbox').hide(); + $('#registerbox').show().addClass('b'); + return false; + }); + + $('#nickInput').focus(); +})(jQuery); 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) {} + }; +} + diff --git a/template/frontpage.st b/template/frontpage.st index efb433c..88c0e25 100755 --- a/template/frontpage.st +++ b/template/frontpage.st @@ -1,13 +1,5 @@ - dump.fm @@ -27,34 +19,22 @@ setTimeout("refreshing()",300000); - $if(!logged_in)$ - - $endif$ - - - - - - - + $endif$ + + + + + + - }); - - - - - + + @@ -199,6 +179,6 @@ $debug_log()$ Loading... - + diff --git a/template/fullscreen.st b/template/fullscreen.st index 5879804..54960fc 100755 --- a/template/fullscreen.st +++ b/template/fullscreen.st @@ -5,23 +5,17 @@ $if(user_nick)$ - $else$ - - $endif$ - - - - - - + $else$ + + $endif$ + + + + + $if(user_nick)$ @@ -75,40 +69,8 @@ $endif$ -
- - $google_analytics()$ - - +
+ + $google_analytics()$ + + diff --git a/template/fullscreen_front.st b/template/fullscreen_front.st index b0bfb4d..9f0e869 100755 --- a/template/fullscreen_front.st +++ b/template/fullscreen_front.st @@ -7,14 +7,9 @@ - + + diff --git a/template/newlog.st b/template/newlog.st index 19b4481..e1f987a 100755 --- a/template/newlog.st +++ b/template/newlog.st @@ -43,10 +43,8 @@ window.location = "/error/ie"; + diff --git a/template/simplerlog.st b/template/simplerlog.st index 7e68473..9acc742 100755 --- a/template/simplerlog.st +++ b/template/simplerlog.st @@ -41,24 +41,12 @@ $endif$ + - - - - + + @@ -216,6 +204,6 @@ $debug_log()$ Loading... - + -- cgit v1.2.3-70-g09d2