Skip to content

Commit afea41a

Browse files
committed
fix logic of treatment bucket vs. cookie preference
1 parent 0d08b8c commit afea41a

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

javascripts/toggle-images.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// import { sendEvent } from './events'
21
import Cookies from 'js-cookie'
32

43
// Set the image placeholder icon here.
@@ -22,7 +21,9 @@ export default function (hideImagesByDefault = false, focusButtonByDefault = fal
2221
toggleImagesBtn.removeAttribute('hidden')
2322

2423
// Look for a cookie with image visibility preference; otherwise, use the default.
25-
const hideImagesPreferred = hideImagesByDefault || (Cookies.get('hideImagesPreferred') === 'true')
24+
const hideImagesPreferred = Cookies.get('hideImagesPreferred') === 'false'
25+
? false
26+
: Cookies.get('hideImagesPreferred') === 'true' || hideImagesByDefault
2627

2728
// Hide the images if that is the preference.
2829
if (hideImagesPreferred) {
@@ -42,6 +43,7 @@ export default function (hideImagesByDefault = false, focusButtonByDefault = fal
4243
onIcon.setAttribute('hidden', true)
4344
offIcon.removeAttribute('hidden')
4445
toggleImagesBtn.setAttribute('aria-label', tooltipImagesOff)
46+
4547
// Show the tooltip if images are hidden by default to help users see the toggle button.
4648
// Downside: the button will begin with focus whenever the user goes to a new page.
4749
if (focusButtonByDefault) {
@@ -73,16 +75,14 @@ export default function (hideImagesByDefault = false, focusButtonByDefault = fal
7375
}
7476

7577
// Remove focus from the button after click so the tooltip does not stay displayed.
76-
toggleImagesBtn.blur()
78+
// Use settimeout to work around Firefox-specific issue.
79+
setTimeout(() => { toggleImagesBtn.blur() }, 100)
7780

7881
// Save this preference as a cookie.
79-
Cookies.set('hideImagesPreferred', showOnNextClick)
82+
Cookies.set('hideImagesPreferred', showOnNextClick, { sameSite: 'strict', secure: true })
8083

8184
// Toggle the action on every click.
8285
showOnNextClick = !showOnNextClick
83-
84-
// TODO Track image toggle events
85-
// sendEvent({ type: 'imageToggle' })
8686
})
8787
}
8888

0 commit comments

Comments
 (0)