Skip to content

Commit

Permalink
feat(plugin): auto-install for CDN usage (script tag)
Browse files Browse the repository at this point in the history
fix #213
  • Loading branch information
iliyaZelenko committed Sep 30, 2019
1 parent 9fff7df commit 2174ad1
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ Write your suggestions, glad to add.

## Get started

### NPM

1. Import this plugin, css (theme) and add plugin via `Vue.use`:
```js
import { CoolSelectPlugin } from 'vue-cool-select'
Expand Down Expand Up @@ -106,6 +108,23 @@ export default {
/>
```

### Browser (CDN)

Include v-tooltip in the page.

```html
<script src="https://unpkg.com/vue-cool-select"></script>

<!-- paste the line below only if you need "bootstrap" theme -->
<link rel="stylesheet" href="https://unpkg.com/vue-cool-select@3.0.2/dist/themes/bootstrap.css">
<!-- paste the line below only if you need "material-design" theme -->
<link rel="stylesheet" href="https://unpkg.com/vue-cool-select@3.0.2/dist/themes/material-design.css">
```

If Vue is detected in the Page, the plugin is installed automatically.

---

Documentation and examples [here](https://iliyazelenko.github.io/vue-cool-select).

#### TODO
Expand Down
File renamed without changes.
File renamed without changes.
17 changes: 16 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import mergeDeep from '~/helpers'
import CoolSelect from '~/component.vue'

export const CoolSelectPlugin = new Singleton()
export { default as EventEmitter } from '~/eventEmitter'
export { default as component } from '~/component.vue'
export { default as CoolSelect } from '~/component.vue'
export { default as VueCoolSelect } from '~/component.vue'
export { CoolSelect }

function Singleton () {
return {
Expand All @@ -22,3 +23,17 @@ function Singleton () {
}
}
}

let GlobalVue = null

if (typeof window !== 'undefined') {
GlobalVue = window.Vue
} else if (typeof global !== 'undefined') {
GlobalVue = global.Vue
}
if (GlobalVue) {
// Automatic installation if Vue has been added to the global scope.
GlobalVue.use(CoolSelectPlugin)
GlobalVue.component('cool-select', CoolSelect)
GlobalVue.component('vue-cool-select', CoolSelect)
}

0 comments on commit 2174ad1

Please sign in to comment.