Fix some js scripts being loaded before their dependencies in ajax calls

This commit is contained in:
Stephen Abello
2023-04-18 10:38:18 +02:00
parent de32b96a83
commit adcd0eb9b0

View File

@@ -1,6 +1,7 @@
{# @copyright Copyright (C) 2010-2023 Combodo SARL #}
{# @license http://opensource.org/licenses/AGPL-3.0 #}
{% apply spaceless %}
{% set sId = oLayout.GetId() | sanitize(constant('utils::ENUM_SANITIZATION_FILTER_VARIABLE_NAME')) %}
{% if bEscapeContent %}
{{ render_block(oLayout, {aPage: aPage})|escape }}
{% else %}
@@ -16,33 +17,33 @@
{% endfor %}
{% endblock %}
{% block iboPageJsInlineLive %}
{% for sJsInline in aPage.aJsInlineLive %}
{# We put each scripts in a dedicated script tag to prevent massive failure if 1 script is broken (eg. missing semi-colon or non closed multi-line comment) #}
<script type="text/javascript">
{{ sJsInline|raw }}
</script>
{% endfor %}
{% for sJsInline in aPage.aJsInlineOnInit %}
<script type="text/javascript">
{{ sJsInline|raw }}
</script>
{% endfor %}
{% endblock %}
{% block iboPageJsInlineLive %}
{% for sJsInline in aPage.aJsInlineLive %}
{# We put each scripts in a dedicated script tag to prevent massive failure if 1 script is broken (eg. missing semi-colon or non closed multi-line comment) #}
<script type="text/javascript">
{{ sJsInline|raw }}
</script>
{% endfor %}
{% endblock %}
<script type="text/javascript">
let fOnJsFilesLoaded{{ sId }} = function (fResolve) {
{% for sJsInline in aPage.aJsInlineOnInit %}
{{ sJsInline|raw }}
{% endfor %}
{% for sJsInline in aPage.aJsInlineOnDomReady %}
{{ sJsInline|raw }}
{% endfor %}
fResolve();
}
</script>
{% set sPromiseId = aPage.sPromiseId %}
{% if aPage.aJsFiles is not empty %}
{% set sId = oLayout.GetId() | sanitize(constant('utils::ENUM_SANITIZATION_FILTER_VARIABLE_NAME')) %}
{% block iboPageJsFiles %}
<script type="text/javascript">
window['{{ sPromiseId }}'] = new Promise(function (resolve, reject) {
let fInlineOnDomReadyScript{{ sId }} = function () {
{% for sJsInlineOnDomReady in aPage.aJsInlineOnDomReady %}
{{ sJsInlineOnDomReady|raw }}
{% endfor %}
resolve();
}
window['{{ sPromiseId }}'] = new Promise(function (fAllJsFilesResolve, fAllJsFilesReject) {
/**
* @type {Array} aJsFilesToLoad Files required by the current \AjaxPage
*
@@ -117,7 +118,7 @@
}
else
{
fInlineOnDomReadyScript{{ sId }}();
fOnJsFilesLoaded{{ sId }}(fAllJsFilesResolve);
}
});
};
@@ -125,21 +126,18 @@
}
else
{
fInlineOnDomReadyScript{{ sId }}();
fOnJsFilesLoaded{{ sId }}(fAllJsFilesResolve);
}
});
</script>
{% endblock %}
{% else %}
{% block iboPageJsInlineOnDomReady %}
{% for sJsInlineOnDomReady in aPage.aJsInlineOnDomReady %}
<script type="text/javascript">
window['{{ sPromiseId }}'] = new Promise(function (resolve, reject) {
{{ sJsInlineOnDomReady|raw }}
resolve();
<script type="text/javascript">
window['{{ sPromiseId }}'] = new Promise(function (fNoJsFileResolve, fNoJsFileReject) {
fOnJsFilesLoaded{{ sId }}(fNoJsFileResolve);
});
</script>
{% endfor %}
</script>
{% endblock %}
{% endif %}