Skip to content

Commit

Permalink
Merge pull request #3 from nickolasjadams/multipath-enhancement
Browse files Browse the repository at this point in the history
Added multipath enhancement
  • Loading branch information
lindseydiloreto authored Dec 18, 2020
2 parents 1ed1253 + 513c013 commit 4e03b9b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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...**
Expand Down
4 changes: 2 additions & 2 deletions src/templates/settings.twig
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<p>Your custom JavaScript will be applied to the entire Control Panel.</p>

{{ 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,
Expand Down
20 changes: 15 additions & 5 deletions src/web/assets/CustomAssets.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}
}
Expand Down

0 comments on commit 4e03b9b

Please sign in to comment.