From 513c0139e2e0b6678461199ba256c9e0f8d96888 Mon Sep 17 00:00:00 2001 From: nickolasjadams Date: Wed, 18 Nov 2020 22:53:29 -0700 Subject: [PATCH] Added multipath enhancement Multiple JS filepaths can now be added by delimiting the paths with a comma Example /js/cp1.js, /jscp2.js --- README.md | 2 +- src/templates/settings.twig | 4 ++-- src/web/assets/CustomAssets.php | 20 +++++++++++++++----- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 8d78bce..955616d 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ After you've installed the plugin, go to: Your custom JavaScript can be saved in either (or both) of two places: -**1) An external file in your public directory...** +**1) One or more external files in your public directory delimited by commas...** ![](src/resources/img/example-jsFile.png) **2) The "Additional JavaScript" field on the settings page...** diff --git a/src/templates/settings.twig b/src/templates/settings.twig index 99f9ca3..489d440 100644 --- a/src/templates/settings.twig +++ b/src/templates/settings.twig @@ -11,8 +11,8 @@

Your custom JavaScript will be applied to the entire Control Panel.

{{ forms.autosuggestField({ - label: "JavaScript File"|t, - instructions: "Enter the path to your JavaScript file."|t, + label: "JavaScript File(s)"|t, + instructions: "Enter the path to your JavaScript file(s). Multiple filepaths may be delimited by commas."|t, id: 'jsFile', name: 'jsFile', suggestEnvVars: true, diff --git a/src/web/assets/CustomAssets.php b/src/web/assets/CustomAssets.php index 446bcd0..6b86493 100644 --- a/src/web/assets/CustomAssets.php +++ b/src/web/assets/CustomAssets.php @@ -36,15 +36,25 @@ public function init() $file = trim(Craft::parseEnv($settings['jsFile'])); + $finalPaths = []; + if ($file) { - // Cache buster - if ($hash = @sha1_file($file)) { - $file .= '?e='.$hash; + $files = explode(',', $file); + foreach ($files as $file) { + $file = trim($file); + + // Cache buster + if ($hash = @sha1_file($file)) { + $file .= '?e='.$hash; + } + + array_push($finalPaths, $file); + } - // Load JS file - $this->js = [$file]; + // Load all cachebusted JS files + $this->js = $finalPaths; } }