(scripts, index)
| 73 | * @param {number} index current script to load |
| 74 | */ |
| 75 | const loadScriptsHelper = (scripts, index) => { |
| 76 | if (index >= scripts.length) |
| 77 | return; |
| 78 | |
| 79 | const currScriptInfo = _allScriptTags[index]; |
| 80 | |
| 81 | /** |
| 82 | * Skip script if it was already executed |
| 83 | */ |
| 84 | if (currScriptInfo._executed) |
| 85 | return loadScriptsHelper(scripts, index+1); |
| 86 | |
| 87 | const currScript = currScriptInfo._script; |
| 88 | const currScriptCategory = currScriptInfo._categoryName; |
| 89 | const currScriptService = currScriptInfo._serviceName; |
| 90 | const categoryAccepted = elContains(acceptedCategories, currScriptCategory); |
| 91 | const serviceAccepted = currScriptService |
| 92 | ? elContains(_acceptedServices[currScriptCategory], currScriptService) |
| 93 | : false; |
| 94 | |
| 95 | const categoryWasJustEnabled = () => !currScriptService |
| 96 | && !currScriptInfo._runOnDisable |
| 97 | && categoryAccepted; |
| 98 | |
| 99 | const serviceWasJustEnabled = () => currScriptService |
| 100 | && !currScriptInfo._runOnDisable |
| 101 | && serviceAccepted; |
| 102 | |
| 103 | const categoryWasJustDisabled = () => !currScriptService |
| 104 | && currScriptInfo._runOnDisable |
| 105 | && !categoryAccepted |
| 106 | && elContains(_lastChangedCategoryNames, currScriptCategory); |
| 107 | |
| 108 | const serviceWasJustDisabled = () => currScriptService |
| 109 | && currScriptInfo._runOnDisable |
| 110 | && !serviceAccepted |
| 111 | && elContains(_lastChangedServices[currScriptCategory] || [], currScriptService); |
| 112 | |
| 113 | const shouldRunScript = |
| 114 | categoryWasJustEnabled() |
| 115 | || categoryWasJustDisabled() |
| 116 | || serviceWasJustEnabled() |
| 117 | || serviceWasJustDisabled(); |
| 118 | |
| 119 | if (shouldRunScript) { |
| 120 | currScriptInfo._executed = true; |
| 121 | const dataType = getAttribute(currScript, 'type', true); |
| 122 | |
| 123 | removeAttribute(currScript, 'type', !!dataType); |
| 124 | removeAttribute(currScript, SCRIPT_TAG_SELECTOR); |
| 125 | |
| 126 | // Get current script data-src (if there is one) |
| 127 | let src = getAttribute(currScript, 'src', true); |
| 128 | |
| 129 | // Some scripts (like ga) might throw warning if data-src is present |
| 130 | src && removeAttribute(currScript, 'src', true); |
| 131 | |
| 132 | /** |
no test coverage detected
searching dependent graphs…