";
$(step.element).popover('destroy'); // destroy existing hover popovers so we can add our own
step.onShow = function(){
// step.path doesn't work in Angular do to async ui-router. Our custom solution:
if (step.state && !$state.is(step.state)) {
// $state.go() returns a promise, necessary for async tour steps; however, that's not working here - have to use timeout instead :/
$state.go(step.state);
return $timeout(function(){});
}
}
step.onHide = function(){
if (step.final) { // -1 indicates complete
var ups={};ups['flags.tour.'+k] = -1;
User.set(ups);
}
}
})
})
var tour = {};
_.each(chapters, function(v,k){
tour[k] = new Tour({
backdrop: true,
template: function(i,step){
return '
' + (true ? ' ' : '') +'
';
// FIXME: see https://github.com/HabitRPG/habitrpg/issues/4726
//return '
' + (step.final ? ' ' : '') +'
';
},
storage: false,
//onEnd: function(){
// User.set({'flags.showTour': false});
//}
});
});
var goto = function(chapter, page, force) {
var curr = User.user.flags.tour[chapter];
if ((page != curr+1 || curr > page) && !force) return;
var updates = {};updates['flags.tour.'+chapter] = page;
User.set(updates);
var end = tour[chapter]._options.steps.length;
tour[chapter].addSteps(chapters[chapter][page]);
tour[chapter].restart(); // Tour doesn't quite mesh with our handling of flags.showTour, just restart it on page load
tour[chapter].goTo(end);
}
//Init and show the welcome tour (only after user is pulled from server & wrapped).
var watcher = $rootScope.$watch('User.user.ops.update', function(updateFn){
if (!updateFn) return; // only run after user has been wrapped
watcher(); // deregister watcher
if (window.env.IS_MOBILE) return; // Don't show tour immediately on mobile devices
goto('intro', User.user.flags.tour.intro, true);
var alreadyShown = function(before, after) { return !(!before && after === true) };
//$rootScope.$watch('user.flags.dropsEnabled', _.flow(alreadyShown, function(already) { //FIXME requires lodash@~3.2.0
$rootScope.$watch('user.flags.dropsEnabled', function(after, before) {
if (alreadyShown(before,after)) return;
var eggs = User.user.items.eggs || {};
if (!eggs) eggs['Wolf'] = 1; // This is also set on the server
$rootScope.openModal('dropsEnabled');
});
$rootScope.$watch('user.flags.rebirthEnabled', function(after, before) {
if (alreadyShown(before, after)) return;
$rootScope.openModal('rebirthEnabled');
});
});
return {
goto: goto
};
}]);