From 2174ad1159852fdb9fb0836a9cd3912e5ca1a7df Mon Sep 17 00:00:00 2001 From: Ilya Date: Mon, 30 Sep 2019 21:57:20 +0300 Subject: [PATCH] feat(plugin): auto-install for CDN usage (script tag) fix #213 --- README.md | 19 +++++++++++++++++++ {public => gh-pages-src/public}/favicon.ico | Bin {public => gh-pages-src/public}/index.html | 0 src/main.js | 17 ++++++++++++++++- 4 files changed, 35 insertions(+), 1 deletion(-) rename {public => gh-pages-src/public}/favicon.ico (100%) rename {public => gh-pages-src/public}/index.html (100%) diff --git a/README.md b/README.md index 1447dbfb..18429f8d 100644 --- a/README.md +++ b/README.md @@ -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' @@ -106,6 +108,23 @@ export default { /> ``` +### Browser (CDN) + +Include v-tooltip in the page. + +```html + + + + + + +``` + +If Vue is detected in the Page, the plugin is installed automatically. + +--- + Documentation and examples [here](https://iliyazelenko.github.io/vue-cool-select). #### TODO diff --git a/public/favicon.ico b/gh-pages-src/public/favicon.ico similarity index 100% rename from public/favicon.ico rename to gh-pages-src/public/favicon.ico diff --git a/public/index.html b/gh-pages-src/public/index.html similarity index 100% rename from public/index.html rename to gh-pages-src/public/index.html diff --git a/src/main.js b/src/main.js index 4cebfa10..21d5fae3 100644 --- a/src/main.js +++ b/src/main.js @@ -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 { @@ -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) +}