|
57 | 57 | * @param {$rootScope.Scope} scope
|
58 | 58 | * @returns {Function}
|
59 | 59 | */
|
60 |
| - function lookupTemplate(templateUrl, scope) { |
| 60 | + function lookupTemplate(templateUrl, scope) { |
61 | 61 |
|
62 | 62 | var template = $templateCache.get(templateUrl);
|
63 | 63 |
|
|
74 | 74 | *
|
75 | 75 | * @param {$rootScope.Scope} scope
|
76 | 76 | * @param {Attributes} attrs
|
77 |
| - * @param {Object} options |
| 77 | + * @param {Object} options represents the tour or step object |
78 | 78 | */
|
79 | 79 | helpers.attachTemplate = function (scope, attrs, options) {
|
80 | 80 |
|
|
99 | 99 | *
|
100 | 100 | * @param {$rootScope.Scope} scope
|
101 | 101 | * @param {Attributes} attrs
|
102 |
| - * @param {Object} options |
| 102 | + * @param {Object} options represents the tour or step object |
103 | 103 | * @param {Array} events
|
104 | 104 | */
|
105 | 105 | helpers.attachEventHandlers = function (scope, attrs, options, events) {
|
|
116 | 116 |
|
117 | 117 | };
|
118 | 118 |
|
| 119 | + /** |
| 120 | + * Helper function that attaches observers to option attributes |
| 121 | + * |
| 122 | + * @param {Attributes} attrs |
| 123 | + * @param {Object} options represents the tour or step object |
| 124 | + * @param {Array} keys attribute names |
| 125 | + */ |
| 126 | + helpers.attachInterpolatedValues = function (attrs, options, keys) { |
| 127 | + |
| 128 | + angular.forEach(keys, function (key) { |
| 129 | + if (attrs[key]) { |
| 130 | + attrs.$observe(key, function (newValue) { |
| 131 | + options[key] = newValue; |
| 132 | + }); |
| 133 | + } |
| 134 | + }); |
| 135 | + |
| 136 | + }; |
| 137 | + |
119 | 138 | return helpers;
|
120 | 139 |
|
121 | 140 | }]);
|
|
146 | 165 | /**
|
147 | 166 | * As steps are linked, add them to the tour options
|
148 | 167 | */
|
149 |
| - function refreshTour() { |
| 168 | + self.refreshTour = function () { |
150 | 169 | if (tour) {
|
151 | 170 | tour._options.steps = [];
|
152 | 171 | tour.addSteps(orderSteps(steps));
|
153 | 172 | }
|
154 |
| - } |
| 173 | + }; |
155 | 174 |
|
156 | 175 | /**
|
157 | 176 | * Adds a step to the tour
|
|
164 | 183 | }
|
165 | 184 |
|
166 | 185 | steps.push(step);
|
167 |
| - refreshTour(); |
| 186 | + self.refreshTour(); |
168 | 187 | };
|
169 | 188 |
|
170 | 189 | /**
|
|
178 | 197 | }
|
179 | 198 |
|
180 | 199 | steps.splice(steps.indexOf(step), 1);
|
181 |
| - refreshTour(); |
| 200 | + self.refreshTour(); |
182 | 201 | };
|
183 | 202 |
|
184 | 203 | /**
|
|
214 | 233 | link: function (scope, element, attrs, ctrl) {
|
215 | 234 |
|
216 | 235 | //Pass static options through or use defaults
|
217 |
| - var options = { |
218 |
| - name: attrs.name || 'tour', |
219 |
| - container: attrs.container || 'body', |
220 |
| - keyboard: attrs.keyboard || true, |
221 |
| - storage: attrs.storage ? scope.$eval(attrs.storage) : window.localStorage, |
222 |
| - debug: attrs.debug || false, |
223 |
| - redirect: attrs.redirect || true, |
224 |
| - duration: attrs.duration || false, |
225 |
| - basePath: attrs.basePath || '', |
226 |
| - placement: attrs.placement || 'right', |
227 |
| - backdrop: attrs.backdrop || false, |
228 |
| - orphan: attrs.orphan || false |
229 |
| - }, |
230 |
| - events = 'onStart onEnd afterGetState afterSetState afterRemoveState onShow onShown onHide onHidden onNext onPrev onPause onResume'.split(' '); |
| 236 | + var tour = {}, |
| 237 | + events = 'onStart onEnd afterGetState afterSetState afterRemoveState onShow onShown onHide onHidden onNext onPrev onPause onResume'.split(' '), |
| 238 | + options = 'name container keyboard storage debug redirect duration basePath placement backdrop orphan'.split(' '); |
| 239 | + |
| 240 | + //Pass interpolated values through |
| 241 | + TourHelpers.attachInterpolatedValues(attrs, tour, options); |
231 | 242 |
|
232 | 243 | //Attach event handlers
|
233 |
| - TourHelpers.attachEventHandlers(scope, attrs, options, events); |
| 244 | + TourHelpers.attachEventHandlers(scope, attrs, tour, events); |
234 | 245 |
|
235 | 246 | //Compile template
|
236 |
| - TourHelpers.attachTemplate(scope, attrs, options); |
| 247 | + TourHelpers.attachTemplate(scope, attrs, tour); |
237 | 248 |
|
238 | 249 | //Monitor number of steps
|
239 | 250 | scope.$watchCollection(ctrl.getSteps, function (steps) {
|
|
242 | 253 |
|
243 | 254 | //If there is an options argument passed, just use that instead
|
244 | 255 | if (attrs.tourOptions) {
|
245 |
| - angular.extend(options, scope.$eval(attrs.tourOptions)); |
| 256 | + angular.extend(tour, scope.$eval(attrs.tourOptions)); |
246 | 257 | }
|
247 | 258 |
|
248 | 259 | //Initialize tour
|
249 |
| - scope.tour = ctrl.init(options); |
| 260 | + scope.tour = ctrl.init(tour); |
250 | 261 |
|
251 | 262 | }
|
252 | 263 | };
|
|
263 | 274 |
|
264 | 275 | //Assign required options
|
265 | 276 | var step = {
|
266 |
| - element: element, |
267 |
| - order: attrs.order || 0 |
| 277 | + element: element |
268 | 278 | },
|
269 |
| - events = 'onShow onShown onHide onHidden onNext onPrev onPause onResume'.split(' '); |
270 |
| - |
271 |
| - //Pass static values through |
272 |
| - if (attrs.path) { step.path = attrs.path; } |
273 |
| - if (attrs.animation) { step.animation = attrs.animation; } |
274 |
| - if (attrs.container) { step.container = attrs.container; } |
275 |
| - if (attrs.placement) { step.placement = attrs.placement; } |
276 |
| - if (attrs.backdrop) { step.backdrop = attrs.backdrop; } |
277 |
| - if (attrs.redirect) { step.redirect = attrs.redirect; } |
278 |
| - if (attrs.orphan) { step.orphan = attrs.orphan; } |
279 |
| - if (attrs.reflex) { step.reflex = attrs.reflex; } |
| 279 | + events = 'onShow onShown onHide onHidden onNext onPrev onPause onResume'.split(' '), |
| 280 | + options = 'content title path animation container placement backdrop redirect orphan reflex'.split(' '); |
280 | 281 |
|
281 | 282 | //Pass interpolated values through
|
282 |
| - attrs.$observe('content', function (content) { |
283 |
| - step.content = content; |
284 |
| - }); |
285 |
| - attrs.$observe('title', function (title) { |
286 |
| - step.content = title; |
| 283 | + TourHelpers.attachInterpolatedValues(attrs, step, options); |
| 284 | + attrs.$observe('order', function (order) { |
| 285 | + step.order = !isNaN(order*1) ? order*1 : 0; |
| 286 | + ctrl.refreshTour(); |
287 | 287 | });
|
288 | 288 |
|
289 | 289 | //Attach event handlers
|
|
294 | 294 |
|
295 | 295 | //Check whether or not the step should be skipped
|
296 | 296 | function stepIsSkipped() {
|
| 297 | + var skipped; |
297 | 298 | if (attrs.skip) {
|
298 |
| - return scope.$eval(attrs.skip); |
| 299 | + skipped = scope.$eval(attrs.skip); |
| 300 | + } |
| 301 | + if (!skipped) { |
| 302 | + skipped = element.is(':hidden'); |
299 | 303 | }
|
300 |
| - return false; |
| 304 | + return skipped; |
301 | 305 | }
|
302 | 306 | scope.$watch(stepIsSkipped, function (skip) {
|
303 | 307 | if (skip) {
|
|
321 | 325 | }]);
|
322 | 326 |
|
323 | 327 | }(angular.module('bm.bsTour', [])));
|
| 328 | + |
| 329 | + |
0 commit comments