diff options
| author | Julien Déramond <[email protected]> | 2022-05-26 23:29:08 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-05-26 14:29:08 -0700 |
| commit | 8b85267739e4bee63f13dfa14a94f94926b4fd7a (patch) | |
| tree | 4f8d807c01f9d90741887263e21348c016419fed /site/layouts/partials/scripts.html | |
| parent | 4a3c004c349ec9b20990c8aa760d12c50c450bbd (diff) | |
| download | bootstrap-8b85267739e4bee63f13dfa14a94f94926b4fd7a.tar.xz bootstrap-8b85267739e4bee63f13dfa14a94f94926b4fd7a.zip | |
Fix StackBlitz examples by embedding snippets.js when needed (#36352)
* Fix StackBlitz examples by embedding snippets.js when needed
* Fix Popovers
* Fix tooltips
* Fix Toasts
* Add comment sections
* Fix Alerts
* Indeterminate heckboxes + classes handling
* Nothing to do for links
* Fix modals
* Nothing to do for Offcanvas
* Remove correctly .bd-example
* Add body .p-3 for all StackBlitz examples
Diffstat (limited to 'site/layouts/partials/scripts.html')
| -rw-r--r-- | site/layouts/partials/scripts.html | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/site/layouts/partials/scripts.html b/site/layouts/partials/scripts.html index 56513c7ff..5535d6439 100644 --- a/site/layouts/partials/scripts.html +++ b/site/layouts/partials/scripts.html @@ -26,11 +26,16 @@ document.querySelectorAll('.btn-edit').forEach(btn => { btn.addEventListener('click', event => { const htmlSnippet = event.target.closest('.bd-code-snippet').querySelector('.bd-example').innerHTML - StackBlitzSDK.openBootstrapSnippet(htmlSnippet) + + // Get extra classes for this example except '.bd-example' + const classes = Array.from(event.target.closest('.bd-code-snippet').querySelector('.bd-example').classList).filter(x => x !== 'bd-example').join(' ') + + const jsSnippet = event.target.closest('.bd-code-snippet').querySelector('.btn-edit').getAttribute('data-js-snippet') + StackBlitzSDK.openBootstrapSnippet(htmlSnippet, jsSnippet, classes) }) }) - StackBlitzSDK.openBootstrapSnippet = snippet => { + StackBlitzSDK.openBootstrapSnippet = (htmlSnippet, jsSnippet, classes) => { const markup = `<!doctype html> <html lang="en"> <head> @@ -38,24 +43,25 @@ <meta name="viewport" content="width=device-width, initial-scale=1"> <link href="{{ .Site.Params.cdn.css }}" rel="stylesheet"> <title>Bootstrap Example</title> + <${'script'} src="{{ .Site.Params.cdn.js_bundle }}"></${'script'}> </head> - <body> + <body class="p-3 ${classes}"> <!-- Example Code --> -${snippet.replace(/^/gm, ' ')} +${htmlSnippet.replace(/^/gm, ' ')} <!-- End Example Code --> - - <${'script'} src="{{ .Site.Params.cdn.js_bundle }}"></${'script'}> </body> </html>` + const jsSnippetContent = jsSnippet ? '{{ os.ReadFile "site/assets/js/snippets.js" }}' : null const project = { files: { - 'index.html': markup + 'index.html': markup, + 'index.js': jsSnippetContent }, title: 'Bootstrap Example', description: `Official example from ${window.location.href}`, - template: 'html', + template: jsSnippet ? 'javascript' : 'html', tags: ['bootstrap'] } |
