Giter VIP home page Giter VIP logo

vue-introjs's Introduction

vue-introjs

intro.js bindings for Vue.

Installation

Add package

yarn add vue-introjs

# or via npm:
npm i vue-introjs

Install plugin

import VueIntro from 'vue-introjs';
Vue.use(VueIntro);

Use CDN version of introJs

Make sure you have installed and attached intro.js scripts and styles to the page. This plugin does not come with intro.js built-in.

The motivation of it is to give the developer more control on intro.js versions.

Use with webpack and vue-cli

Install required dependency:

yarn add intro.js

# or via npm:
npm i intro.js

As this plugin relies on global introJs variable, webpack should provide it:

// webpack.config.js
{
    plugins: [
        new webpack.ProvidePlugin({
            // other modules
            introJs: ['intro.js']
        })
    ]
}

// attach CSS
// SomeComponent.vue
import 'intro.js/introjs.css';

If you are using vue-cli this can be done with the following lines in your vue.config.js:

// vue.config.js
const webpack = require('webpack');

module.exports = {
  configureWebpack: {
    plugins: [
      new webpack.ProvidePlugin({
        'introJs': ['intro.js']
      })
    ]
  },
}

Use with vue-cli and webpack template

Add to your src/main.js something like this for global, or per SFC like above:

import VueIntro from 'vue-introjs'
Vue.use(VueIntro)

import 'intro.js/introjs.css';

then add into the plugins sections of build/webpack.dev.conf.js and build/webpack.prod.conf.js the new webpack.ProvidePlugin({ section from above.

Don't forget to install intro.js though and save it (via yarn or npm). The webpack.ProvidePlugin will pull it in, so no need to import introJs from 'intro.js' in src/main.js

Use with NuxtJs

Make sure you install vue-introjs and intro.js then create a Nuxt plugin in /plugins

//plugins/vue-introjs.js`
import Vue from 'vue'
import VueIntro from 'vue-introjs'
import 'intro.js/introjs.css'

Vue.use(VueIntro)

then add it to your nuxt.config.js list of plugins

//nuxt.config.js`
plugins: [
    // ..
    { src: '~plugins/vue-introjs.js', mode: 'client' },
]

Finally register introjs by adding it as a webpack plugin and you're set

//nuxt.config.js
import webpack from 'webpack'

export default {
    build: {
        // ..
        plugins: [
            new webpack.ProvidePlugin({
                introJs: ['intro.js'],
            }),
        ],
    }
}

Contents

The plugin extends Vue with a set of directives and $intro() constructor function.

Define steps and hints

Directives, to define introductional steps:

Steps

The tooltip text of step.
<div v-intro="'The content of tooltip'"></div>
Optionally define the number (priority) of step.
<div v-intro="'The content of tooltip'" v-intro-step="2"></div>
Optionally define a CSS class for tooltip.
<div v-intro="'The content of tooltip'" v-intro-tooltip-class="'red-bg'"></div>
Optionally append a CSS class to the helperLayer.
<div v-intro="'The content of tooltip'" v-intro-highlight-class="'blue-bg'"></div>
Optionally define the position of tooltip, `top`, `left`, `right`, `bottom`, `bottom-left-aligned` (same as `bottom`), `bottom-middle-aligned`, `bottom-right-aligned` or `auto` (to detect the position of element and assign the correct position automatically). Default is `bottom`.
<div v-intro="'The content of tooltip'" v-intro-position="'top'"></div>
Optionally define the element to scroll to, `element` or `tooltip`. Default is `element`.
<div v-intro="'The content of tooltip'" v-intro-scroll-to="'element'"></div>
To disable interactions with elements inside the highlighted box, `true` or `false` (also `1` or `0`).
<div v-intro="'The content of tooltip'" v-intro-disable-interaction="false"></div>

More about intro steps

Hints

Directives, to define hints:

The tooltip text of hint.
<div v-intro-hint="'The content of tooltip'"></div>
Optionally define the position of hint. Options: `top-middle`, `top-left`, `top-right`, `bottom-left`, `bottom-right`, `bottom-middle`, `middle-left`, `middle-right`, `middle-middle`. Default: `top-middle`.
<div v-intro-hint="'The content of tooltip'" v-intro-position="'top'"></div>

More about hints

Also refer example directory for live examples.

Usage

Once all steps are defined, call start() or showHints() to start the show:

// SomeComponent.vue
{
    mounted() {
        this.$intro().start(); // start the guide
        this.$intro().showHints(); // show hints
    }
}

Configuration

When the defaults are not enough, then fine tuning is required. Construct a new introJs instance and configure in own way:

this.$intro('#intro-farm'); // //start introduction for element id='intro-farm'
this.$intro().addStep({}); // Add a new step to introJs programmatically.

Basically, $intro() returns a new introJs instance which then can be configured usign it's API.

Registering callbacks

Just call this.$intro().<callback-name>. Example:

// SomeComponent
this.$intro().oncomplete(function () {
    console.log('completed');
});

Autostart

If tour should start automatically when all directives loaded, add v-intro-autostart="true" directive. Also extra configuration required for plugin:

import VueIntro from 'intro.js';
Vue.use(VueIntro, {
    waitTimeout: 400
});

For hints use v-intro-autostart:hints="true".

How it works

The plugin starts a timer with waitTimeout. Every v-intro directive restarts that timer. This lets the plugin to wait for async components, router views or other components to load before tour will be autostarted.

Configure intro.js instance

Add v-intro-autostart.config next to v-intro-autostart with intro.js configuration object as an argument. That object then passed to introJs(obj) constructor.

<div v-intro-autostart="true" v-intro-autostart.config="{ doneLabel: 'DONE!' }"></div>

Listening for intro.js events

It is possible to add event listeners to automatically started tour. The format is:

v-intro-autostart:on.<event-name>="<callback>"

where event-name is any of intro.js supported hooks (see intro.js hooks) for more details. Same applies to hints.

Note, the plugin defines two more events, designed to work with the autostart feature: onautostart and onautostarthints. These callbacks receive two arguments: element and current introjs instance.

For example:

<div v-intro-autostart="true" v-intro-autostart:on.complete="onComplete"></div>
<div v-intro-autostart="true" v-intro-autostart:on.autostart="onAutostarted"></div>

Conditional steps and hints

When it is required to bind intro only when some expression evaluates to true, use v-intro-if directive. It accepts any valid expression that evaluates to either true or false:

<div v-intro="'Conditional step'" v-intro-if="item.id == 1" v-for="item in items" :key="item.id"></div>

Note, that v-intro-if directive must go after v-intro.

Credits

  1. http://introjs.com
  2. Gabriel J Perez Irizarry

vue-introjs's People

Contributors

alex-oleshkevich avatar dependabot[bot] avatar ghenry avatar mbackonja avatar orlandster avatar seyidayo avatar shaun-sweet avatar txantslusam avatar white-gecko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vue-introjs's Issues

build error

ERROR in static/js/vendor.d59fade80353c4f96b45.js from UglifyJs
Unexpected token: punc (() [./node_modules/_vue-introjs@1.1.1@vue-introjs/src/index.js:10,0][static/js/vendor.d59fade80353c4f96b45.js:2710,11]

Build failed with errors.

and
npm run dev is good

add update hook to vue-intro directive

Hi, i have a child component that receive a computed string to be displayed in the second step of my intro and only the default value is bound.
It would be nice if the value passed to v-intro could be updated.

introjs triggers tour on completely different view

Notice a really odd behaviour, follows this pattern:

  1. IntroJS runs the tour once my component has dynamically rendered
  2. If I press back, and go to the homepage and enter a search again it will run the tour directly on the homepage view
    image
    you can see that in localstorage first_tour is set to true which means the tour has already ran, so it should not be running at all.

Also, note how it has no elements to bind to on the homepage so it just attaches itself to the top left corner of the page, and for some reason starts on the second step.

For some reason, this is what I see when I inspect the element ... it appears to be binding to the CDN code in my index.html file, not sure if this is relevant:
image

Basic outline of my code:

watch: {
    myVar: { 
        handler: function(){
            /* only start the tour once the actual elements have finished dynamically loading in the DOM */
            /* otherwise, introJS does not have any elements to actually bind to, or gets the positions wrong */
            this.$nextTick(() => {    
                if (this.results.hits.length > 0 && !this.loggedIn && !first_tour){
                    /* dynamically load my steps */
                    this.$intro().addSteps(
                        [
                            {
                                intro: "Step 1",
                                element: this.$refs.step_1,
                                position: "right",
                                disableInteraction: true // don't let the user click inside of the highlighted element
                            },
                            {
                                intro: "Step 2",
                                element: this.$refs.step_2,
                                position: "left",
                                disableInteraction: true
                            },
                            {
                                intro: "Step 3",
                                element: this.$refs.step_3_parent.$refs.step3_child_element,
                                position: "right",
                                disableInteraction: true
                            }
                        ]
                    )
                    .setOptions({
                        exitOnOverlayClick: false, // don't let the user click "out" of the tour to exit
                        overlayOpacity: 0.5 // changed to 0.5 felt it was too dark by default
                    })
                    .start() // start the tour
                    .oncomplete(function () { // callback tour completion
                        console.log("done");
                    })
                    .onexit(function () {
                        console.log("exited"); // callback tour exit
                    });
                }
            });
        },
        deep: true,
        immediate: false // don't load the tour right away
    }

what can I do about this? Note how my code clearly specifies only create the tour if the user is not logged in or has not done the tour before (as per record in local storage).

Is there any work around to just disable the tour so that it doesn't run on other pages? I can't tell if it's loading on the homepage or just loading prematurely when its going to the next page ... still shouldn't be acting this way.

I've tried lots of things including removing steps from the introJS instance upon exit or completion, I've tried setting display:none to introJS classes on the homepage, I've tried setting introJS to null, I've also tried triggering alerts throughout the introJS instantiation but for whatever reason, this unexpected behaviour won't go away.

This unexpected behaviour appears once in a while on Chrome but occurs frequently on Safari.

Any ideas would be greatly appreciated.

vue-cli import error

vue-cli import VueIntro from 'vue-introJs'; Vue.use(VueIntro);
// error Uncaught SyntaxError: Unexpected token ( autostart.js?9e2a:29

Not working on IE 11

Vue introjs is not working correctly on IE 11. So it causes my site to display white screen. Is there any polyfills I need to add to make it work on IE/Safari?

image

current examples are not working

Current examples are not working and integration instruction in README.md file is also not clear. Please add some nice integration document.

options hideNext not work

this.intro = this.$intro();
this.intro.setOptions({
hideNext: true, // <-- not work, still shows the next button
hidePrev: true,
prevLabel: '上一步',
nextLabel: '下一步',
doneLabel: '完成',
showProgress: true,
showBullets: false,
exitOnOverlayClick: false,
// showButtons: false,
steps: [
{
intro: '点击按钮',
element: document.querySelector('.list-step0'),
},
{}
],
});
this.intro.start();

options is like above, but the next button is still visible.

Error in mounted hook: "ReferenceError: introJs is not defined"

I'm using electron-vue, which uses vue-cli + webpack.

I've added this in src/main.js:

import VueIntro from 'vue-introjs'
Vue.use(VueIntro)

then added the plugin in webpack.renderer.config.js and `webpack.main.config.js:

plugins: [
     [...]
     new webpack.ProvidePlugin({
        introJs: ['intro.js', 'introJs']
    })
],

Then when I use the intro directives in a component, I get the error: Error in mounted hook: "ReferenceError: introJs is not defined"

Both intro.js and vue-introjs have been installed via NPM

Any ideas?

webpack issues

> webpack-dev-server --inline --progress --config build/webpack.dev.conf.js

 95% emitting                                                                           

 WARNING  Compiled with 1 warnings                                                                                                                                                3:26:06 PM

 warning  in ./node_modules/intro.js/introjs.css

(Emitted value instead of an instance of Error) autoprefixer: /home/ghenry/src/SureVoIP-Portal/root/src/client_side/node_modules/intro.js/introjs.css:12:3: Gradient has outdated direction syntax. Replace `cover` to `farthest-corner`.

 @ ./node_modules/intro.js/introjs.css 4:14-114 13:3-17:5 14:22-122
 @ ./src/main.js
 @ multi (webpack)-dev-server/client?http://localhost:8081 webpack/hot/dev-server ./src/main.js

I need attribute like exitOnOverlayClick to forbid click mask exit those step

It's there any events or attribute that I can use to forbid exit steps when I click the background mask, thanks.I compared with Options Props of intro.js and find it has props named exitOnOverlayClick. Thank you for you plugin that I don't want to use intro.js in vue project.Moreover, your work totally help me shorten my time in programming new tour function.

how to hear the callback onComplete in vue?

how to hear the callback onComplete in vue? would it be with watch? I need when I click the done button, it shows me that it is complete, but where is it in the vue? I'm kind of lost.

Unable to listen to any of the events

My intro of app is working correctly but I am unable to listen to events.

In mounted of main App.js I have this code:


mounted: {

	this.$intro().onbeforechange(function (targetElement) {
	    console.log("before new step"); // no output
	    console.log(targetElement); // no output
	});

	this.$intro().onchange(function (targetElement) {
	    console.log("new step"); // no output
	});

	console.log('Post intro start', this.$intro()); // this prints some instance variables
}

Feature request: Optional auto start hook

Would be great to be able to provide a function to an auto started tour that takes an introjs instance as a parameter. That would open up the use of the whole intro.js API on auto started tours. The function could be provided a Component method.

Bug report: Auto start fails on second use

I start one tour on the first landing page after login. Then after that tour is over, I send the user to another page using vue-router. The tour on that second page is not started using auto start. However, if I do a refresh on that second page, the auto-tour starts as expected.

v-intro-autostart.config not working

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/intro.js/2.7.0/introjs.min.css" rel="stylesheet">
    <style type="text/css">
        .red-bg {
            background: red;
        }
        
        .blue-bg {
            background: blue;
        }
    </style>
</head>

<body>
    <div class="container" id="root">
        <br />
        <div>
            <button class="btn btn-primary" @click="startTour">Start tour</button>
        </div>
        <br />
        <div v-intro-autostart="autostart" v-intro-autostart.config="{ doneLabel: 'over!' }">>
            <h3 v-intro="'Step 1, default'">Intro step 1</h3>
            <div>
                Step 1, use of v-intro="'Message'".
            </div>
            <hr />

            <h3 v-intro="'Step 2, custom position'" v-intro-position="'top'">Intro step 2 (position "top")</h3>
            <div>
                Step 2, use of v-intro-position="'top'". <br /> Renders tooltip on the top of this element.
            </div>
            <hr />

            <h3 v-intro="'Step 3, custom priority'" v-intro-step="2">Intro step 3 (set priority)</h3>
            <div>
                Step 3, use of v-intro-step="2". <br /> This step defines step priority = 2, so intro for step #3 is rendered before step #2.
            </div>
            <hr />

            <h3 v-intro="'Step 4, tooltip class'" v-intro-tooltip-class="'red-bg'">Intro step 4 (tooltip class)</h3>
            <div>
                Step 4, use of v-intro-tooltip-class="'red-bg'". <br /> Custom CSS class for tooltip.
            </div>
            <hr />

            <h3 v-intro="'Step 5, highlight class'" v-intro-highlight-class="'blue-bg'">Intro step 5 (highlight class)</h3>
            <div>
                Step 5, use of v-highlight-tooltip-class="'blue-bg'". <br /> Custom CSS class for helper layer.
            </div>
            <hr />

            <h3 v-intro="'Step 6, scroll to'" v-intro-scroll-to="'element'">Intro step 6 (change scrollTo attribute)</h3>
            <div>
                Step 6, use of v-scroll-to="'element'". <br />
            </div>
            <hr />

            <h3 v-intro="'Step 7, disable-interaction'" v-intro-disable-interaction="true">Intro step 7 (change disable-interaction attribute)</h3>
            <div>
                Step 7, use of v-disable-interaction="true". <br />
            </div>
            <hr />

            <h3 v-intro-hint="'The hint'">A hint</h3>
            <div>
                Renders a hint
            </div>
            <hr />

            <h3 v-intro-hint="'The hint'" v-intro-hint-position="'top'">A hint (position = top)</h3>
            <div>
                Renders a hint on top of elemenet.
            </div>
            <hr />
        </div>

        <div>
            <button class="btn btn-primary" @click="showHints">Show hints</button>
        </div>
    </div>
    <script src="https://unpkg.com/[email protected]/dist/vue.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/intro.js/2.7.0/intro.min.js"></script>
    <script type="text/javascript" src="../node_modules/vue-introjs/dist/index.min.js"></script>
    <script type="text/javascript">
        new Vue({
            el: '#root',
            data() {
                return {
                    autostart: false,

                };
            },
            methods: {
                startTour() {
                    this.$intro().start();
                },
                showHints() {
                    this.$intro().showHints();
                },
                toggleAutostart() {
                    this.autostart = !this.autostart;
                }
            }
        });
    </script>
</body>

</html>

it is still display "Done" not replace......

import VueIntro from 'intro.js' or import VueIntro from 'vue-introjs'

Hi,

In the readme you have both:


import VueIntro from 'intro.js'; 

import VueIntro from 'vue-introjs';

I am seeing:

[Vue warn]: Error in mounted hook: "ReferenceError: intro is not defined"

after adding this to my webpack.dev.conf.js

  plugins: [
    new webpack.DefinePlugin({
      'process.env': require('../config/dev.env'),
       introJs: ['intro.js', 'introJs']
    }),

This dependency was not found

Suddenly, I started to get this error on starting my project. Earlier (few days ago) everything was fine.

This dependency was not found:

  • vue-introjs in ./src/main.js
    To install it, you can run: npm install --save vue-introjs

My current version of the package is: "vue-introjs": "^1.1.2"
Even if I execute npm install --save vue-introjs and update the package to version 1.3.1, it doesn't help.

hints don't work at all

  1. Adding hints by using v-intro-hint:
<div v-intro-hint="'tooltip text'">
  ...
</div>
mounted() {
  this.$intro().addHints()
  this.$intro().showHints()
}

In the inspector i can see that v-intro-hint has been transpiled to data-hint but nothing else happens.

  1. Adding hints programmatically:
<div id="hint-0">
  ...
</div>
mounted() {
  const hints = [
    {
      hint: 'tooltip text',
      element: document.querySelector('#hint-0')
    }
  ]
  this.$intro.setOptions({hints})
  this.$intro().addHints()
  this.$intro().showHints()
}

In the inspector i can't even see that v-intro-hint has been transpiled to data-hint.
Then i tried:

mounted() {
  ...
  this.$intro().showHintDialog(0)
}

i got an error: item is undefined
So just in case i tried as well:

mounted() {
  ...
  console.log(document.querySelector('#hint-0'))
  setTimeout(() => {
    this.$intro().showHintDialog(0)
  }, 1000)
}

console.log() prints <div id="hint-0>..
introjs outputs error item is undefined.

Adding steps with .addSteps

Perhaps I'm missing something obvious, but I can't seem to get this plugin to work using the this.$intro().addSteps(steps) method. I can get it to work just fine only using the v-intro directives, but I wanted to source my steps from Vuex so that there was one central spot for step information and then I could import it into whichever components needed it and then just add id to elements.

I have an array in Vuex that looks like this:

steps: [
  {
    element: '#step1',
    intro: 'Click events to get started',
  },
  {
    element: '#step2',
    intro: `Search for your Organization's region by Zip or City`,
  },
],

And I have corresponding ids set on a pair of divs in a component. I then import the steps from Vuex. I checked that they came through with console log. In the mounted() lifecycle hook I have a pair of lines that I think should have kicked off the tour:

this.$intro().addSteps(this.steps)
this.$intro().start()

Nothing happens when I load that page and there are no errors in the console. Any ideas on what to do?

ie9 support

intro.js

if (el.dataset) {
el.dataset.intro = binding.value;
}else{
el.setAttribute("data-intro", binding.value);
}

autostart doesn't work with vue-router

I'm using 'autostart' with vue-router, but intro doesn't show after router changes, I have to refresh the whole page to show it.
I've set the 'waitTimeout' value, but it doesn't work.
vue-introjs version: 1.3.0
intro.js version: 2.9.3

CSS directive for helperNumberLayer

Is there a default directive to append a CSS class to the numbering layer?

Requirement
Add a default CSS customization directive for introjs-helperNumberLayer (v-intro-number-class).

Similar to..

Optionally append a CSS class to the helperLayer.
<div v-intro="'The content of tooltip'" v-intro-highlight-class="'blue-bg'"></div>

Nested Components

Has anyone been able to get the plugin to load steps on nested components or components which dynamically render? I have only been able to get the tour to run on parent component steps.

Not sure where I'm going wrong.

UglifyJS issues

Hi!

I got stuck into issues when trying to minify VueIntroJs. My solution was to point to the dist file, instead of the package.json main value, "src/index.js":

	resolve: {
		alias: {
			'vue-introjs': 'vue-introjs/dist/index.min.js',

Thank you!

window is not defined - nuxt

This throws an error while using with nuxt.js. Since nuxt doesn't use webpack explicitly there is no way to define it the same way.

I'm trying to declare vue-introjs as a plugins in vuex.

IE11 / Edge bug

Using the lastest version of Vue, IE11/Edge throws a polyfill event-souce missing.

Question: onComplete

Hello, thank you so nice plugin. it really great plugin
I tired to read your document it seem likes I did not see any mention use on onComplete in methods

thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.