🌐 AI搜索 & 代理 主页
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
49e2a97
feat(v-b-visible): make `v-b-visible` directive available for general…
tmorehouse Oct 30, 2019
d490731
Create README.md
tmorehouse Oct 30, 2019
203b4a9
Create package.json
tmorehouse Oct 30, 2019
a9ee505
Create index.js
tmorehouse Oct 30, 2019
d28fc4c
Create index.d.ts
tmorehouse Oct 30, 2019
44df1b5
Update index.js
tmorehouse Oct 30, 2019
2ed06ce
Update index.d.ts
tmorehouse Oct 30, 2019
f8a2cf7
Update index.js
tmorehouse Oct 30, 2019
7d61743
Update README.md
tmorehouse Oct 30, 2019
15f109c
Update package.json
tmorehouse Oct 30, 2019
200a217
Update package.json
tmorehouse Oct 30, 2019
0521a4e
Delete visible.js
tmorehouse Oct 30, 2019
1c0b2e2
Update img-lazy.js
tmorehouse Oct 30, 2019
48c7263
Update form-textarea.js
tmorehouse Oct 30, 2019
5e68364
Update package.json
tmorehouse Oct 30, 2019
eea74b2
Update README.md
tmorehouse Oct 30, 2019
c4d9b1b
Update package.json
tmorehouse Oct 30, 2019
a3ec638
Update README.md
tmorehouse Oct 30, 2019
577510b
Update package.json
tmorehouse Oct 30, 2019
6b1e181
Update package.json
tmorehouse Oct 30, 2019
a8bb8ba
Update README.md
tmorehouse Oct 30, 2019
b98c27c
Update README.md
tmorehouse Oct 30, 2019
1980eae
Update section-toc.vue
tmorehouse Oct 30, 2019
b864f86
Merge branch 'dev' into feat/v-b-visible
tmorehouse Oct 30, 2019
b3a8f0a
Update section-toc.vue
tmorehouse Oct 30, 2019
4ab3ff5
Update README.md
jacobmllr95 Oct 30, 2019
4f97a5a
Merge branch 'feat/v-b-visible' of https://github.com/bootstrap-vue/b…
jacobmllr95 Oct 30, 2019
7b63738
Update index.d.ts
jacobmllr95 Oct 30, 2019
0d3804a
Update index.d.ts
tmorehouse Oct 30, 2019
07e0256
Update section-toc.vue
tmorehouse Oct 30, 2019
54183fe
Update index.js
jacobmllr95 Oct 30, 2019
48ffea4
Merge branch 'feat/v-b-visible' of https://github.com/bootstrap-vue/b…
jacobmllr95 Oct 30, 2019
174309e
Update section-toc.vue
tmorehouse Oct 30, 2019
b6b8fe1
Update README.md
tmorehouse Oct 30, 2019
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: 2 additions & 0 deletions docs/components/section-toc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
active-class=""
>
<strong class="text-primary">{{ page.title }}</strong> &mdash;
<b-badge v-if="page.new" variant="success">NEW</b-badge>
<span class="text-muted">{{ page.description }}</span>
<b-badge v-if="page.version" variant="secondary">v{{ page.version }}</b-badge>
</b-list-group-item>
</b-list-group>
</Section>
Expand Down
2 changes: 1 addition & 1 deletion src/components/form-textarea/form-textarea.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Vue from '../../utils/vue'
import { VBVisible } from '../../directives/visible'
import { VBVisible } from '../../directives/visible/visible'
import idMixin from '../../mixins/id'
import formMixin from '../../mixins/form'
import formSizeMixin from '../../mixins/form-size'
Expand Down
2 changes: 1 addition & 1 deletion src/components/image/img-lazy.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Vue from '../../utils/vue'
import { getComponentConfig } from '../../utils/config'
import { hasIntersectionObserverSupport } from '../../utils/env'
import { VBVisible } from '../../directives/visible'
import { VBVisible } from '../../directives/visible/visible'
import { BImg } from './img'

const NAME = 'BImgLazy'
Expand Down
5 changes: 3 additions & 2 deletions src/directives/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import { BvPlugin } from '../'
export declare const directivesPlugin: BvPlugin

// Named exports of all directives
export * from './toggle'
export * from './modal'
export * from './popover'
export * from './scrollspy'
export * from './toggle'
export * from './tooltip'
export * from './popover'
export * from './visible'
4 changes: 3 additions & 1 deletion src/directives/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { VBPopoverPlugin } from './popover'
import { VBScrollspyPlugin } from './scrollspy'
import { VBTogglePlugin } from './toggle'
import { VBTooltipPlugin } from './tooltip'
import { VBVisiblePlugin } from './visible'

// Main plugin for installing all directive plugins
export const directivesPlugin = /*#__PURE__*/ pluginFactory({
Expand All @@ -13,6 +14,7 @@ export const directivesPlugin = /*#__PURE__*/ pluginFactory({
VBPopoverPlugin,
VBScrollspyPlugin,
VBTogglePlugin,
VBTooltipPlugin
VBTooltipPlugin,
VBVisiblePlugin
}
})
135 changes: 135 additions & 0 deletions src/directives/visible/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
# Visible

> The `v-b-visible` directive allows you to react when an element becomes visible in the viewport.

The `v-b-visible` directive was added in version `2.1.0`.

## Overview

- `v-b-visible` will call your callback method with a boolean value indicating if the element is
visible (intersecting) with the viewport.
- The directive can be placed on almost any element or component.
- Changes in visibility cqn also be detected (such as `display: none`), as long as the element is
within (or partially within) the viewport, or within the optional offset.
- Several BootstrapVue components use `v-b-visible`, such as `<b-img-lazy>`.
- The `v-b-visible` directive requires browser support of
[`IntersectionObserver`](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API).
For older browsers that do not support `IntersectionObserver`, you will need to use a
[polyfill](/docs/#js).

## Directive syntax and usage

```html
<div v-b-visible.[mod].[...]="callback">content</div>
```

Where `callback` is required:

- A function reference that will be called whenever visibility changes. The callback is passed a
single boolean argument. `true` indicates that the element is intersecting (partially or entirely
visible) in the viewport, or `false` if the element is not visible/intersecting with the viewport.
The callback will be called each time the element's visibility changes (except when hte `once`
modifier is used. See below for details)

Where `[mod]` can be (all optional):

- A positive number representing the offset (margin) in pixels _away_ from the edge of the viewport
to determine when the element is considered in (or just about to be in) the viewport. The value
adds a margin around the view port. The default value is `0`.
- The keyword `once`. When this modifier is present, the callback will be called once (with the
argument of `true` indicating the element is intersecting/visible) when the element is
intersecting with the viewport. Note the callback may be called prior to this with an argument of
`false` signifying the element is not intersecting/visible.

### Usage examples

Basic:

```html
<template>
<div v-b-visible="visibleHandler"> ... </div>
</template>
<script>
export default {
methods: {
visibleHandler(isVisible) {
if (isVisible) {
// Do something
} else {
// Do something else
}
}
}
}
</script>
```

With viewport offset modifier of 350px (if the element is outside of the physical viewport by at
least 350px, then it will be considered "visible"):

```html
<template>
<div v-b-visible.350="visibleHandler"> ... </div>
</template>
<script>
export default {
methods: {
visibleHandler(isVisible) {
if (isVisible) {
// Do something
} else {
// Do something else
}
}
}
}
</script>
```

With `once` modifier:

```html
<template>
<div v-b-visible.350="visibleHandler"> ... </div>
</template>
<script>
export default {
methods: {
visibleHandler(isVisible) {
if (isVisible) {
// This will only ever happen once, when the
// element has become visible for the first time
} else {
// This may happen zero or more times before
// the element becomes visible, but will never
// happen after the element has become visible
}
}
}
}
</script>
```

With `once` and offset modifiers:

```html
<template>
<div v-b-visible.350.once="visibleHandler"> ... </div>
</template>
<script>
export default {
methods: {
visibleHandler(isVisible) {
if (isVisible) {
// This will only ever happen once, when the
// element has become visible for the first time
} else {
// This may happen zero or more times before
// the element becomes visible, but will never
// happen after the element has become visible
}
}
}
}
</script>
```
11 changes: 11 additions & 0 deletions src/directives/visible/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//
// VBVisible
//
import Vue, { DirectiveOptions } from 'vue'
import { BvPlugin } from '../../'

// Plugin
export declare const VBVisiblePlugin: BvPlugin

// Directive: v-b-visible
export declare const VBVisible: DirectiveOptions
8 changes: 8 additions & 0 deletions src/directives/visible/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { VBVisible } from './visible'
import { pluginFactory } from '../../utils/plugins'

const VBVisiblePlugin = /*#__PURE__*/ pluginFactory({
directives: { VBVisible }
})

export { VBVisiblePlugin, VBVisible }
25 changes: 25 additions & 0 deletions src/directives/visible/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "@bootstrap-vue/v-b-visible",
"version": "0.0.0",
"meta": {
"title": "Visible",
"description": "The `v-b-visible` directive allows you to react when an element becomes visible in the viewport.",
"directive": "VBVisible",
"new": true,
"version": "2.1.0",
"expression": [
"Function"
],
"modifiers": [
{
"name": "once",
"description": "Only calls the callback once when the element becomes visible in the viewport"
},
{
"name": "{###}",
"pattern": "[0-9]+",
"description": "An offset value in pixels (where `{###}` is the number of pixels) relative to the viewport, defaults to 0. Negative values allowed"
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
// )
// }

import looseEqual from '../utils/loose-equal'
import { requestAF } from '../utils/dom'
import { isFunction } from '../utils/inspect'
import { keys } from '../utils/object'
import looseEqual from '../../utils/loose-equal'
import { requestAF } from '../../utils/dom'
import { isFunction } from '../../utils/inspect'
import { keys } from '../../utils/object'

const OBSERVER_PROP_NAME = '__bv__visibility_observer'

Expand Down
23 changes: 14 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,22 @@ export {
//
// Export named injection plugins
//
// TODO: we should probably move injections into their
// own parent directory (i.e. /src/injections)
// TODO:
// We should probably move injections into their own
// parent directory (i.e. `/src/injections`)
export { BVModalPlugin } from './components/modal/helpers/bv-modal'
export { BVToastPlugin } from './components/toast/helpers/bv-toast'

//
// Export all individual components and component group plugins as named exports.
//

// Webpack 4 has optimization difficulties with re-eport of re-exports, so
// we import the components individulaly here for better tree shaking,
// Webpack 4 has optimization difficulties with re-export of re-exports,
// so we import the components individually here for better tree shaking
//
// Webpack v5 fixes the optimizations with re-export of re-exports so this
// can be reverted back to `export * from './table'` when Webpack v5 is released.
// https://github.com/webpack/webpack/pull/9203 (available in Webpack v5.0.0-alpha.15)
// can be reverted back to `export * from './table'` when Webpack v5 is released
// See: https://github.com/webpack/webpack/pull/9203 (available in Webpack v5.0.0-alpha.15)

// export * from './components/alert'
export { AlertPlugin } from './components/alert'
Expand Down Expand Up @@ -273,11 +274,11 @@ export { BTooltip } from './components/tooltip/tooltip'
// Named exports of all directives (VB<Name>) and Plugins (VB<name>Plugin)
//

// Webpack 4 has optimization difficulties with re-eport of re-exports, so
// we import the directives individulaly here for better tree shaking,
// Webpack 4 has optimization difficulties with re-export of re-exports,
// so we import the directives individually here for better tree shaking
//
// Webpack v5 fixes the optimizations with re-export of re-exports so this
// can be reverted back to `export * from './scrollspy'` when Webpack v5 is released.
// can be reverted back to `export * from './scrollspy'` when Webpack v5 is released
// https://github.com/webpack/webpack/pull/9203 (available in Webpack v5.0.0-alpha.15)

// export * from './directives/modal'
Expand All @@ -300,5 +301,9 @@ export { VBToggle } from './directives/toggle/toggle'
export { VBTooltipPlugin } from './directives/tooltip'
export { VBTooltip } from './directives/tooltip/tooltip'

// export * from './directives/tooltip'
export { VBVisiblePlugin } from './directives/visible'
export { VBVisible } from './directives/visible/visible'

// Default export is the BootstrapVue plugin
export default BootstrapVue