-
Notifications
You must be signed in to change notification settings - Fork 564
/
Copy pathinlineJSNonBlocking.scala.html
75 lines (66 loc) · 2.6 KB
/
inlineJSNonBlocking.scala.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
@import common.InlineJs
@import conf.switches.Switches.IdentityProfileNavigationSwitch
@import conf.Configuration
@import model.Page
@import templates.inlineJS.nonBlocking.js._
@import play.twirl.api.HtmlFormat
@import model.DotcomContentType
@()(implicit page: Page, request: RequestHeader, context: model.ApplicationContext)
@**
* Use this fragment to add JavaScript that can improve the perceived rendering speed
* but that is too blocking / risky to be put in the `head` of the document
*@
<script>
// non-blocking JS to improve the perceived rendering speed
@InlineJs(getUserData().body, "getUserData.js")
@if(IdentityProfileNavigationSwitch.isSwitchedOn) {
// Insert username in top bar on page load
@InlineJs(showUserName().body, "showUserName.js")
}
// ************* ANALYTICS *************
// Ophan pageview ID and browser ID
@InlineJs(ophanConfig().body, "ophanConfig.js")
@if(page.metadata.contentType.exists { c =>
c == DotcomContentType.Article ||
c == DotcomContentType.LiveBlog ||
c == DotcomContentType.Interactive
}
) {
// provide CURL for interactives ASAP, and in perpetuity.
// this config may or may not be needed. but it has been present
// on the page for years, and if an interactive was released that assumed it,
// it will break. so we're providing just incase that is true.
window.curlConfig = {
baseUrl: '@{Configuration.assets.path}javascripts',
apiName: 'require',
paths: {
'ophan/ng': '@{Configuration.javascript.config("ophanJsUrl")}'
}
};
window.curl = window.curlConfig;
@HtmlFormat.raw(common.Assets.js.curl)
[].slice.apply(document.querySelectorAll('figure.interactive[data-interactive]')).forEach(function (el) {
require([el.getAttribute('data-interactive')], function (interactive) {
interactive.boot(el, document, window.guardian.config);
}, function (err) {
console.log('Interactive failed', mainJS);
console.log('Error:', err);
});
require(['ophan/ng'], function(ophan) {
var a = el.querySelector('a');
var href = a && a.href;
if (href) {
ophan.trackComponentAttention(href, el);
}
});
[].slice.apply(document.querySelectorAll('iframe.interactive-atom-fence')).forEach(function (el) {
var srcdoc;
if (!el.srcdoc) {
srcdoc = el.getAttribute('srcdoc');
el.contentWindow.contents = srcdoc;
el.src = 'javascript:window["contents"]';
}
});
});
}
</script>