Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added multipath enhancement #3

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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