Skip to content

Commit a19be78

Browse files
committed
fixes #13: tour steps were not passing inherited properties to $uibTooltip
fixes #16: unregisters tours when their scopes are destroyed
1 parent 3332b7e commit a19be78

File tree

10 files changed

+340
-175
lines changed

10 files changed

+340
-175
lines changed

app/tour-controller.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
(function (app) {
44
'use strict';
55

6-
app.controller('uiTourController', ['$timeout', '$q', '$filter', 'TourConfig', 'uiTourBackdrop', 'uiTourService', function ($timeout, $q, $filter, TourConfig, uiTourBackdrop, uiTourService) {
6+
app.controller('uiTourController', ['$timeout', '$q', '$filter', 'TourConfig', 'uiTourBackdrop', 'uiTourService', 'ezEventEmitter', function ($timeout, $q, $filter, TourConfig, uiTourBackdrop, uiTourService, EventEmitter) {
77

88
var self = this,
99
stepList = [],
@@ -17,6 +17,8 @@
1717
tourStatus = statuses.OFF,
1818
options = TourConfig.getAll();
1919

20+
EventEmitter.mixin(self);
21+
2022
/**
2123
* Closer to $evalAsync, just resolves a promise
2224
* after the next digest cycle
@@ -300,8 +302,19 @@
300302
options = angular.extend(options, opts);
301303
self.options = options;
302304
uiTourService._registerTour(self);
305+
self.initialized = true;
306+
self.emit('init');
303307
return self;
304308
};
309+
310+
/**
311+
* Unregisters with the tour service when tour is destroyed
312+
*
313+
* @protected
314+
*/
315+
self.destroy = function () {
316+
uiTourService._unregisterTour(self);
317+
};
305318
//------------------ end Protected API ------------------
306319

307320

app/tour-directive.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
if (typeof tour.onReady === 'function') {
3535
tour.onReady();
3636
}
37+
38+
scope.$on('$destroy', function () {
39+
ctrl.destroy();
40+
});
3741
}
3842
};
3943

app/tour-helpers.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,23 @@
4242
return string;
4343
}
4444

45+
/**
46+
* This will attach the properties native to Angular UI Tooltips. If there is a tour-level value set
47+
* for any of them, this passes that value along to the step
48+
*
49+
* @param {$rootScope.Scope} scope The tour step's scope
50+
* @param {Attributes} attrs The tour step's Attributes
51+
* @param {Object} step Represents the tour step object
52+
* @param {Array} properties The list of Tooltip properties
53+
*/
54+
helpers.attachTourConfigProperties = function (scope, attrs, step, properties) {
55+
angular.forEach(properties, function (property) {
56+
if (!attrs[helpers.getAttrName(property)] && angular.isDefined(step.config(property))) {
57+
attrs.$set(helpers.getAttrName(property), String(step.config(property)));
58+
}
59+
});
60+
};
61+
4562
/**
4663
* Helper function that attaches event handlers to options
4764
*

app/tour-service.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,21 @@
3939
*
4040
* @protected
4141
* @param tour
42-
* @private
4342
*/
4443
service._registerTour = function (tour) {
4544
tours.push(tour);
4645
};
4746

47+
/**
48+
* Used by uiTourController to remove a destroyed tour from the registry
49+
*
50+
* @protected
51+
* @param tour
52+
*/
53+
service._unregisterTour = function (tour) {
54+
tours.splice(tours.indexOf(tour), 1);
55+
};
56+
4857
return service;
4958

5059
}]);

app/tour-step-directive.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,23 @@
3737
},
3838
events = 'onShow onShown onHide onHidden onNext onPrev'.split(' '),
3939
options = 'content title animation placement backdrop orphan popupDelay popupCloseDelay fixed preventScrolling nextStep prevStep nextPath prevPath scrollOffset'.split(' '),
40+
tooltipAttrs = 'animation appendToBody placement popupDelay popupCloseDelay'.split(' '),
4041
orderWatch,
4142
enabledWatch;
4243

44+
//Will add values to pass to $uibTooltip
45+
function configureInheritedProperties() {
46+
TourHelpers.attachTourConfigProperties(scope, attrs, step, tooltipAttrs, 'tourStep');
47+
tourStepLinker(scope, element, attrs);
48+
}
49+
4350
//Pass interpolated values through
4451
TourHelpers.attachInterpolatedValues(attrs, step, options);
4552
orderWatch = attrs.$observe(TourHelpers.getAttrName('order'), function (order) {
4653
step.order = !isNaN(order*1) ? order*1 : 0;
47-
ctrl.reorderStep(step);
54+
if (ctrl.hasStep(step)) {
55+
ctrl.reorderStep(step);
56+
}
4857
});
4958
enabledWatch = attrs.$observe(TourHelpers.getAttrName('enabled'), function (isEnabled) {
5059
step.enabled = isEnabled !== 'false';
@@ -81,10 +90,17 @@
8190
step.trustedContent = $sce.trustAsHtml(step.content);
8291

8392
//Add step to tour
84-
ctrl.addStep(step);
8593
scope.tourStep = step;
8694
scope.tour = scope.tour || ctrl;
87-
tourStepLinker(scope, element, attrs);
95+
if (ctrl.initialized) {
96+
configureInheritedProperties();
97+
ctrl.addStep(step);
98+
} else {
99+
ctrl.once('init', function () {
100+
configureInheritedProperties();
101+
ctrl.addStep(step);
102+
});
103+
}
88104

89105
//clean up when element is destroyed
90106
scope.$on('$destroy', function () {

0 commit comments

Comments
 (0)