refactor(webserver): extract Dreamweaver MM_* JS into shared common.js - #90
Merged
Merged
Conversation
Every main page of the default template embedded its own copy of the Dreamweaver-generated image-rollover helpers (MM_swapImgRestore, MM_preloadImages, MM_findObj, MM_swapImage), with drift between pages: dload and shared additionally carried MM_nbGroup for their toolbars. That was ~276 lines of copy-pasted script across 8 pages. Move the five functions into a new common.js, served statically with the correct text/javascript MIME type by the webserver, and replace each inline block with a single <script src="common.js"> reference. The PHP `include` directive cannot be used for this because the embedded interpreter resolves it against the process working directory, so deduplication has to go through static assets. While extracting, retire the deprecated constructs that lived inside those blocks: the language="JavaScript" attribute, the <!-- --> script-hiding comments, and the Netscape-4-era document.all / document.layers fallbacks in MM_findObj (document.getElementById covers all supported browsers). common.js is added to the CMake INSTALL list so it ships with the template. Verified against a running amuleweb: all 8 pages return the common.js reference with no inline MM_ leftovers, the file is served as text/javascript, and a headless-browser check confirms the navigation rollovers (MM_swapImage/MM_swapImgRestore), the toolbar group buttons (MM_nbGroup) and image preloading still work with no console errors.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Every main page of the default template embedded its own copy of the Dreamweaver-generated image-rollover helpers (MM_swapImgRestore, MM_preloadImages, MM_findObj, MM_swapImage), with drift between pages: dload and shared additionally carried MM_nbGroup for their toolbars. That was ~276 lines of copy-pasted script across 8 pages.
Move the five functions into a new common.js, served statically with the correct text/javascript MIME type by the webserver, and replace each inline block with a single <script src="common.js"> reference. The PHP
includedirective cannot be used for this because the embedded interpreter resolves it against the process working directory, so deduplication has to go through static assets.While extracting, retire the deprecated constructs that lived inside
those blocks: the language="JavaScript" attribute, the
script-hiding comments, and the Netscape-4-era document.all / document.layers fallbacks in MM_findObj (document.getElementById covers all supported browsers).
common.js is added to the CMake INSTALL list so it ships with the template.
Verified against a running amuleweb: all 8 pages return the common.js reference with no inline MM_ leftovers, the file is served as text/javascript, and a headless-browser check confirms the navigation rollovers (MM_swapImage/MM_swapImgRestore), the toolbar group buttons (MM_nbGroup) and image preloading still work with no console errors.