Skip to content

Commit

Permalink
refactor(tour): more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
DaftMonk committed Mar 2, 2014
1 parent 772c574 commit dd7e9be
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/tour/tour.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ angular.module('angular-tour.tour', ['ivpusic.cookie'])

/**
* tourtip
* a single step, tourtip manages the state of the tour-popup directive
* tourtip manages the state of the tour-popup directive
*/
.directive('tourtip', function ($window, $compile, $interpolate, $timeout, scrollTo, tourConfig) {
var startSym = $interpolate.startSymbol(),
Expand Down Expand Up @@ -432,32 +432,33 @@ angular.module('angular-tour.tour', ['ivpusic.cookie'])
* listens for events on the scope to keep cookies synced up
*/
.factory('tourCookieManager', function($rootScope, tourCookieStore, tourConfig) {
var cookieName = tourConfig.cookieName;

$rootScope.$on('tour:tourCancel', function() {
tourCookieStore.put(tourConfig.cookieName + '_closed', true);
tourCookieStore.put(cookieName + '_closed', true);
});

$rootScope.$on('tour:tourComplete', function() {
tourCookieStore.put(tourConfig.cookieName + '_completed', true);
tourCookieStore.put(tourConfig.cookieName + '_closed', true);
tourCookieStore.put(cookieName + '_completed', true);
tourCookieStore.put(cookieName + '_closed', true);
});

$rootScope.$on('tour:tourStart', function(event, stepIndex) {
if(tourCookieStore.get(tourConfig.cookieName + '_completed')) return;
tourCookieStore.put(tourConfig.cookieName + '_completed', false);
tourCookieStore.put(tourConfig.cookieName, stepIndex);
if(tourCookieStore.get(cookieName + '_completed')) return;
tourCookieStore.put(cookieName + '_completed', false);
tourCookieStore.put(cookieName, stepIndex);
});

$rootScope.$on('tour:nextStep', function(event, stepIndex) {
tourCookieStore.put(tourConfig.cookieName, stepIndex);
tourCookieStore.put(cookieName, stepIndex);
});

return {
lastStepIndex: function() {
var wasCompleted = tourCookieStore.get(tourConfig.cookieName + '_completed');
var wasCompleted = tourCookieStore.get(cookieName + '_completed');
if(wasCompleted) return;

var loadedIndex = tourCookieStore.get(tourConfig.cookieName);
var loadedIndex = tourCookieStore.get(cookieName);
if(loadedIndex) {
return loadedIndex;
}
Expand Down

0 comments on commit dd7e9be

Please sign in to comment.