DaftMonk / angular-tour

AngularJS directive for giving an interactive tour of your website.
http://daftmonk.github.io/angular-tour/
MIT License
609 stars 137 forks source link

Use ngCookies #4

Closed timelf123 closed 10 years ago

timelf123 commented 10 years ago

First of all, thanks for the work put into this. Can't wait to get it up and running on a few sites!

Is it possible to use ngCookies instead of jQuery cookies?

DaftMonk commented 10 years ago

Yes, I actually have made some changes to this to do just that, as well as clean up the code so cookies are more optional.

I say more optional because I haven't figured out a way to have an optional dependency in a module with angularJS, so even if you disable cookies you still will need a angular-cookie script somewhere in your app. But I would like there to be a viable alternative to using the tour with cookies.

I'll push that a little later today, I want to go over it a bit first and see if it needs any more tests.

Edit: Oh I see you said ngCookies. Actually what I was talking about was using angular-cookie, https://github.com/ivpusic/angular-cookie. ngCookie unfortunately doesn't let you set the cookies expiration date, which makes it useless for this purpose :(

timelf123 commented 10 years ago

Ohh didn't realize that ngCookies doesn't let you set things like that - how pointless.

As far as an optional dependency, what about something like this:

try {
    cookie.function(args);
} catch (e) {
    if (!(e instanceof ReferenceError)) {
        throw e;
    }
}

Basically if cookie.function is not available because of a ReferenceError, nothing will be thrown.

DaftMonk commented 10 years ago

The problem is with the angular module system though. To be able to inject the cookie service into my services I need to register the cookie module with angular, e.g.

angular.module('angular-tour', ['cookieModule']);

If the cookie module isn't included in the app, angular will throw an error that I don't think I can catch.

timelf123 commented 10 years ago

ahh. missed the point there. i'm not sure how to overcome that. thanks for the continued work on angular-tour! looking forward to seeing your latest work

DaftMonk commented 10 years ago

I've thought about this a little more and I'd love to get your feedback on this.

I'm thinking about just removing cookies altogether from the tour, and have a tour directive just keep track of the currentStep. If the current step is greater than the number of steps in the tour, it is assumed to be completed.

This would solve a lot of the problems with flexibility, as you can use whatever storage method you want to save the currentStep, and load the tour from that.

DaftMonk commented 10 years ago

Sorry I won't be able to get this up today. Since I've changed my approach its going to take longer than I thought to have something working. I'll try to push a working version tomorrow though :)

timelf123 commented 10 years ago

No problem! I like the idea of getting rid of cookies - a flexible storage adapter opens up lots of possibilities

dv336699 commented 10 years ago

@DaftMonk I'm with you. It's up to the developer to use ngCookies, angular-cookie, web storage or whatever.

Thanks for the great tool.

DaftMonk commented 10 years ago

Finally got the chance to release the version with the changes I talked about. Take a look at the updated demo/readme for example usage. Let me know how it works :)