diff --git a/www/Application.cfc b/www/Application.cfc index 8053e8b..67ce7c9 100644 --- a/www/Application.cfc +++ b/www/Application.cfc @@ -79,6 +79,9 @@ component displayname="Application" output="false" extends="backend.myapp.ownApp // Load layout setting struct and save it into the application scope application.layoutStruct = application.objLayout.layoutSetting(application.systemSettingStruct.settingLayout); + // Load JS and CSS path + application.assetFiles = application.objCoreUtil.getAssets(variables.activeTheme); + ownApplicationStart(); return true; diff --git a/www/frontend/core/com/coreutility.cfc b/www/frontend/core/com/coreutility.cfc index 43549ae..5ff9207 100644 --- a/www/frontend/core/com/coreutility.cfc +++ b/www/frontend/core/com/coreutility.cfc @@ -1,5 +1,91 @@ component displayname="coreutility" output="false" { + /** + * Returns the paths to the CSS and JS files, including versions if available, preferring minified files. + */ + public struct function getAssets(required string theme) { + + local.result = {}; + local.systemPath = expandPath("frontend/" & arguments.theme & "/"); + local.wwwPath = application.mainURL & "/frontend/" & arguments.theme & "/"; + + // Standard CSS file + local.cssFile = local.wwwPath & "css/styles.css"; + + // Standard JS file + local.jsFile = local.wwwPath & "js/scripts.js"; + + + // CSS handling + if (fileExists(local.systemPath & "css/styles.min.css")) { + + // Minimized CSS file + local.cssFile = local.wwwPath & "css/styles.min.css"; + + // JSON file with the current version for the CSS + local.cssVFile = local.systemPath & "css/version.json"; + + if (fileExists(local.cssVFile)) { + + // Read the JSON file + local.jsonFile = fileRead(local.cssVFile); + + if (isJSON(local.jsonFile)) { + + // Extract the version number and append it to the css + local.jsonContent = deserializeJSON(local.jsonFile); + if (structKeyExists(local.jsonContent, "version")) { + local.cssVersion = local.jsonContent.version; + local.cssFile = local.cssFile & "?v=" & local.cssVersion; + } + + } + + } + + } + + local.result["css"] = local.cssFile; + + + // JS handling + if (fileExists(local.systemPath & "js/scripts.min.js")) { + + // Minimized JS file + local.jsFile = local.wwwPath & "js/scripts.min.js"; + + // JSON file with the current version for the CSS + local.jsVFile = local.systemPath & "js/version.json"; + + if (fileExists(local.jsVFile)) { + + // Read the JSON file + local.jsonFile = fileRead(local.jsVFile); + + if (isJSON(local.jsonFile)) { + + // Extract the version number and append it to the js + local.jsonContent = deserializeJSON(local.jsonFile); + if (structKeyExists(local.jsonContent, "version")) { + local.jsVersion = local.jsonContent.version; + local.jsFile = local.jsFile & "?v=" & local.jsVersion; + } + + } + + } + + } + + local.result["js"] = local.jsFile; + + return local.result; + + } + + + + /** * Prepares session data for the registration form and initializes default values if needed. */ diff --git a/www/frontend/custom_theme/css/css-include.cfm b/www/frontend/custom_theme/css/css-include.cfm index c45a9fe..4239488 100644 --- a/www/frontend/custom_theme/css/css-include.cfm +++ b/www/frontend/custom_theme/css/css-include.cfm @@ -2,9 +2,5 @@ - - - - - + diff --git a/www/frontend/custom_theme/js/js-include.cfm b/www/frontend/custom_theme/js/js-include.cfm index 7be4685..f967520 100644 --- a/www/frontend/custom_theme/js/js-include.cfm +++ b/www/frontend/custom_theme/js/js-include.cfm @@ -1,9 +1,5 @@ - - - - - + \ No newline at end of file diff --git a/www/frontend/default_theme/css/css-include.cfm b/www/frontend/default_theme/css/css-include.cfm index c45a9fe..4239488 100644 --- a/www/frontend/default_theme/css/css-include.cfm +++ b/www/frontend/default_theme/css/css-include.cfm @@ -2,9 +2,5 @@ - - - - - + diff --git a/www/frontend/default_theme/js/js-include.cfm b/www/frontend/default_theme/js/js-include.cfm index 7be4685..f967520 100644 --- a/www/frontend/default_theme/js/js-include.cfm +++ b/www/frontend/default_theme/js/js-include.cfm @@ -1,9 +1,5 @@ - - - - - + \ No newline at end of file