@@ -17,6 +17,13 @@ import {
17
17
} from 'docc-render/utils/object-properties' ;
18
18
import { resolveAbsoluteUrl } from 'docc-render/utils/url-helper' ;
19
19
20
+ /** Enum for the allowed values of the `run` property in a custom script. */
21
+ const Run = {
22
+ onLoad : 'on-load' ,
23
+ onLoadAndNavigate : 'on-load-and-navigate' ,
24
+ onNavigate : 'on-navigate' ,
25
+ } ;
26
+
20
27
/**
21
28
* Returns whether the custom script should be run when the reader navigates to a subpage.
22
29
* @param {object } customScript
@@ -25,7 +32,7 @@ import { resolveAbsoluteUrl } from 'docc-render/utils/url-helper';
25
32
*/
26
33
function shouldRunOnPageLoad ( customScript ) {
27
34
return ! has ( customScript , 'run' )
28
- || customScript . run === 'on-load' || customScript . run === 'on-load-and-navigate' ;
35
+ || customScript . run === Run . onLoad || customScript . run === Run . onLoadAndNavigate ;
29
36
}
30
37
31
38
/**
@@ -36,7 +43,7 @@ function shouldRunOnPageLoad(customScript) {
36
43
*/
37
44
function shouldRunOnNavigate ( customScript ) {
38
45
return has ( customScript , 'run' )
39
- && ( customScript . run === 'on-navigate' || customScript . run === 'on-load-and-navigate' ) ;
46
+ && ( customScript . run === Run . onNavigate || customScript . run === Run . onLoadAndNavigate ) ;
40
47
}
41
48
42
49
/**
@@ -78,7 +85,7 @@ function addScriptElement(customScript) {
78
85
79
86
scriptElement . src = customScript . url ;
80
87
81
- // Dynamically-created script elements are `async` by default. But we don't want custom
88
+ // Dynamically-created script elements are `async` by default. But we don't want custom
82
89
// scripts to be implicitly async by default, because if a documentation author adds `defer` to
83
90
// some or all of their custom scripts (meaning that they want the execution order of those
84
91
// scripts to be deterministic), then the author's `defer` will be overriden by the implicit
0 commit comments