File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,6 +6,12 @@ set -euo pipefail
66PATH=" /tmp/claat:${PATH} " python3 ./build.py
77
88sed -e ' s#https://storage.googleapis.com/claat-public#/static#g' -i build/* /index.html
9+ # Stop focus() inside an embedding iframe from scrolling the parent page (see static/iframe-focus-fix.js)
10+ sed -e ' s#<script src="/static/codelab-elements.js"></script>#<script src="/static/iframe-focus-fix.js"></script>&#' -i build/* /index.html
11+ if grep -L ' iframe-focus-fix.js' build/* /index.html | grep -q . ; then
12+ echo " iframe-focus-fix.js was not injected into every page - has claat's script tag changed?" >&2
13+ exit 1
14+ fi
915
1016# The public static hosting seems offline (e.g. https://storage.googleapis.com/claat-public/codelab-elements.css) so we vendor these assets:
1117# Built by running `USE_BAZEL_VERSION=0.19.1 bazel build :bundle` with patches to:
Original file line number Diff line number Diff line change 1+ // When a codelab is embedded in an iframe (e.g. on the CYF curriculum site),
2+ // codelab-elements.js focuses the current step on load. Focusing an element
3+ // inside an iframe scrolls the parent page to the iframe, losing the reader's
4+ // place. Force preventScroll on every focus() call, only when embedded.
5+ // Must load before codelab-elements.js.
6+ ( function ( ) {
7+ if ( window . self === window . top ) return ;
8+ var originalFocus = HTMLElement . prototype . focus ;
9+ HTMLElement . prototype . focus = function ( options ) {
10+ var opts = Object . assign ( { } , options , { preventScroll : true } ) ;
11+ return originalFocus . call ( this , opts ) ;
12+ } ;
13+ } ) ( ) ;
You can’t perform that action at this time.
0 commit comments