From 55744998af96b12eef4278328f442d56b0679f13 Mon Sep 17 00:00:00 2001 From: Thomas Walker Lynch Date: Fri, 15 May 2026 07:19:24 +0000 Subject: [PATCH] page refresh with hash url --- consumer/release/RT/core/utility.js | 2 + .../release/RT/layout/article_tech_ref.js | 37 +++++++++--------- developer/authored/RT/core/utility.js | 2 +- .../authored/RT/layout/article_tech_ref.js | 38 +++++++++---------- 4 files changed, 40 insertions(+), 39 deletions(-) diff --git a/consumer/release/RT/core/utility.js b/consumer/release/RT/core/utility.js index 3044654..b8522c9 100644 --- a/consumer/release/RT/core/utility.js +++ b/consumer/release/RT/core/utility.js @@ -13,6 +13,7 @@ window.StyleRT.debug = { 'style', 'layout', 'pagination' ,'selector', 'config', 'error' ,'term' + ,'scroll' ]), active_tokens: new Set([ @@ -21,6 +22,7 @@ window.StyleRT.debug = { */ active_tokens: new Set([ + 'scroll' ]), diff --git a/consumer/release/RT/layout/article_tech_ref.js b/consumer/release/RT/layout/article_tech_ref.js index 275d597..9e571f3 100644 --- a/consumer/release/RT/layout/article_tech_ref.js +++ b/consumer/release/RT/layout/article_tech_ref.js @@ -1,10 +1,13 @@ (function(){ - console.log("[RT-Scroll] 1. Initializing script."); + const RT = window.StyleRT = window.StyleRT || {}; + const debug = RT.debug || { log: function(){} }; + + debug.log('scroll', "1. Initializing script."); // 1. Intercept native history restoration immediately if ('scrollRestoration' in history) { history.scrollRestoration = 'manual'; - console.log("[RT-Scroll] 2. history.scrollRestoration set to manual."); + debug.log('scroll', "2. history.scrollRestoration set to manual."); } // 2. Read coordinate from memory before any layout shifts occur @@ -22,13 +25,11 @@ } } - console.log(`[RT-Scroll] 3. Target Y: ${target_y} | Is Reload: ${is_reload}`); + debug.log('scroll', `3. Target Y: ${target_y} | Is Reload: ${is_reload}`); // 4. The Lock let is_layout_locked = true; - const RT = window.StyleRT = window.StyleRT || {}; - // 5. Declare Dependencies RT.include('RT/core/utility'); RT.include('RT/element/math'); @@ -166,7 +167,7 @@ // 7. The Execution Sequence function run_semantics() { - console.log(`[RT-Scroll] 4. run_semantics starting.`); + debug.log('scroll', `4. run_semantics starting.`); if(RT.theme) RT.theme(); RT.article(); if(RT.title) RT.title(); @@ -182,18 +183,17 @@ } function run_layout() { - console.log(`[RT-Scroll] 5. run_layout starting.`); + debug.log('scroll', `5. run_layout starting.`); if(RT.TOC) RT.TOC(); if(RT.paginate_by_element) RT.paginate_by_element(); if(RT.page) RT.page(); if(RT.body_visibility_visible) RT.body_visibility_visible(); - console.log(`[RT-Scroll] 6. Pagination complete.`); + debug.log('scroll', `6. Pagination complete.`); let final_target = target_y; let use_hash = false; - // Prioritize the hash only if it is NOT a page reload if (window.location.hash && !is_reload) { const hash_target = document.getElementById(window.location.hash.substring(1)); if (hash_target) { @@ -201,14 +201,14 @@ } } - console.log(`[RT-Scroll] 7. Commencing viewport enforce loop. Mode: ${use_hash ? 'HASH' : 'Y-COORDINATE'}`); + debug.log('scroll', `7. Commencing viewport enforce loop. Mode: ${use_hash ? 'HASH' : 'Y-COORDINATE'}`); enforce_scroll(final_target, use_hash, 0); } // 8. The Enforcer Logic function enforce_scroll(target, use_hash, attempts) { if (attempts > 15) { - console.log("[RT-Scroll] 8. Scroll enforcement timed out. Unlocking."); + debug.log('scroll', "8. Scroll enforcement timed out. Unlocking."); is_layout_locked = false; return; } @@ -217,11 +217,11 @@ const hash_target = document.getElementById(window.location.hash.substring(1)); if (hash_target) { hash_target.scrollIntoView(); - console.log(`[RT-Scroll] 8a. Attempt ${attempts}: Scrolled to Hash Target. Y is now ${window.scrollY}`); + debug.log('scroll', `8a. Attempt ${attempts}: Scrolled to Hash Target. Y is now ${window.scrollY}`); } } else { window.scrollTo(0, target); - console.log(`[RT-Scroll] 8b. Attempt ${attempts}: Scrolled to Y=${target}. Current Y is ${window.scrollY}`); + debug.log('scroll', `8b. Attempt ${attempts}: Scrolled to Y=${target}. Current Y is ${window.scrollY}`); } let is_successful = false; @@ -232,16 +232,15 @@ } if (is_successful && document.body.scrollHeight > 1000) { - console.log(`[RT-Scroll] 9. Viewport anchored successfully.`); + debug.log('scroll', `9. Viewport anchored successfully.`); - // Hold the line against native browser hash jumping setTimeout(() => { if (!use_hash && Math.abs(window.scrollY - target) >= 5) { - console.log(`[RT-Scroll] 9a. Browser late-stage rebellion detected. Re-enforcing.`); + debug.log('scroll', `9a. Browser late-stage rebellion detected. Re-enforcing.`); enforce_scroll(target, use_hash, attempts + 1); } else { is_layout_locked = false; - console.log("[RT-Scroll] 10. Layout fully unlocked."); + debug.log('scroll', "10. Layout fully unlocked."); } }, 100); } else { @@ -256,13 +255,13 @@ clearTimeout(scroll_timer); scroll_timer = setTimeout(() => { sessionStorage.setItem('RT_saved_y', window.scrollY); - console.log(`[RT-Scroll] X. User stopped scrolling. Saved Y: ${window.scrollY}`); + debug.log('scroll', `X. User stopped scrolling. Saved Y: ${window.scrollY}`); }, 200); }, { passive: true }); window.addEventListener('beforeunload', () => { is_layout_locked = true; - console.log("[RT-Scroll] Y. Page unloading. Scroll listener locked."); + debug.log('scroll', "Y. Page unloading. Scroll listener locked."); }); // 10. Bind to DOM Ready diff --git a/developer/authored/RT/core/utility.js b/developer/authored/RT/core/utility.js index 3044654..b070510 100644 --- a/developer/authored/RT/core/utility.js +++ b/developer/authored/RT/core/utility.js @@ -13,6 +13,7 @@ window.StyleRT.debug = { 'style', 'layout', 'pagination' ,'selector', 'config', 'error' ,'term' + ,'scroll' ]), active_tokens: new Set([ @@ -23,7 +24,6 @@ window.StyleRT.debug = { active_tokens: new Set([ ]), - log: function(token, message) { if (this.active_tokens.has(token)) { console.log(`[StyleRT:${token}]`, message); diff --git a/developer/authored/RT/layout/article_tech_ref.js b/developer/authored/RT/layout/article_tech_ref.js index 275d597..47e6a78 100644 --- a/developer/authored/RT/layout/article_tech_ref.js +++ b/developer/authored/RT/layout/article_tech_ref.js @@ -1,10 +1,14 @@ +// debug messsages don't work here, because RT/core/utility isn't loaded until after the function runs. (function(){ - console.log("[RT-Scroll] 1. Initializing script."); + const RT = window.StyleRT = window.StyleRT || {}; + const debug = RT.debug || { log: function(){} }; + + debug.log('scroll', "1. Initializing script."); // 1. Intercept native history restoration immediately if ('scrollRestoration' in history) { history.scrollRestoration = 'manual'; - console.log("[RT-Scroll] 2. history.scrollRestoration set to manual."); + debug.log('scroll', "2. history.scrollRestoration set to manual."); } // 2. Read coordinate from memory before any layout shifts occur @@ -22,13 +26,11 @@ } } - console.log(`[RT-Scroll] 3. Target Y: ${target_y} | Is Reload: ${is_reload}`); + debug.log('scroll', `3. Target Y: ${target_y} | Is Reload: ${is_reload}`); // 4. The Lock let is_layout_locked = true; - const RT = window.StyleRT = window.StyleRT || {}; - // 5. Declare Dependencies RT.include('RT/core/utility'); RT.include('RT/element/math'); @@ -166,7 +168,7 @@ // 7. The Execution Sequence function run_semantics() { - console.log(`[RT-Scroll] 4. run_semantics starting.`); + debug.log('scroll', `4. run_semantics starting.`); if(RT.theme) RT.theme(); RT.article(); if(RT.title) RT.title(); @@ -182,18 +184,17 @@ } function run_layout() { - console.log(`[RT-Scroll] 5. run_layout starting.`); + debug.log('scroll', `5. run_layout starting.`); if(RT.TOC) RT.TOC(); if(RT.paginate_by_element) RT.paginate_by_element(); if(RT.page) RT.page(); if(RT.body_visibility_visible) RT.body_visibility_visible(); - console.log(`[RT-Scroll] 6. Pagination complete.`); + debug.log('scroll', `6. Pagination complete.`); let final_target = target_y; let use_hash = false; - // Prioritize the hash only if it is NOT a page reload if (window.location.hash && !is_reload) { const hash_target = document.getElementById(window.location.hash.substring(1)); if (hash_target) { @@ -201,14 +202,14 @@ } } - console.log(`[RT-Scroll] 7. Commencing viewport enforce loop. Mode: ${use_hash ? 'HASH' : 'Y-COORDINATE'}`); + debug.log('scroll', `7. Commencing viewport enforce loop. Mode: ${use_hash ? 'HASH' : 'Y-COORDINATE'}`); enforce_scroll(final_target, use_hash, 0); } // 8. The Enforcer Logic function enforce_scroll(target, use_hash, attempts) { if (attempts > 15) { - console.log("[RT-Scroll] 8. Scroll enforcement timed out. Unlocking."); + debug.log('scroll', "8. Scroll enforcement timed out. Unlocking."); is_layout_locked = false; return; } @@ -217,11 +218,11 @@ const hash_target = document.getElementById(window.location.hash.substring(1)); if (hash_target) { hash_target.scrollIntoView(); - console.log(`[RT-Scroll] 8a. Attempt ${attempts}: Scrolled to Hash Target. Y is now ${window.scrollY}`); + debug.log('scroll', `8a. Attempt ${attempts}: Scrolled to Hash Target. Y is now ${window.scrollY}`); } } else { window.scrollTo(0, target); - console.log(`[RT-Scroll] 8b. Attempt ${attempts}: Scrolled to Y=${target}. Current Y is ${window.scrollY}`); + debug.log('scroll', `8b. Attempt ${attempts}: Scrolled to Y=${target}. Current Y is ${window.scrollY}`); } let is_successful = false; @@ -232,16 +233,15 @@ } if (is_successful && document.body.scrollHeight > 1000) { - console.log(`[RT-Scroll] 9. Viewport anchored successfully.`); + debug.log('scroll', `9. Viewport anchored successfully.`); - // Hold the line against native browser hash jumping setTimeout(() => { if (!use_hash && Math.abs(window.scrollY - target) >= 5) { - console.log(`[RT-Scroll] 9a. Browser late-stage rebellion detected. Re-enforcing.`); + debug.log('scroll', `9a. Browser late-stage rebellion detected. Re-enforcing.`); enforce_scroll(target, use_hash, attempts + 1); } else { is_layout_locked = false; - console.log("[RT-Scroll] 10. Layout fully unlocked."); + debug.log('scroll', "10. Layout fully unlocked."); } }, 100); } else { @@ -256,13 +256,13 @@ clearTimeout(scroll_timer); scroll_timer = setTimeout(() => { sessionStorage.setItem('RT_saved_y', window.scrollY); - console.log(`[RT-Scroll] X. User stopped scrolling. Saved Y: ${window.scrollY}`); + debug.log('scroll', `X. User stopped scrolling. Saved Y: ${window.scrollY}`); }, 200); }, { passive: true }); window.addEventListener('beforeunload', () => { is_layout_locked = true; - console.log("[RT-Scroll] Y. Page unloading. Scroll listener locked."); + debug.log('scroll', "Y. Page unloading. Scroll listener locked."); }); // 10. Bind to DOM Ready -- 2.20.1