Skip to content

Commit ee329fa

Browse files
committed
added path option
1 parent 39b1081 commit ee329fa

File tree

3 files changed

+43
-22
lines changed

3 files changed

+43
-22
lines changed

app/tour_directive.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,15 @@
3232
});
3333

3434
//If there is an options argument passed, just use that instead
35+
//@deprecated use 'options' instead
3536
if (attrs.tourOptions) {
3637
angular.extend(tour, scope.$eval(attrs.tourOptions));
3738
}
3839

40+
if (attrs[TourHelpers.getAttrName('options')]) {
41+
angular.extend(tour, scope.$eval(attrs[TourHelpers.getAttrName('options')]));
42+
}
43+
3944
//Initialize tour
4045
scope.tour = ctrl.init(tour);
4146
scope.tour.refresh = ctrl.refreshTour;

app/tour_helpers.js

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@
8989

9090
var template;
9191

92-
if (attrs.template) {
93-
template = compileTemplate(scope.$eval(attrs.template), scope);
92+
if (attrs[helpers.getAttrName('template')]) {
93+
template = compileTemplate(scope.$eval(attrs[helpers.getAttrName('template')]), scope);
9494
}
9595

96-
if (attrs.templateUrl) {
97-
template = lookupTemplate(attrs.templateUrl, scope);
96+
if (attrs[helpers.getAttrName('templateUrl')]) {
97+
template = lookupTemplate(attrs[helpers.getAttrName('templateUrl')], scope);
9898
}
9999

100100
if (template) {
@@ -114,13 +114,10 @@
114114
helpers.attachEventHandlers = function (scope, attrs, options, events) {
115115

116116
angular.forEach(events, function (eventName) {
117-
if (TourConfig.get('prefixOptions')) {
118-
eventName = TourConfig.get('prefix') + eventName.charAt(0).toUpperCase() + eventName.substr(1);
119-
}
120-
if (attrs[eventName]) {
117+
if (attrs[helpers.getAttrName(eventName)]) {
121118
options[eventName] = function (tour) {
122119
safeApply(scope, function () {
123-
scope.$eval(attrs[eventName]);
120+
scope.$eval(attrs[helpers.getAttrName(eventName)]);
124121
});
125122
};
126123
}
@@ -138,19 +135,30 @@
138135
helpers.attachInterpolatedValues = function (attrs, options, keys) {
139136

140137
angular.forEach(keys, function (key) {
141-
if (TourConfig.get('prefixOptions')) {
142-
key = TourConfig.get('prefix') + key.charAt(0).toUpperCase() + key.substr(1);
143-
}
144-
if (attrs[key]) {
145-
options[key] = stringToBoolean(attrs[key]);
146-
attrs.$observe(key, function (newValue) {
138+
if (attrs[helpers.getAttrName(key)]) {
139+
options[key] = stringToBoolean(attrs[helpers.getAttrName(key)]);
140+
attrs.$observe(helpers.getAttrName(key), function (newValue) {
147141
options[key] = stringToBoolean(newValue);
148142
});
149143
}
150144
});
151145

152146
};
153147

148+
/**
149+
* Returns the attribute name for an option depending on the prefix
150+
*
151+
* @param {string} option - name of option
152+
* @returns {string} potentially prefixed name of option, or just name of option
153+
*/
154+
helpers.getAttrName = function (option) {
155+
if (TourConfig.get('prefixOptions')) {
156+
return TourConfig.prefix + option.charAt(0).toUpperCase() + option.substr(1);
157+
} else {
158+
return option;
159+
}
160+
};
161+
154162
return helpers;
155163

156164
}]);

app/tour_step_directive.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
'use strict';
55

66
function directive() {
7-
return ['TourHelpers', function (TourHelpers) {
7+
return ['TourHelpers', 'TourConfig', function (TourHelpers, TourConfig) {
88

99
return {
1010
restrict: 'EA',
@@ -21,7 +21,7 @@
2121

2222
//Pass interpolated values through
2323
TourHelpers.attachInterpolatedValues(attrs, step, options);
24-
attrs.$observe('order', function (order) {
24+
attrs.$observe(TourHelpers.getAttrName('order'), function (order) {
2525
step.order = !isNaN(order*1) ? order*1 : 0;
2626
ctrl.refreshTour();
2727
});
@@ -35,11 +35,11 @@
3535
//Check whether or not the step should be skipped
3636
function stepIsSkipped() {
3737
var skipped;
38-
if (attrs.skip) {
39-
skipped = scope.$eval(attrs.skip);
38+
if (attrs[TourHelpers.getAttrName('skip')]) {
39+
skipped = scope.$eval(attrs[TourHelpers.getAttrName('skip')]);
4040
}
4141
if (!skipped) {
42-
skipped = element.is(':hidden');
42+
skipped = !!step.path || element.is(':hidden');
4343
}
4444
return skipped;
4545
}
@@ -52,8 +52,16 @@
5252
});
5353

5454
//If there is an options argument passed, just use that instead
55-
if (attrs.options) {
56-
angular.extend(step, scope.$eval(attrs.options));
55+
if (attrs[TourHelpers.getAttrName('options')]) {
56+
angular.extend(step, scope.$eval(attrs[TourHelpers.getAttrName('options')]));
57+
}
58+
59+
//set up redirects
60+
if (attrs[TourHelpers.getAttrName('path')]) {
61+
step.path = document.location.pathname + '#' + scope.$eval(TourHelpers.getAttrName('path'));
62+
}
63+
if (attrs[TourHelpers.getAttrName('abspath')]) {
64+
step.path = scope.$eval(TourHelpers.getAttrName('abspath'));
5765
}
5866

5967
//Add step to tour

0 commit comments

Comments
 (0)