@gorse/shards-vue 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +13 -0
- package/CHANGELOG.md +49 -0
- package/CONTRIBUTING.md +92 -0
- package/ISSUE_TEMPLATE.md +19 -0
- package/LICENSE +21 -0
- package/README.md +157 -0
- package/build/optimize.js +49 -0
- package/build/paths.js +12 -0
- package/build/rollup.config.js +106 -0
- package/dist/shards-vue.common.js +13994 -0
- package/dist/shards-vue.common.js.map +1 -0
- package/dist/shards-vue.common.min.js +1 -0
- package/dist/shards-vue.common.min.map +1 -0
- package/dist/shards-vue.esm.js +13990 -0
- package/dist/shards-vue.esm.js.map +1 -0
- package/dist/shards-vue.esm.min.js +1 -0
- package/dist/shards-vue.esm.min.map +1 -0
- package/dist/shards-vue.umd.js +13997 -0
- package/dist/shards-vue.umd.js.map +1 -0
- package/dist/shards-vue.umd.min.js +1 -0
- package/dist/shards-vue.umd.min.map +1 -0
- package/logo.jpg +0 -0
- package/package.json +121 -0
- package/sandbox/Sandbox.vue +45 -0
- package/src/components/alert/Alert.vue +156 -0
- package/src/components/alert/README.md +86 -0
- package/src/components/alert/index.js +17 -0
- package/src/components/badge/Badge.vue +62 -0
- package/src/components/badge/README.md +112 -0
- package/src/components/badge/index.js +17 -0
- package/src/components/breadcrumb/Breadcrumb.vue +55 -0
- package/src/components/breadcrumb/BreadcrumbItem.vue +42 -0
- package/src/components/breadcrumb/BreadcrumbLink.vue +56 -0
- package/src/components/breadcrumb/README.md +53 -0
- package/src/components/breadcrumb/index.js +23 -0
- package/src/components/button/Button.vue +107 -0
- package/src/components/button/ButtonClose.vue +47 -0
- package/src/components/button/README.md +197 -0
- package/src/components/button/index.js +21 -0
- package/src/components/button-group/ButtonGroup.vue +66 -0
- package/src/components/button-group/README.md +72 -0
- package/src/components/button-group/index.js +18 -0
- package/src/components/button-toolbar/ButtonToolbar.vue +29 -0
- package/src/components/button-toolbar/README.md +24 -0
- package/src/components/button-toolbar/index.js +18 -0
- package/src/components/card/Card.vue +57 -0
- package/src/components/card/CardBody.vue +92 -0
- package/src/components/card/CardFooter.vue +61 -0
- package/src/components/card/CardGroup.vue +47 -0
- package/src/components/card/CardHeader.vue +61 -0
- package/src/components/card/CardImg.vue +64 -0
- package/src/components/card/README.md +96 -0
- package/src/components/card/index.js +27 -0
- package/src/components/collapse/Collapse.vue +209 -0
- package/src/components/collapse/README.md +86 -0
- package/src/components/collapse/index.js +17 -0
- package/src/components/container/Col.vue +125 -0
- package/src/components/container/Container.vue +31 -0
- package/src/components/container/README.md +91 -0
- package/src/components/container/Row.vue +64 -0
- package/src/components/container/index.js +21 -0
- package/src/components/datepicker/Datepicker.vue +391 -0
- package/src/components/datepicker/README.md +185 -0
- package/src/components/datepicker/index.js +17 -0
- package/src/components/dropdown/Dropdown.vue +442 -0
- package/src/components/dropdown/DropdownDivider.vue +22 -0
- package/src/components/dropdown/DropdownHeader.vue +29 -0
- package/src/components/dropdown/DropdownItem.vue +25 -0
- package/src/components/dropdown/README.md +177 -0
- package/src/components/dropdown/index.js +23 -0
- package/src/components/embed/Embed.vue +47 -0
- package/src/components/embed/README.md +23 -0
- package/src/components/embed/index.js +17 -0
- package/src/components/form/Form.vue +40 -0
- package/src/components/form/FormFeedback.vue +39 -0
- package/src/components/form/FormInvalidFeedback.vue +39 -0
- package/src/components/form/FormRow.vue +21 -0
- package/src/components/form/FormText.vue +41 -0
- package/src/components/form/FormValidFeedback.vue +39 -0
- package/src/components/form/README.md +84 -0
- package/src/components/form/index.js +29 -0
- package/src/components/form-checkbox/FormCheckbox.vue +200 -0
- package/src/components/form-checkbox/README.md +131 -0
- package/src/components/form-checkbox/index.js +18 -0
- package/src/components/form-input/FormInput.vue +176 -0
- package/src/components/form-input/README.md +110 -0
- package/src/components/form-input/index.js +18 -0
- package/src/components/form-radio/FormRadio.vue +155 -0
- package/src/components/form-radio/README.md +61 -0
- package/src/components/form-radio/index.js +18 -0
- package/src/components/form-select/FormSelect.vue +246 -0
- package/src/components/form-select/README.md +180 -0
- package/src/components/form-select/index.js +18 -0
- package/src/components/form-textarea/FormTextarea.vue +250 -0
- package/src/components/form-textarea/README.md +74 -0
- package/src/components/form-textarea/index.js +18 -0
- package/src/components/image/Image.vue +123 -0
- package/src/components/image/README.md +32 -0
- package/src/components/image/index.js +18 -0
- package/src/components/index.js +63 -0
- package/src/components/input-group/InputGroup.vue +125 -0
- package/src/components/input-group/InputGroupAddon.vue +58 -0
- package/src/components/input-group/InputGroupText.vue +20 -0
- package/src/components/input-group/README.md +188 -0
- package/src/components/input-group/index.js +21 -0
- package/src/components/link/Link.vue +157 -0
- package/src/components/link/README.md +27 -0
- package/src/components/link/create-link-props.js +54 -0
- package/src/components/link/index.js +17 -0
- package/src/components/list-group/ListGroup.vue +30 -0
- package/src/components/list-group/ListGroupItem.vue +90 -0
- package/src/components/list-group/README.md +23 -0
- package/src/components/list-group/index.js +19 -0
- package/src/components/modal/Modal.vue +121 -0
- package/src/components/modal/ModalBody.vue +20 -0
- package/src/components/modal/ModalFooter.vue +21 -0
- package/src/components/modal/ModalHeader.vue +39 -0
- package/src/components/modal/ModalTitle.vue +21 -0
- package/src/components/modal/README.md +74 -0
- package/src/components/modal/index.js +25 -0
- package/src/components/nav/Nav.vue +62 -0
- package/src/components/nav/NavItem.vue +23 -0
- package/src/components/nav/NavText.vue +21 -0
- package/src/components/nav/README.md +94 -0
- package/src/components/nav/index.js +19 -0
- package/src/components/navbar/Navbar.vue +63 -0
- package/src/components/navbar/NavbarBrand.vue +41 -0
- package/src/components/navbar/NavbarNav.vue +38 -0
- package/src/components/navbar/NavbarToggle.vue +55 -0
- package/src/components/navbar/README.md +51 -0
- package/src/components/navbar/index.js +23 -0
- package/src/components/popover/Popover.vue +126 -0
- package/src/components/popover/README.md +73 -0
- package/src/components/popover/index.js +17 -0
- package/src/components/progress/Progress.vue +93 -0
- package/src/components/progress/ProgressBar.vue +123 -0
- package/src/components/progress/README.md +95 -0
- package/src/components/progress/index.js +19 -0
- package/src/components/slider/README.md +120 -0
- package/src/components/slider/Slider.vue +103 -0
- package/src/components/slider/index.js +17 -0
- package/src/components/tabs/README.md +111 -0
- package/src/components/tabs/Tab.vue +132 -0
- package/src/components/tabs/Tabs.vue +290 -0
- package/src/components/tabs/_TabButton.vue +130 -0
- package/src/components/tabs/index.js +19 -0
- package/src/components/tooltip/README.md +70 -0
- package/src/components/tooltip/Tooltip.vue +115 -0
- package/src/components/tooltip/index.js +17 -0
- package/src/directives/index.js +7 -0
- package/src/directives/toggle/index.js +16 -0
- package/src/directives/toggle/toggle.js +45 -0
- package/src/directives/tooltip/README.md +42 -0
- package/src/directives/tooltip/index.js +16 -0
- package/src/directives/tooltip/meta.json +5 -0
- package/src/directives/tooltip/tooltip.js +145 -0
- package/src/index.js +27 -0
- package/src/markdown/getting-started/README.md +80 -0
- package/src/markdown/getting-started/meta.json +4 -0
- package/src/markdown/roadmap/README.md +3 -0
- package/src/markdown/roadmap/meta.json +4 -0
- package/src/mixins/checkbox-radio.mixin.js +73 -0
- package/src/mixins/root-listener.mixin.js +32 -0
- package/src/mixins/tooltip-popover.mixin.js +292 -0
- package/src/scripts/utils.js +18 -0
- package/src/utils/constants.js +191 -0
- package/src/utils/events.js +48 -0
- package/src/utils/index.js +251 -0
- package/src/utils/observer.js +56 -0
- package/src/utils/popover.class.js +91 -0
- package/src/utils/target.js +50 -0
- package/src/utils/tooltip.class.js +60 -0
- package/src/utils/tpmanager.class.js +730 -0
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
/*--------------------------------------------------------------------------
|
|
2
|
+
/* UTILITY FUNCTIONS
|
|
3
|
+
/*--------------------------------------------------------------------------*/
|
|
4
|
+
|
|
5
|
+
// Install a Vue plugin if Vue is available on the window object.
|
|
6
|
+
export function vueUse(VuePlugin) {
|
|
7
|
+
if (typeof window !== 'undefined' && window.Vue) {
|
|
8
|
+
window.Vue.use(VuePlugin)
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Register a component plugin.
|
|
13
|
+
export function registerComponent(Vue, name, definition) {
|
|
14
|
+
Vue._shards_vue_components_ = Vue._shards_vue_components_ || {}
|
|
15
|
+
const loaded = Vue._shards_vue_components_[name]
|
|
16
|
+
|
|
17
|
+
if (!loaded && definition && name) {
|
|
18
|
+
Vue._shards_vue_components_[name] = true
|
|
19
|
+
Vue.component(name, definition)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return loaded
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Register a group of components.
|
|
26
|
+
export function registerComponents(Vue, components) {
|
|
27
|
+
for (let component in components) {
|
|
28
|
+
registerComponent(Vue, component, components[component])
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Register a directive as being loaded. returns true if directive plugin already registered
|
|
33
|
+
export function registerDirective(Vue, name, definition) {
|
|
34
|
+
Vue._shards_vue_directives_ = Vue._shards_vue_directives_ || {}
|
|
35
|
+
const loaded = Vue._shards_vue_directives_[name]
|
|
36
|
+
|
|
37
|
+
if (!loaded && definition && name) {
|
|
38
|
+
Vue._shards_vue_directives_[name] = true
|
|
39
|
+
Vue.directive(name, definition)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return loaded
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Register a group of directives as being loaded.
|
|
46
|
+
export function registerDirectives(Vue, directives) {
|
|
47
|
+
for (let directive in directives) {
|
|
48
|
+
registerDirective(Vue, directive, directives[directive])
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Array check
|
|
53
|
+
if (!Array.isArray) {
|
|
54
|
+
Array.isArray = arg => Object.prototype.toString.call(arg) === '[object Array]'
|
|
55
|
+
}
|
|
56
|
+
export const isArray = Array.isArray;
|
|
57
|
+
|
|
58
|
+
// Element.matches polyfill
|
|
59
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/Element/matches#Polyfill
|
|
60
|
+
if (typeof Element !== 'undefined' && !Element.prototype.matches) {
|
|
61
|
+
Element.prototype.matches =
|
|
62
|
+
Element.prototype.matchesSelector ||
|
|
63
|
+
Element.prototype.mozMatchesSelector ||
|
|
64
|
+
Element.prototype.msMatchesSelector ||
|
|
65
|
+
Element.prototype.oMatchesSelector ||
|
|
66
|
+
Element.prototype.webkitMatchesSelector ||
|
|
67
|
+
function(s) {
|
|
68
|
+
var matches = (this.document || this.ownerDocument).querySelectorAll(s),
|
|
69
|
+
i = matches.length;
|
|
70
|
+
// eslint-disable-next-line
|
|
71
|
+
while (--i >= 0 && matches.item(i) !== this) {}
|
|
72
|
+
return i > -1;
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Converts a value to an array.
|
|
77
|
+
export function convertToArray(value) {
|
|
78
|
+
if (typeof value === 'string') {
|
|
79
|
+
value = value.split(' ')
|
|
80
|
+
}
|
|
81
|
+
return value
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Mocks SVGAnimatedString
|
|
85
|
+
let SVGAnimatedString = function () {}
|
|
86
|
+
if (typeof window !== 'undefined') {
|
|
87
|
+
SVGAnimatedString = window.SVGAnimatedString
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Generates a GUID
|
|
91
|
+
export const guid = () => {
|
|
92
|
+
var lut = [];
|
|
93
|
+
|
|
94
|
+
for (var i = 0; i < 256; i++) {
|
|
95
|
+
lut[i] = (i < 16 ? '0' : '') + (i).toString(16);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
var d0 = Math.random() * 0xffffffff | 0;
|
|
99
|
+
var d1 = Math.random() * 0xffffffff | 0;
|
|
100
|
+
var d2 = Math.random() * 0xffffffff | 0;
|
|
101
|
+
var d3 = Math.random() * 0xffffffff | 0;
|
|
102
|
+
|
|
103
|
+
return lut[d0 & 0xff] + lut[d0 >> 8 & 0xff] + lut[d0 >> 16 & 0xff] + lut[d0 >> 24 & 0xff] + '-' +
|
|
104
|
+
lut[d1 & 0xff] + lut[d1 >> 8 & 0xff] + '-' + lut[d1 >> 16 & 0x0f | 0x40] + lut[d1 >> 24 & 0xff] + '-' +
|
|
105
|
+
lut[d2 & 0x3f | 0x80] + lut[d2 >> 8 & 0xff] + '-' + lut[d2 >> 16 & 0xff] + lut[d2 >> 24 & 0xff] +
|
|
106
|
+
lut[d3 & 0xff] + lut[d3 >> 8 & 0xff] + lut[d3 >> 16 & 0xff] + lut[d3 >> 24 & 0xff];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
/*--------------------------------------------------------------------------
|
|
111
|
+
/* DOM UTILITY FUNCTIONS
|
|
112
|
+
/*--------------------------------------------------------------------------*/
|
|
113
|
+
|
|
114
|
+
// Get an element by id
|
|
115
|
+
export const getById = (id) => {
|
|
116
|
+
return document.getElementById(/^#/.test(id) ? id.slice(1) : id) || null
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Checks whether a variable is a DOM element, or not.
|
|
120
|
+
export const isElement = el => {
|
|
121
|
+
return el && el.nodeType === Node.ELEMENT_NODE
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Checks whether an element has a particular class name, or not.
|
|
125
|
+
export const hasClass = (el, className) => {
|
|
126
|
+
if (className && isElement(el)) {
|
|
127
|
+
return el.classList.contains(className)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return false
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Adds a class to an element
|
|
134
|
+
export const addClass = (el, className) => {
|
|
135
|
+
if (className && isElement(el)) {
|
|
136
|
+
el.classList.add(className)
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Removes a class from an element
|
|
141
|
+
export const removeClass = (el, className) => {
|
|
142
|
+
if (className && isElement(el)) {
|
|
143
|
+
el.classList.remove(className)
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Removes multiple classes
|
|
148
|
+
export function removeClasses(el, classes) {
|
|
149
|
+
const newClasses = convertToArray(classes)
|
|
150
|
+
let classList
|
|
151
|
+
|
|
152
|
+
if (el.className instanceof SVGAnimatedString) {
|
|
153
|
+
classList = convertToArray(el.className.baseVal)
|
|
154
|
+
} else {
|
|
155
|
+
classList = convertToArray(el.className)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
newClasses.forEach((newClass) => {
|
|
159
|
+
const index = classList.indexOf(newClass)
|
|
160
|
+
if (index !== -1) {
|
|
161
|
+
classList.splice(index, 1)
|
|
162
|
+
}
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
if (el instanceof SVGElement) {
|
|
166
|
+
el.setAttribute('class', classList.join(' '))
|
|
167
|
+
} else {
|
|
168
|
+
el.className = classList.join(' ')
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Sets an attribute on an element
|
|
173
|
+
export const setAttr = (el, attr, value) => {
|
|
174
|
+
if (attr && isElement(el)) {
|
|
175
|
+
el.setAttribute(attr, value)
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Removes an attribute from an element
|
|
180
|
+
export const removeAttr = (el, attr) => {
|
|
181
|
+
if (attr && isElement(el)) {
|
|
182
|
+
el.removeAttribute(attr)
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Gets an attribute value from an element
|
|
187
|
+
export const getAttr = (el, attr) => {
|
|
188
|
+
if (attr && isElement(el)) {
|
|
189
|
+
return el.getAttribute(attr)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return null
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// Checks whether an element is disabled, or not.
|
|
196
|
+
export const isDisabled = el => {
|
|
197
|
+
return !isElement(el)
|
|
198
|
+
|| el.disabled
|
|
199
|
+
|| el.classList.contains('disabled')
|
|
200
|
+
|| Boolean(el.getAttribute('disabled'))
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Determines if an HTML element is visible - Faster than CSS check
|
|
204
|
+
export const isVisible = el => {
|
|
205
|
+
return isElement(el)
|
|
206
|
+
&& document.body.contains(el)
|
|
207
|
+
&& el.getBoundingClientRect().height > 0
|
|
208
|
+
&& el.getBoundingClientRect().width > 0
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// Selects an element.
|
|
212
|
+
export const selectElement = (selector, root) => {
|
|
213
|
+
if (!isElement(root)) {
|
|
214
|
+
root = document
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return root.querySelector(selector) || null
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// Finds closest element matching selector.
|
|
221
|
+
export const closest = (selector, root) => {
|
|
222
|
+
if (!isElement(root)) {
|
|
223
|
+
return null
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const Closest = Element.prototype.closest ||
|
|
227
|
+
function (sel) {
|
|
228
|
+
let element = this
|
|
229
|
+
if (!document.documentElement.contains(element)) {
|
|
230
|
+
return null
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
do {
|
|
234
|
+
if (element.matches(sel)) {
|
|
235
|
+
return element
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
element = element.parentElement
|
|
239
|
+
} while (element !== null)
|
|
240
|
+
|
|
241
|
+
return null
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const el = Closest.call(root, selector)
|
|
245
|
+
|
|
246
|
+
return el === root ? null : el
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export const getComputedStyles = el => {
|
|
250
|
+
return isElement(el) ? window.getComputedStyle(el) : {}
|
|
251
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { isElement } from './'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Observes DOM changes.
|
|
5
|
+
* @see http://stackoverflow.com/questions/3219758
|
|
6
|
+
*/
|
|
7
|
+
export default (el, callback, opts = null) => {
|
|
8
|
+
|
|
9
|
+
if (opts === null) {
|
|
10
|
+
opts = {
|
|
11
|
+
subtree: true,
|
|
12
|
+
childList: true,
|
|
13
|
+
characterData: true,
|
|
14
|
+
attributes: true,
|
|
15
|
+
attributeFilter: ['class', 'style']
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver
|
|
20
|
+
const eventListenerSupported = window.addEventListener
|
|
21
|
+
|
|
22
|
+
el = el ? (el.$el || el) : null
|
|
23
|
+
if (!isElement(el)) {
|
|
24
|
+
return null
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let obs = null
|
|
28
|
+
|
|
29
|
+
if (MutationObserver) {
|
|
30
|
+
obs = new MutationObserver(mutations => {
|
|
31
|
+
let changed = false
|
|
32
|
+
for (let i = 0; i < mutations.length && !changed; i++) {
|
|
33
|
+
const mutation = mutations[i]
|
|
34
|
+
const type = mutation.type
|
|
35
|
+
const target = mutation.target
|
|
36
|
+
if (type === 'characterData' && target.nodeType === Node.TEXT_NODE) {
|
|
37
|
+
changed = true
|
|
38
|
+
} else if (type === 'attributes') {
|
|
39
|
+
changed = true
|
|
40
|
+
} else if (type === 'childList' && (mutation.addedNodes.length > 0 || mutation.removedNodes.length > 0)) {
|
|
41
|
+
changed = true
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (changed) {
|
|
45
|
+
callback()
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
obs.observe(el, { ...{ childList: true, subtree: true }, ...opts })
|
|
50
|
+
} else if (eventListenerSupported) {
|
|
51
|
+
el.addEventListener('DOMNodeInserted', callback, false)
|
|
52
|
+
el.addEventListener('DOMNodeRemoved', callback, false)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return obs
|
|
56
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import TPManager from './tpmanager.class'
|
|
2
|
+
import { selectElement, removeClasses } from './index'
|
|
3
|
+
import { POPOVER_SELECTORS, TP_STATE_CLASSES } from './constants'
|
|
4
|
+
|
|
5
|
+
const PopoverDefaults = {
|
|
6
|
+
trigger: 'click',
|
|
7
|
+
content: '',
|
|
8
|
+
template: '<div class="popover" role="tooltip"><div class="arrow"></div><h3 class="popover-header"></h3><div class="popover-body"></div></div>'
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const Defaults = { ...TPManager.Defaults, ...PopoverDefaults }
|
|
12
|
+
|
|
13
|
+
export default class Popover extends TPManager {
|
|
14
|
+
|
|
15
|
+
static get Name () {
|
|
16
|
+
return 'popover'
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
static get Defaults () {
|
|
20
|
+
return Defaults
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static get ClassPrefix () {
|
|
24
|
+
return 'bs-popover'
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/*--------------------------------------------------------------------------
|
|
28
|
+
/* OVERRIDES
|
|
29
|
+
/*--------------------------------------------------------------------------*/
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Checks if the Popover has content.
|
|
33
|
+
* @returns True if the Popover has content (title or body), false otherwise.
|
|
34
|
+
*/
|
|
35
|
+
hasContent(TPElement) {
|
|
36
|
+
const Popover = TPElement || this._TPElement
|
|
37
|
+
|
|
38
|
+
if (!Popover) {
|
|
39
|
+
return false
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const popoverHeaderEl = selectElement(POPOVER_SELECTORS.HEADER, Popover)
|
|
43
|
+
const popoverBodyEl = selectElement(POPOVER_SELECTORS.BODY, Popover)
|
|
44
|
+
const hasHeader = Boolean((popoverHeaderEl || {}).innerHTML)
|
|
45
|
+
const hasBody = Boolean((popoverBodyEl || {}).innerHTML)
|
|
46
|
+
|
|
47
|
+
return hasHeader || hasBody
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Sets the content for the Popover element.
|
|
52
|
+
*/
|
|
53
|
+
setContent(TPElement) {
|
|
54
|
+
const Popover = TPElement || this._TPElement
|
|
55
|
+
|
|
56
|
+
const popoverHeaderEl = selectElement(POPOVER_SELECTORS.HEADER, Popover)
|
|
57
|
+
const popoverBodyEl = selectElement(POPOVER_SELECTORS.BODY, Popover)
|
|
58
|
+
|
|
59
|
+
this.setElementContent( popoverHeaderEl, this.getTitle())
|
|
60
|
+
this.setElementContent( popoverBodyEl, this.getContent())
|
|
61
|
+
|
|
62
|
+
removeClasses(Popover, [TP_STATE_CLASSES.FADE, TP_STATE_CLASSES.SHOW])
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/*--------------------------------------------------------------------------
|
|
66
|
+
/* CLASS SPECIFIC
|
|
67
|
+
/*--------------------------------------------------------------------------*/
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Returns the Popover content.
|
|
71
|
+
*/
|
|
72
|
+
getContent() {
|
|
73
|
+
let content = this._config.content || ''
|
|
74
|
+
|
|
75
|
+
switch (content) {
|
|
76
|
+
case 'string':
|
|
77
|
+
content = content.trim()
|
|
78
|
+
break
|
|
79
|
+
case 'function':
|
|
80
|
+
content = content(this._targetElement)
|
|
81
|
+
break
|
|
82
|
+
case 'object':
|
|
83
|
+
if (content.nodeType && !content.innerHTML.trim()) {
|
|
84
|
+
content = ''
|
|
85
|
+
}
|
|
86
|
+
break
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return content
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const allListenTypes = {
|
|
2
|
+
hover: true,
|
|
3
|
+
click: true,
|
|
4
|
+
focus: true
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const BEL_KEY = '__DR_BOUND_EVENT_LISTENERS__'
|
|
8
|
+
|
|
9
|
+
const bindTargets = (vnode, binding, listenTypes, callback) => {
|
|
10
|
+
const targets = Object.keys(binding.modifiers || {}).filter(t => !allListenTypes[t])
|
|
11
|
+
|
|
12
|
+
if (binding.value) {
|
|
13
|
+
targets.push(binding.value)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const listener = () => {
|
|
17
|
+
callback({ targets, vnode })
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
Object.keys(allListenTypes).forEach(type => {
|
|
21
|
+
if (listenTypes[type] || binding.modifiers[type]) {
|
|
22
|
+
vnode.elm.addEventListener(type, listener)
|
|
23
|
+
const boundListeners = vnode.elm[BEL_KEY] || {}
|
|
24
|
+
boundListeners[type] = boundListeners[type] || []
|
|
25
|
+
boundListeners[type].push(listener)
|
|
26
|
+
vnode.elm[BEL_KEY] = boundListeners
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
return targets
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const unbindTargets = (vnode, binding, listenTypes) => {
|
|
34
|
+
Object.keys(allListenTypes).forEach(type => {
|
|
35
|
+
if (listenTypes[type] || binding.modifiers[type]) {
|
|
36
|
+
const boundListeners = vnode.elm[BEL_KEY] && vnode.elm[BEL_KEY][type]
|
|
37
|
+
if (boundListeners) {
|
|
38
|
+
boundListeners.forEach(listener => vnode.elm.removeEventListener(type, listener))
|
|
39
|
+
delete vnode.elm[BEL_KEY][type]
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export {
|
|
46
|
+
bindTargets,
|
|
47
|
+
unbindTargets
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export default bindTargets
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
|
|
2
|
+
import TPManager from './tpmanager.class'
|
|
3
|
+
import { TP_STATE_CLASSES, TOOLTIP_SELECTORS } from './constants'
|
|
4
|
+
import { removeClasses, selectElement } from './index'
|
|
5
|
+
|
|
6
|
+
const TooltipDefaults = {
|
|
7
|
+
template: '<div class="tooltip" role="tooltip"><div class="arrow"></div><div class="tooltip-inner"></div></div>',
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const Defaults = { ...TPManager.Defaults, ...TooltipDefaults }
|
|
11
|
+
|
|
12
|
+
export default class Tooltip extends TPManager {
|
|
13
|
+
|
|
14
|
+
static get Name() {
|
|
15
|
+
return 'tooltip'
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
static get Defaults() {
|
|
19
|
+
return Defaults
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
static get ClassPrefix() {
|
|
23
|
+
return 'bs-tooltip'
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/*--------------------------------------------------------------------------
|
|
27
|
+
/* OVERRIDES
|
|
28
|
+
/*--------------------------------------------------------------------------*/
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Checks whether the Tooltip has any content.
|
|
32
|
+
*/
|
|
33
|
+
hasContent(TPElement) {
|
|
34
|
+
const Tooltip = TPElement || this._TPElement
|
|
35
|
+
|
|
36
|
+
if (!Tooltip) {
|
|
37
|
+
return false
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const tooltipInnerEl = selectElement(TOOLTIP_SELECTORS.TOOLTIP_INNER, Tooltip)
|
|
41
|
+
|
|
42
|
+
return Boolean((tooltipInnerEl || {}).innerHTML)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Sets the Tooltip content.
|
|
47
|
+
*/
|
|
48
|
+
setContent(TPElement) {
|
|
49
|
+
const Tooltip = TPElement || this._TPElement
|
|
50
|
+
|
|
51
|
+
if (!Tooltip) {
|
|
52
|
+
return false
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const tooltipInnerEl = selectElement(TOOLTIP_SELECTORS.TOOLTIP_INNER, Tooltip)
|
|
56
|
+
this.setElementContent(tooltipInnerEl, this.getTitle())
|
|
57
|
+
|
|
58
|
+
removeClasses(Tooltip, [TP_STATE_CLASSES.FADE, TP_STATE_CLASSES.SHOW])
|
|
59
|
+
}
|
|
60
|
+
}
|