usablica / intro.js

Lightweight, user-friendly onboarding tour library
http://introjs.com
Other
22.8k stars 2.59k forks source link

Multi instance (the doc seems a bit wrong) #582

Closed ibc closed 3 years ago

ibc commented 8 years ago

Why does the Documentation always refer to introJs().start(), introJs().exit(), etc?

Given that introJs() is a function that returns a IntroJs "instance" I assume that start/exit methods must be called on the specific instance. So If I call introJs().exit() that means that I'm creating a new instance and directly calling exit() on it, isn't it?

So, can I have multiple IntroJs instances at the same time?:

var intro1 = introJs('#elem1');
var intro2 = introJs('#elem2');

intro1.onexit(function() { console.log('intro1 exited'); });
intro2.onexit(function() { console.log('intro2 exited'); });

intro1.start();
intro2.start();

intro1.exit();
intro2.exit()

Would that work? or is this library designed to handle a single "instance"? If so, that's particularly bad for SPA (single page applications) in which I may need different "tours" within different app "steps".

Ericzhiluo commented 8 years ago

+1

nblackburn commented 7 years ago

The library seems a little confused when it comes to this, it is setup in a way that allows for multiple instances to exist but cleans up existing elements on instantiation of those instances effectively meaning only one can exist.

bozdoz commented 7 years ago

The biggest problem on this topic is probably the container selectors. A solution is to save container elements as instance properties:

Instead of just globally selecting 'introjs-tooltipReferenceLayer', for example, it should save it to the instance as this.tooltipReferenceLayer, and then in _exitIntro it can clean up its own reference layer with this.tooltipReferenceLayer.parentNode.removeChild(this.tooltipReferenceLayer) (what fun).

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.