Repository navigation
Switch on the normalized displayOption value - #138
Open
Denimworld12 wants to merge 1 commit into
Open
Denimworld12 wants to merge 1 commit into
Denimworld12 wants to merge 1 commit into
Conversation
init() normalizes config.displayOption with .trim().toLowerCase() into a
local, but the switch that follows tested this.config.displayOption -- the
original string -- so the normalization never reached the comparison.
Values such as 'Popup', ' popup' and 'FIXED' fell through to default with
no class added.
The class is the feature: .skip-to.popup sets top:-30em so the button is
hidden until focus, and .skip-to.fixed pins it to the viewport. Without it
the button falls back to .skip-to { position:absolute; top:0 } and stays
visible on every page, with no error reported.
The if (displayOption.length) guard on the preceding line already read the
normalized copy, so the two lines disagreed about which value they judged.
This branch has not been deployed
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.
SkipTo.init()normalizesconfig.displayOptionwith.trim().toLowerCase()into a local, but theswitchthat follows testedthis.config.displayOption— the original string — so the normalization never reached the comparison and values such as'Popup',' popup'and'FIXED'fell through todefaultwith no class added.skipto/src/js/skipto.js
Lines 185 to 201 in 93599ba
(Filing this as a PR rather than an issue first, since issues are turned off on this repo.)
Why it matters
The class is the whole feature. From
src/css/SkipTo.css:With no class added the button falls back to
.skip-to { position: absolute; top: 0 }and stays visible. So a site configured withdisplayOption: 'Popup'gets a Skip To Content button pinned to the top of every page instead of one that appears on focus — the opposite of what it asked for, with no error and nothing in the console.SkipTo reads its configuration from
window.SkipToConfigorwindow.Joomla.getOptions('skipto-settings', {}), so the value can arrive from a hand-written object or from a settings form; both are easy places for a capital letter or a stray space to survive.Note that the
if (displayOption.length)guard on the preceding line does read the normalized copy, so' popup'passes that guard and then fails the switch — the two lines disagreed about which value they were judging.Testing
Chrome 144, the
example/pages loadingdownloads/js/skipto.jsbuilt from this branch, plus three copies of those pages with only the configured value changed. "Before" is the committed build at93599ba.displayOptionskipTo-onfocus.html'popup'skip-to popup,top: -480px'Popup'skip-to,top: 0pxskip-to popup,top: -480px' popup'skip-to,top: 0pxskip-to popup,top: -480pxskipTo-fixed.html'fixed'skip-to fixed,position: fixed'FIXED'skip-to,position: absoluteskip-to fixed,position: fixednpx grunt testpasses (2 files lint free). The repository has no unit test harness, so the verification above is a browser measurement of the rendered class and computed style, not an automated test.For what it is worth, this matches what the v5 rewrite already does:
setDisplayOption()inskipto-landmarks-headings/page-script-5normalizes intovalueand switches onvalue. The same line is still present on thedev/v5.0branch here, atsrc/js/skipto.js:329, if you want it carried over.A note on
downloads/I have not regenerated the build artifacts, because
npx gruntafter a freshnpm installno longer reproduces the committed bundle.grunt-contrib-uglify@4.0.1resolvesuglify-js@3.x(theuglify-js: ~2.8.0devDependency is not the copy grunt loads), and its output differs fromdownloads/js/skipto.min.jsin roughly a hundred places unrelated to this change — it emits(()=>{where the committed file has!function(){"use strict";, drops the"use strict"directive, and renames locals despitemangle: false.downloads/js/skipto.json its own is byte-reproducible (concat only, no uglify), but shipping it without the matching minified files would leave the set inconsistent, so I left all four alone.Happy to add whatever output you want here — say the word and I will include it.