Merge pull request #2642 from sammarshallou/MOBILE-3607

MOBILE-3607 Site plugins: CSS should be included in reliable order
main
Juan Leyva 2020-12-09 12:56:34 +01:00 committed by GitHub
commit c6243bce12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 1 deletions

View File

@ -439,7 +439,21 @@ export class CoreSitePluginsHelperProvider {
styleEl.setAttribute('id', 'siteplugin-' + uniqueName);
styleEl.innerHTML = cssCode;
// To ensure consistency, insert in alphabetical order among other site plugin styles.
let lowestGreater = null;
Array.from(document.head.querySelectorAll('style')).forEach((other) => {
if (/^siteplugin-/.test(other.id) && other.id > styleEl.id) {
if (lowestGreater === null || other.id < lowestGreater.id) {
lowestGreater = other;
}
}
});
if (lowestGreater) {
document.head.insertBefore(styleEl, lowestGreater);
} else {
document.head.appendChild(styleEl);
}
// Styles have been loaded, now treat the CSS.
this.filepoolProvider.treatCSSCode(siteId, fileUrl, cssCode, CoreSitePluginsProvider.COMPONENT, uniqueName, version)