Skip to content

Commit

Permalink
Added method of providing options for script install
Browse files Browse the repository at this point in the history
  • Loading branch information
Accudio committed Sep 23, 2022
1 parent da6f842 commit a0c5b7d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ AsyncAlpine.init(Alpine, {
Alpine.prefix('data-x-')
```

For a script installation, advanced options can be specified by setting `window.AsyncAlpineOptions` to the object as above.

### Available Options

| Option Name | property | Default | Notes |
Expand Down
2 changes: 1 addition & 1 deletion dist/async-alpine.script.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { AsyncAlpine } from './core/async-alpine.js';

document.addEventListener('alpine:init', () => {
window.AsyncAlpine = AsyncAlpine;
AsyncAlpine.init(Alpine);
AsyncAlpine.init(
Alpine,
window.AsyncAlpineOptions || {}
);
document.dispatchEvent(new CustomEvent('async-alpine:init'));
AsyncAlpine.start();
});
1 change: 1 addition & 0 deletions tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ <h2>Misc</h2>
<li><a href="/dynamic">Dynamic Import</a></li>
<li><a href="/mutation">Mutation</a></li>
<li><a href="/mutation-nested">Nested Mutation</a></li>
<li><a href="/script-options">Script Options</a></li>
</ul>
</body>
</html>
25 changes: 25 additions & 0 deletions tests/script-options.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<title>Script Options - Async Alpine tests</title>
</head>
<body>
<div
ax-load
ax-load-src="/components/output.js"
x-data="output('loaded')"
x-ignore
></div>

<script>
window.AsyncAlpineOptions = {
defaultStrategy: 'media (max-width:800px)'
}
</script>
<script src="/dist/async-alpine.script.js"></script>
<script src="https://unpkg.com/[email protected]/dist/cdn.min.js"></script>
</body>
</html>

0 comments on commit a0c5b7d

Please sign in to comment.