Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anchor icon is always visible on Windows when visible=touch after promoted to v4.3.0 #168

Closed
v-pegao opened this issue Jan 8, 2021 · 3 comments

Comments

@v-pegao
Copy link

v-pegao commented Jan 8, 2021

Issue description

We identified a behavior change after promoted Anchorjs from v4.2.2 to v4.3.0.

We are using visible: touch as anchor options. For v4.2.2, the anchor image is hover on page of Windows10, after promoted to v4.3.0, the anchor image is always there instead of hover.

Here are sample pages to help understand the issue:
v4.2.2 page(hover): https://kleisauke.github.io/net-vips-tests/api/NetVips.html
v4.3.0 page(always): https://kleisauke.github.io/net-vips/api/NetVips.html

Operating System: Windows

AnchorJs version: 4.3.0

Expected Behavior:
AnchorJS links only become visible when hovering over the headings like before for Windows when visible is touch.

Actual Behavior:
AnchorJS links are always visible for Windows when visible is touch.

Note:
This behavior change seems related to the newly added condition window.TouchEvent in function isTouchDevice() with this commit

isTouchDevice() for v4.3.0:
this.isTouchDevice=function(){return Boolean("ontouchstart"in window||window.TouchEvent||window.DocumentTouch&&document instanceof DocumentTouch)}

isTouchDevice() for v4.2.2:
,this.isTouchDevice=function(){return!!("ontouchstart"in window||window.DocumentTouch&&document instanceof DocumentTouch)}

@bryanbraun
Copy link
Owner

Thanks for the detailed report. You're totally right about where that new behavior is coming from.

Unfortunately, the behavior you're seeing is intended. To quote the docs:

touch will always display anchors for devices that support touch events, and only display them via hover for devices that do not support touch events. This approximates touchscreen detection (but isn't 100% accurate).

If you're seeing the links in your browser on Windows 10, that means your browser supports touch events (more specifically, window.TouchEvent). That might mean your desktop/laptop has support for touch interface (many windows computers, like surface books, do), or that the browser would support a touch interface if it were installed on such a device.

The change that you saw in the newer AnchorJS version comes from a similar Modernizr update, which was intended to make touch event detection more accurate. You can see details on that here: Modernizr/Modernizr#2409

Ultimately, I'm comfortable leaving this feature as-is, focused on detecting touch-events, which only approximates touchscreen detection. The alternative is to remove the feature altogether (which is what Modernizr eventually did).

If you prefer the former behavior, I'd say feel free to continue using v4.2.2.

@v-pegao
Copy link
Author

v-pegao commented Jan 14, 2021

Thanks for the reply, closing the issue now

@v-pegao v-pegao closed this as completed Jan 14, 2021
tnir added a commit to rubygems/bundler-site that referenced this issue Jul 30, 2022
This option does not work in many browsers as expected in PR 218

https://caniuse.com/touch

bryanbraun/anchorjs#168

Signed-off-by: Takuya Noguchi <[email protected]>
@KasparEtter
Copy link

Boolean('ontouchstart' in window || window.TouchEvent || window.DocumentTouch && document instanceof DocumentTouch) returns true in the current Chrome (Version 105.0.5195.125) on my old MacBook Pro, which doesn't have a touch screen. The new behavior is unacceptable to me, so I will have to stay on v4.2.2. 😕

purecodecoach added a commit to purecodecoach/bundler-site that referenced this issue Jan 13, 2023
This option does not work in many browsers as expected in PR 218

https://caniuse.com/touch

bryanbraun/anchorjs#168

Signed-off-by: Takuya Noguchi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants