Skip to content

Commit f84ec71

Browse files
committed
added promises for templates
1 parent 29ec2ac commit f84ec71

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

app/tour_directive.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
//Pass static options through or use defaults
1616
var tour = {},
17+
templateReady,
1718
events = 'onStart onEnd afterGetState afterSetState afterRemoveState onShow onShown onHide onHidden onNext onPrev onPause onResume'.split(' '),
1819
options = 'name container keyboard storage debug redirect duration basePath backdrop orphan'.split(' ');
1920

@@ -24,7 +25,7 @@
2425
TourHelpers.attachEventHandlers(scope, attrs, tour, events);
2526

2627
//Compile template
27-
TourHelpers.attachTemplate(scope, attrs, tour);
28+
templateReady = TourHelpers.attachTemplate(scope, attrs, tour);
2829

2930
//Monitor number of steps
3031
scope.$watchCollection(ctrl.getSteps, function (steps) {
@@ -42,8 +43,10 @@
4243
}
4344

4445
//Initialize tour
45-
scope.tour = ctrl.init(tour);
46-
scope.tour.refresh = ctrl.refreshTour;
46+
templateReady.then(function () {
47+
scope.tour = ctrl.init(tour);
48+
scope.tour.refresh = ctrl.refreshTour;
49+
});
4750

4851
}
4952
};

app/tour_helpers.js

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

6-
app.factory('TourHelpers', ['$templateCache', '$http', '$compile', 'TourConfig', function ($templateCache, $http, $compile, TourConfig) {
6+
app.factory('TourHelpers', ['$templateCache', '$http', '$compile', 'TourConfig', '$q', function ($templateCache, $http, $compile, TourConfig, $q) {
77

88
var helpers = {},
99
safeApply;
@@ -89,24 +89,26 @@
8989
*/
9090
helpers.attachTemplate = function (scope, attrs, options) {
9191

92-
var template;
92+
var deferred = $q.defer(),
93+
template;
9394

9495
if (attrs[helpers.getAttrName('template')]) {
9596
template = compileTemplate(scope.$eval(attrs[helpers.getAttrName('template')]), scope);
96-
}
97-
98-
if (template) {
9997
options.template = template;
100-
}
101-
102-
if (attrs[helpers.getAttrName('templateUrl')]) {
98+
deferred.resolve(template);
99+
} else if (attrs[helpers.getAttrName('templateUrl')]) {
103100
lookupTemplate(attrs[helpers.getAttrName('templateUrl')], scope).then(function (template) {
104101
if (template) {
105102
options.template = template;
103+
deferred.resolve(template);
106104
}
107105
});
106+
} else {
107+
deferred.resolve();
108108
}
109109

110+
return deferred.promise;
111+
110112
};
111113

112114
/**

app/tour_step_directive.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
events = 'onShow onShown onHide onHidden onNext onPrev onPause onResume'.split(' '),
2121
options = 'content title path animation container placement backdrop redirect orphan reflex nextStep prevStep nextPath prevPath'.split(' '),
2222
orderWatch,
23-
skipWatch;
23+
skipWatch,
24+
templateReady;
2425

2526
//Pass interpolated values through
2627
TourHelpers.attachInterpolatedValues(attrs, step, options);
@@ -33,7 +34,7 @@
3334
TourHelpers.attachEventHandlers(scope, attrs, step, events);
3435

3536
//Compile templates
36-
TourHelpers.attachTemplate(scope, attrs, step);
37+
templateReady = TourHelpers.attachTemplate(scope, attrs, step);
3738

3839
//Check whether or not the step should be skipped
3940
function stepIsSkipped() {
@@ -89,7 +90,9 @@
8990
}
9091

9192
//Add step to tour
92-
ctrl.addStep(step);
93+
templateReady.then(function () {
94+
ctrl.addStep(step);
95+
});
9396

9497
}
9598
};

0 commit comments

Comments
 (0)