mirror of
https://github.com/tenrok/bootstrap.git
synced 2026-06-08 17:22:31 +03:00
Add all javascript in bundle
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
{
|
||||
"env": {
|
||||
"browser": true,
|
||||
"es6": true
|
||||
},
|
||||
"plugins": [
|
||||
"markdown"
|
||||
],
|
||||
"overrides": [
|
||||
{
|
||||
// In v2, configuration for fenced code blocks is separate from the
|
||||
// containing Markdown file. Each code block has a virtual filename
|
||||
// appended to the Markdown file's path.
|
||||
"files": [
|
||||
"./**/*.js"
|
||||
],
|
||||
// Configuration for fenced code blocks goes with the override for
|
||||
// the code block's virtual filename, for example:
|
||||
"parserOptions": {
|
||||
"ecmaFeatures": {
|
||||
"impliedStrict": true
|
||||
}
|
||||
},
|
||||
"rules": {
|
||||
"no-array-for-each": "off",
|
||||
"unicorn/no-array-for-each": "off",
|
||||
"unicorn/numeric-separators-style": "off",
|
||||
"no-unused-expressions": "off",
|
||||
"no-unused-labels": "off",
|
||||
"no-labels": "off"
|
||||
}
|
||||
}
|
||||
],
|
||||
"parserOptions": {
|
||||
"sourceType": "module"
|
||||
},
|
||||
"extends": "../.eslintrc.json",
|
||||
"rules": {
|
||||
"no-new": "off",
|
||||
"prefer-template": "error",
|
||||
"strict": "error",
|
||||
"unicorn/no-array-for-each": "off",
|
||||
"unicorn/numeric-separators-style": "off"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// NOTICE!! DO NOT USE ANY OF THIS JAVASCRIPT
|
||||
// IT'S ALL JUST JUNK FOR OUR DOCS!
|
||||
// ++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
/*!
|
||||
* JavaScript for Bootstrap's docs (https://getbootstrap.com/)
|
||||
* Copyright 2011-2022 The Bootstrap Authors
|
||||
* Copyright 2011-2022 Twitter, Inc.
|
||||
* Licensed under the Creative Commons Attribution 3.0 Unported License.
|
||||
* For details, see https://creativecommons.org/licenses/by/3.0/.
|
||||
*/
|
||||
|
||||
|
||||
// Scroll the active sidebar link into view
|
||||
const sidenav = document.querySelector('.bd-sidebar')
|
||||
if (sidenav) {
|
||||
const sidenavHeight = sidenav.clientHeight
|
||||
const sidenavActiveLink = document.querySelector('.bd-links-nav .active')
|
||||
const sidenavActiveLinkTop = sidenavActiveLink.offsetTop
|
||||
const sidenavActiveLinkHeight = sidenavActiveLink.clientHeight
|
||||
const viewportTop = sidenavActiveLinkTop
|
||||
const viewportBottom = viewportTop - sidenavHeight + sidenavActiveLinkHeight
|
||||
|
||||
if (sidenav.scrollTop > viewportTop || sidenav.scrollTop < viewportBottom) {
|
||||
sidenav.scrollTop = viewportTop - (sidenavHeight / 2) + (sidenavActiveLinkHeight / 2)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
// NOTICE!! DO NOT USE ANY OF THIS JAVASCRIPT
|
||||
// IT'S ALL JUST JUNK FOR OUR DOCS!
|
||||
// ++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
/*!
|
||||
* JavaScript for Bootstrap's docs (https://getbootstrap.com/)
|
||||
* Copyright 2011-2022 The Bootstrap Authors
|
||||
* Copyright 2011-2022 Twitter, Inc.
|
||||
* Licensed under the Creative Commons Attribution 3.0 Unported License.
|
||||
* For details, see https://creativecommons.org/licenses/by/3.0/.
|
||||
*/
|
||||
|
||||
import ClipboardJS from 'clipboard'
|
||||
// import { Tooltip } from '../../../dist/js/bootstrap.esm.min.js'
|
||||
/* global bootstrap: false */
|
||||
|
||||
// Insert copy to clipboard button before .highlight
|
||||
const btnTitle = 'Copy to clipboard'
|
||||
const btnEdit = 'Edit on StackBlitz'
|
||||
|
||||
const btnHtml = [
|
||||
'<div class="bd-code-snippet">',
|
||||
' <div class="bd-clipboard">',
|
||||
' <button type="button" class="btn-clipboard">',
|
||||
' <svg class="bi" role="img" aria-label="Copy"><use xlink:href="#clipboard"/></svg>',
|
||||
' </button>',
|
||||
' </div>',
|
||||
'</div>'
|
||||
].join('')
|
||||
|
||||
// wrap programmatically code blocks and add copy btn.
|
||||
document.querySelectorAll('.highlight')
|
||||
.forEach(element => {
|
||||
if (!element.closest('.bd-example-snippet')) { // Ignore examples made be shortcode
|
||||
element.insertAdjacentHTML('beforebegin', btnHtml)
|
||||
element.previousElementSibling.append(element)
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} selector
|
||||
* @param {string} title
|
||||
*/
|
||||
function snippetButtonTooltip(selector, title) {
|
||||
document.querySelectorAll(selector).forEach(btn => {
|
||||
bootstrap.Tooltip.getOrCreateInstance(btn, { title })
|
||||
})
|
||||
}
|
||||
|
||||
snippetButtonTooltip('.btn-clipboard', btnTitle)
|
||||
snippetButtonTooltip('.btn-edit', btnEdit)
|
||||
|
||||
const clipboard = new ClipboardJS('.btn-clipboard', {
|
||||
target: trigger => trigger.closest('.bd-code-snippet').querySelector('.highlight')
|
||||
})
|
||||
|
||||
clipboard.on('success', event => {
|
||||
const iconFirstChild = event.trigger.querySelector('.bi').firstChild
|
||||
const tooltipBtn = bootstrap.Tooltip.getInstance(event.trigger)
|
||||
const namespace = 'http://www.w3.org/1999/xlink'
|
||||
const originalXhref = iconFirstChild.getAttributeNS(namespace, 'href')
|
||||
const originalTitle = event.trigger.title
|
||||
|
||||
tooltipBtn.setContent({ '.tooltip-inner': 'Copied!' })
|
||||
event.trigger.addEventListener('hidden.bs.tooltip', () => {
|
||||
tooltipBtn.setContent({ '.tooltip-inner': btnTitle })
|
||||
}, { once: true })
|
||||
event.clearSelection()
|
||||
iconFirstChild.setAttributeNS(namespace, 'href', originalXhref.replace('clipboard', 'check2'))
|
||||
|
||||
setTimeout(() => {
|
||||
iconFirstChild.setAttributeNS(namespace, 'href', originalXhref)
|
||||
event.trigger.title = originalTitle
|
||||
}, 2000)
|
||||
})
|
||||
|
||||
clipboard.on('error', event => {
|
||||
const modifierKey = /mac/i.test(navigator.userAgent) ? '\u2318' : 'Ctrl-'
|
||||
const fallbackMsg = `Press ${modifierKey}C to copy`
|
||||
const tooltipBtn = bootstrap.Tooltip.getInstance(event.trigger)
|
||||
|
||||
tooltipBtn.setContent({ '.tooltip-inner': fallbackMsg })
|
||||
event.trigger.addEventListener('hidden.bs.tooltip', () => {
|
||||
tooltipBtn.setContent({ '.tooltip-inner': btnTitle })
|
||||
}, { once: true })
|
||||
})
|
||||
|
||||
@@ -2,18 +2,18 @@
|
||||
// IT'S ALL JUST JUNK FOR OUR DOCS!
|
||||
// ++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
import docsearch from '@docsearch/js'
|
||||
// const docsearch = await import('@docsearch/js');
|
||||
(() => {
|
||||
'use strict'
|
||||
|
||||
const searchElement = document.getElementById('docsearch')
|
||||
|
||||
if (!window.docsearch || !searchElement) {
|
||||
if (!searchElement) {
|
||||
return
|
||||
}
|
||||
|
||||
const siteDocsVersion = searchElement.getAttribute('data-bd-docs-version')
|
||||
|
||||
window.docsearch({
|
||||
docsearch({
|
||||
apiKey: '3151f502c7b9e9dafd5e6372b691a24e',
|
||||
indexName: 'bootstrap',
|
||||
appId: 'AK7KMZKZHQ',
|
||||
@@ -0,0 +1,17 @@
|
||||
import * as StackBlitzSDK from '@stackblitz/sdk/bundles/sdk'
|
||||
/* global openBootstrapSnippet: false */
|
||||
|
||||
// Open in StackBlitz logic
|
||||
document.querySelectorAll('.btn-edit').forEach(btn => {
|
||||
btn.addEventListener('click', event => {
|
||||
const htmlSnippet = event.target.closest('.bd-code-snippet').querySelector('.bd-example').innerHTML
|
||||
|
||||
// Get extra classes for this example
|
||||
const classes = Array.from(event.target.closest('.bd-code-snippet').querySelector('.bd-example').classList).join(' ')
|
||||
|
||||
const jsSnippet = event.target.closest('.bd-code-snippet').querySelector('.btn-edit').getAttribute('data-sb-js-snippet')
|
||||
|
||||
StackBlitzSDK.openProject(openBootstrapSnippet(htmlSnippet, jsSnippet, classes), { openFile: 'index.html' })
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
// NOTICE!! DO NOT USE ANY OF THIS JAVASCRIPT
|
||||
// IT'S ALL JUST JUNK FOR OUR DOCS!
|
||||
// ++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
/*!
|
||||
* JavaScript for Bootstrap's docs (https://getbootstrap.com/)
|
||||
* Copyright 2011-2022 The Bootstrap Authors
|
||||
* Copyright 2011-2022 Twitter, Inc.
|
||||
* Licensed under the Creative Commons Attribution 3.0 Unported License.
|
||||
* For details, see https://creativecommons.org/licenses/by/3.0/.
|
||||
*/
|
||||
|
||||
(() => {
|
||||
'use strict'
|
||||
|
||||
// Scroll the active sidebar link into view
|
||||
const sidenav = document.querySelector('.bd-sidebar')
|
||||
if (sidenav) {
|
||||
const sidenavHeight = sidenav.clientHeight
|
||||
const sidenavActiveLink = document.querySelector('.bd-links-nav .active')
|
||||
const sidenavActiveLinkTop = sidenavActiveLink.offsetTop
|
||||
const sidenavActiveLinkHeight = sidenavActiveLink.clientHeight
|
||||
const viewportTop = sidenavActiveLinkTop
|
||||
const viewportBottom = viewportTop - sidenavHeight + sidenavActiveLinkHeight
|
||||
|
||||
if (sidenav.scrollTop > viewportTop || sidenav.scrollTop < viewportBottom) {
|
||||
sidenav.scrollTop = viewportTop - (sidenavHeight / 2) + (sidenavActiveLinkHeight / 2)
|
||||
}
|
||||
}
|
||||
})()
|
||||
@@ -1,88 +0,0 @@
|
||||
// NOTICE!! DO NOT USE ANY OF THIS JAVASCRIPT
|
||||
// IT'S ALL JUST JUNK FOR OUR DOCS!
|
||||
// ++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
/*!
|
||||
* JavaScript for Bootstrap's docs (https://getbootstrap.com/)
|
||||
* Copyright 2011-2022 The Bootstrap Authors
|
||||
* Copyright 2011-2022 Twitter, Inc.
|
||||
* Licensed under the Creative Commons Attribution 3.0 Unported License.
|
||||
* For details, see https://creativecommons.org/licenses/by/3.0/.
|
||||
*/
|
||||
|
||||
/* global ClipboardJS: false, bootstrap: false */
|
||||
|
||||
(() => {
|
||||
'use strict'
|
||||
// Insert copy to clipboard button before .highlight
|
||||
const btnTitle = 'Copy to clipboard'
|
||||
const btnEdit = 'Edit on StackBlitz'
|
||||
|
||||
const btnHtml = [
|
||||
'<div class="bd-code-snippet">',
|
||||
' <div class="bd-clipboard">',
|
||||
' <button type="button" class="btn-clipboard">',
|
||||
' <svg class="bi" role="img" aria-label="Copy"><use xlink:href="#clipboard"/></svg>',
|
||||
' </button>',
|
||||
' </div>',
|
||||
'</div>'
|
||||
].join('')
|
||||
|
||||
// wrap programmatically code blocks and add copy btn.
|
||||
document.querySelectorAll('.highlight')
|
||||
.forEach(element => {
|
||||
if (!element.closest('.bd-example-snippet')) { // Ignore examples made be shortcode
|
||||
element.insertAdjacentHTML('beforebegin', btnHtml)
|
||||
element.previousElementSibling.append(element)
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} selector
|
||||
* @param {string} title
|
||||
*/
|
||||
function snippetButtonTooltip(selector, title) {
|
||||
document.querySelectorAll(selector).forEach(btn => {
|
||||
bootstrap.Tooltip.getOrCreateInstance(btn, { title })
|
||||
})
|
||||
}
|
||||
|
||||
snippetButtonTooltip('.btn-clipboard', btnTitle)
|
||||
snippetButtonTooltip('.btn-edit', btnEdit)
|
||||
|
||||
const clipboard = new ClipboardJS('.btn-clipboard', {
|
||||
target: trigger => trigger.closest('.bd-code-snippet').querySelector('.highlight')
|
||||
})
|
||||
|
||||
clipboard.on('success', event => {
|
||||
const iconFirstChild = event.trigger.querySelector('.bi').firstChild
|
||||
const tooltipBtn = bootstrap.Tooltip.getInstance(event.trigger)
|
||||
const namespace = 'http://www.w3.org/1999/xlink'
|
||||
const originalXhref = iconFirstChild.getAttributeNS(namespace, 'href')
|
||||
const originalTitle = event.trigger.title
|
||||
|
||||
tooltipBtn.setContent({ '.tooltip-inner': 'Copied!' })
|
||||
event.trigger.addEventListener('hidden.bs.tooltip', () => {
|
||||
tooltipBtn.setContent({ '.tooltip-inner': btnTitle })
|
||||
}, { once: true })
|
||||
event.clearSelection()
|
||||
iconFirstChild.setAttributeNS(namespace, 'href', originalXhref.replace('clipboard', 'check2'))
|
||||
|
||||
setTimeout(() => {
|
||||
iconFirstChild.setAttributeNS(namespace, 'href', originalXhref)
|
||||
event.trigger.title = originalTitle
|
||||
}, 2000)
|
||||
})
|
||||
|
||||
clipboard.on('error', event => {
|
||||
const modifierKey = /mac/i.test(navigator.userAgent) ? '\u2318' : 'Ctrl-'
|
||||
const fallbackMsg = `Press ${modifierKey}C to copy`
|
||||
const tooltipBtn = bootstrap.Tooltip.getInstance(event.trigger)
|
||||
|
||||
tooltipBtn.setContent({ '.tooltip-inner': fallbackMsg })
|
||||
event.trigger.addEventListener('hidden.bs.tooltip', () => {
|
||||
tooltipBtn.setContent({ '.tooltip-inner': btnTitle })
|
||||
}, { once: true })
|
||||
})
|
||||
})()
|
||||
@@ -0,0 +1,8 @@
|
||||
|
||||
// import('./../../../dist/js/bootstrap.esm.min')
|
||||
import('./_application.js')
|
||||
import('./_search.js')
|
||||
import('./snippets.js')
|
||||
import('./_code-examples.js')
|
||||
import('./_stackblitz.js')
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
/* global bootstrap: false */
|
||||
|
||||
(() => {
|
||||
'use strict'
|
||||
|
||||
// --------
|
||||
// Tooltips
|
||||
// --------
|
||||
|
||||
-7
File diff suppressed because one or more lines are too long
@@ -4,38 +4,22 @@
|
||||
<script src="/docs/{{ .Site.Params.docs_version }}/dist/js/bootstrap.bundle.js"></script>
|
||||
{{- end }}
|
||||
|
||||
{{ if eq .Page.Layout "docs" -}}
|
||||
<script src="https://cdn.jsdelivr.net/npm/@docsearch/js@3"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/@stackblitz/sdk@1/bundles/sdk.umd.js"></script>
|
||||
{{- end }}
|
||||
{{- $docsJs := resources.Get "js/main.js" -}}
|
||||
|
||||
{{- $vendor := resources.Match "js/vendor/*.js" -}}
|
||||
{{- $js := resources.Match "js/*.js" -}}
|
||||
{{- $targetDocsJSPath := path.Join "/docs" .Site.Params.docs_version "assets/js/docs.js" -}}
|
||||
{{- $docsJs := append $js $vendor | resources.Concat $targetDocsJSPath -}}
|
||||
{{ if eq hugo.Environment "development" -}}
|
||||
{{ $docsJs = $docsJs | js.Build (dict "format" "esm" "sourceMap" "inline") -}}
|
||||
{{ else -}}
|
||||
{{ $docsJs = $docsJs | js.Build (dict "format" "esm" "minify" true) | fingerprint -}}
|
||||
{{ end -}}
|
||||
|
||||
{{- if eq hugo.Environment "production" -}}
|
||||
{{- $docsJs = $docsJs | resources.Minify -}}
|
||||
{{- end }}
|
||||
|
||||
<script src="{{ $docsJs.Permalink | relURL }}"></script>
|
||||
|
||||
<script src="{{ $docsJs.Permalink | relURL }}" defer></script>
|
||||
|
||||
{{ if eq .Page.Layout "docs" -}}
|
||||
<script>
|
||||
// Open in StackBlitz logic
|
||||
document.querySelectorAll('.btn-edit').forEach(btn => {
|
||||
btn.addEventListener('click', event => {
|
||||
const htmlSnippet = event.target.closest('.bd-code-snippet').querySelector('.bd-example').innerHTML
|
||||
|
||||
// Get extra classes for this example
|
||||
const classes = Array.from(event.target.closest('.bd-code-snippet').querySelector('.bd-example').classList).join(' ')
|
||||
|
||||
const jsSnippet = event.target.closest('.bd-code-snippet').querySelector('.btn-edit').getAttribute('data-sb-js-snippet')
|
||||
StackBlitzSDK.openBootstrapSnippet(htmlSnippet, jsSnippet, classes)
|
||||
})
|
||||
})
|
||||
|
||||
StackBlitzSDK.openBootstrapSnippet = (htmlSnippet, jsSnippet, classes) => {
|
||||
openBootstrapSnippet = (htmlSnippet, jsSnippet, classes) => {
|
||||
const markup = `<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
@@ -55,7 +39,7 @@ ${htmlSnippet.replace(/^/gm, ' ')}
|
||||
</html>`
|
||||
|
||||
const jsSnippetContent = jsSnippet ? '{{ os.ReadFile "site/assets/js/snippets.js" }}' : null
|
||||
const project = {
|
||||
return {
|
||||
files: {
|
||||
'index.html': markup,
|
||||
'index.js': jsSnippetContent
|
||||
@@ -65,8 +49,6 @@ ${htmlSnippet.replace(/^/gm, ' ')}
|
||||
template: jsSnippet ? 'javascript' : 'html',
|
||||
tags: ['bootstrap']
|
||||
}
|
||||
|
||||
StackBlitzSDK.openProject(project, { openFile: 'index.html' })
|
||||
}
|
||||
</script>
|
||||
{{- end }}
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
{{- $sassOptions = merge $sassOptions (dict "outputStyle" "compressed") -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $style := resources.Get "scss/docs.scss" | toCSS $sassOptions | postCSS $postcssOptions }}
|
||||
{{- $style := resources.Get "scss/docs.scss" | resources.ToCSS $sassOptions | postCSS $postcssOptions }}
|
||||
|
||||
<link href="{{ $style.Permalink | relURL }}" rel="stylesheet">
|
||||
{{- end }}
|
||||
|
||||
Reference in New Issue
Block a user