|
11 | 11 | return; |
12 | 12 | } |
13 | 13 |
|
| 14 | + // For styling necessary only when embedded in an iframe. |
| 15 | + function addEmbededClass() { |
| 16 | + document.body.classList.add("embedded"); |
| 17 | + } |
| 18 | + |
14 | 19 | // Change document base to that of Developer.anki.com so that navigation happens at the top level. |
15 | 20 | function updateDocumentBase() { |
16 | 21 | var base = document.createElement('base'); |
|
21 | 26 | head.insertBefore(base, firstChild); |
22 | 27 | } |
23 | 28 |
|
24 | | - if (document.readyState === 'loading') { |
| 29 | + // Signal to Developer.anki.com that we're done loading and ready to receive messages. |
| 30 | + // We send page title to Developer.anki.com so that the browser displays it. |
| 31 | + function notifyParentWindowOnLoad() { |
| 32 | + parent.postMessage({ |
| 33 | + event: 'load', |
| 34 | + docTitle: document.title |
| 35 | + }, '*'); |
| 36 | + } |
| 37 | + |
| 38 | + function initEmbeddedMode() { |
| 39 | + addEmbededClass(); |
| 40 | + updateDocumentBase(); |
| 41 | + notifyParentWindowOnLoad(); |
| 42 | + } |
| 43 | + |
| 44 | + if (document.readyState !== 'complete') { |
25 | 45 | window.addEventListener('load', function(){ |
26 | | - updateDocumentBase(); |
| 46 | + initEmbeddedMode(); |
27 | 47 | }); |
28 | 48 | } else { |
29 | | - updateDocumentBase(); |
| 49 | + initEmbeddedMode(); |
30 | 50 | } |
31 | 51 |
|
32 | 52 | // Handle messages from Developer.anki.com. |
33 | 53 | function receiveMessage(event) { |
34 | 54 | var eventName = event.data.event; |
35 | 55 | if(eventName === 'hashchange') { |
36 | 56 | window.location.hash = event.data.hash; |
| 57 | + // Workaround for IOS Safari lack of support for window.location.hash scrolling. |
| 58 | + var linkedElement = document.getElementById(event.data.hash.replace('#', '')) |
| 59 | + if (linkedElement && linkedElement.scrollIntoView) { |
| 60 | + linkedElement.scrollIntoView(); |
| 61 | + } |
37 | 62 | } |
38 | 63 | } |
39 | 64 | window.addEventListener("message", receiveMessage, false); |
40 | 65 |
|
41 | | - // Send page title to Developer.anki.com so that the browser displays it. |
42 | | - parent.postMessage({ |
43 | | - event: 'load', |
44 | | - docTitle: document.title |
45 | | - }, '*'); |
46 | 66 | })(window); |
47 | 67 |
|
48 | 68 | /** |
|
56 | 76 | // } |
57 | 77 |
|
58 | 78 | </script> |
| 79 | + <style> |
| 80 | + /* Allows scrolling to anchor links on IOS Safari */ |
| 81 | + .embedded .wy-grid-for-nav { |
| 82 | + position: fixed; |
| 83 | + top: 0; |
| 84 | + right: 0; |
| 85 | + bottom: 0; |
| 86 | + left: 0; |
| 87 | + overflow-y: scroll; |
| 88 | + -webkit-overflow-scrolling: touch; |
| 89 | + z-index: 1; |
| 90 | + } |
| 91 | + </style> |
59 | 92 | <!-- <script async src='https://www.google-analytics.com/analytics.js'></script> --> |
60 | 93 | {{ super() }} |
61 | 94 | {% endblock %} |
0 commit comments