Skip to content

Commit 2174ad1

Browse files
committed
feat(plugin): auto-install for CDN usage (script tag)
fix #213
1 parent 9fff7df commit 2174ad1

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

README.md

+19
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ Write your suggestions, glad to add.
6767

6868
## Get started
6969

70+
### NPM
71+
7072
1. Import this plugin, css (theme) and add plugin via `Vue.use`:
7173
```js
7274
import { CoolSelectPlugin } from 'vue-cool-select'
@@ -106,6 +108,23 @@ export default {
106108
/>
107109
```
108110

111+
### Browser (CDN)
112+
113+
Include v-tooltip in the page.
114+
115+
```html
116+
<script src="https://unpkg.com/vue-cool-select"></script>
117+
118+
<!-- paste the line below only if you need "bootstrap" theme -->
119+
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/themes/bootstrap.css">
120+
<!-- paste the line below only if you need "material-design" theme -->
121+
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/themes/material-design.css">
122+
```
123+
124+
If Vue is detected in the Page, the plugin is installed automatically.
125+
126+
---
127+
109128
Documentation and examples [here](https://iliyazelenko.github.io/vue-cool-select).
110129

111130
#### TODO
File renamed without changes.
File renamed without changes.

src/main.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import mergeDeep from '~/helpers'
2+
import CoolSelect from '~/component.vue'
23

34
export const CoolSelectPlugin = new Singleton()
45
export { default as EventEmitter } from '~/eventEmitter'
56
export { default as component } from '~/component.vue'
6-
export { default as CoolSelect } from '~/component.vue'
77
export { default as VueCoolSelect } from '~/component.vue'
8+
export { CoolSelect }
89

910
function Singleton () {
1011
return {
@@ -22,3 +23,17 @@ function Singleton () {
2223
}
2324
}
2425
}
26+
27+
let GlobalVue = null
28+
29+
if (typeof window !== 'undefined') {
30+
GlobalVue = window.Vue
31+
} else if (typeof global !== 'undefined') {
32+
GlobalVue = global.Vue
33+
}
34+
if (GlobalVue) {
35+
// Automatic installation if Vue has been added to the global scope.
36+
GlobalVue.use(CoolSelectPlugin)
37+
GlobalVue.component('cool-select', CoolSelect)
38+
GlobalVue.component('vue-cool-select', CoolSelect)
39+
}

0 commit comments

Comments
 (0)