xbsoftware / enjoyhint

MIT License
777 stars 275 forks source link

Triggering custom event through script not working #70

Open vibhu-imaginea opened 7 years ago

vibhu-imaginea commented 7 years ago

I have a series of steps (say 5 steps), last two of which are asynchronous. So, I am giving custom event for last two steps. Now, I am not able to trigger the last two steps manually. Also I am getting the 4th step which should not be triggered until triggered manually. Any idea? The error I get after 4th step is rendered is:

Uncaught TypeError: Cannot read property 'left' of undefined

Here is the sample steps config:

var enjoyhint_script_steps = [{ "click #btn1": "Some Instruction.", "showSkip": showSkip, "showNext": showNext }, { "click [name='btn2']": "Some Instruction", "showSkip": showSkip, "showNext": showNext }, { "click .btn3": "Some Instruction", "showSkip": showSkip, "showNext": showNext }, { "event_type": "custom", "event": "my-custom-event1", "selector": "[name='btn4']", "description": "Some thing here", "showSkip": showSkip, "showNext": showNext }, { "event_type": "custom", "event": "my-custom-event2", "selector": "[name='btn5']", "description": "More instructions", "showSkip": showSkip, "showNext": showNext }];

var enjoyhint_instance = new EnjoyHint({}); enjoyhint_instance.set(enjoyhint_script_steps); enjoyhint_instance.run();

showSkip and showNext are boolean variables set to false.

This is how I am triggering custom events on some event: enjoyhint_instance.trigger('my-custom-event1');

SGE66 commented 6 years ago

Hi,

did you manage to solve this issue ? I'm having the same issue...

jagers commented 6 years ago

Even though the docs say enjoyhint_instance.trigger('custom_event_name'); should work, I'm looking at the source code and it appears that the only values that will do something are trigger('next) and trigger('skip'). So the way I got a "custom" event to work was to set the event to custom and then calling enjoyhint_instance.trigger('next') when appropriate. e.g.

var enjoyhint_script_steps = [
  {
    'custom .new_btn' : 'Waiting for a custom event to trigger'
  }  
];

function iAmReady()
{
  enjoyhint_instance.trigger('next');
}

Hope that helps

phant0mstrife commented 6 years ago

jagers it right about the code only run with 2 case ('next' and 'skip') in trigger event.

I came up with the solutions add custom case to trigger event and run to next step with nextStep() function.

that.trigger = function (event_name) { switch (event_name) { case 'next': nextStep(); break case 'skip': skipAll(); break default : nextStep(); break; } };

Hope this help.

mobilizecloud commented 6 years ago

Still experience this issue. Any way to jump to a specific step based on trigger?

zapper59 commented 6 years ago

I've got custom steps working in this fork: https://github.com/darron1217/enjoyhint.js It's a bit different so be sure to look at the example I put in that README

zapper59 commented 6 years ago

As far as skipping to a specific step give me until tomorrow and I can post the changes I had to make on the project I'm working on. It requires some specific changes to the rerunscript function

Ciampije commented 5 years ago

Any update on skipping to a specific step?

zapper59 commented 5 years ago

My pull request https://github.com/xbsoftware/enjoyhint/pull/103 Has rerunscript(step) working correctly.

Ciampije commented 5 years ago

Awesome thank you. I see it hasn't been merged into xbsoftware/enjoyhint. Is there a repo I can pull to get these latest changes?

zapper59 commented 5 years ago

https://github.com/zapper59/enjoyhint