|
82 | 82 |
|
83 | 83 | }
|
84 | 84 |
|
| 85 | + app.factory('TourTemplateFactory', ['$templateCache', '$compile', function ($templateCache, $compile) { |
| 86 | + |
| 87 | + var templateFactory = {}; |
| 88 | + |
| 89 | + templateFactory.wrap = function (template, scope) { |
| 90 | + return function (/*index, step*/) { |
| 91 | + var $template = angular.element(template); //requires jQuery |
| 92 | + safeApply(scope, function () { |
| 93 | + $compile($template)(scope); |
| 94 | + }); |
| 95 | + return $template; |
| 96 | + } |
| 97 | + |
| 98 | + }; |
| 99 | + |
| 100 | + templateFactory.get = function (templateUrl, scope) { |
| 101 | + |
| 102 | + var template = $templateCache.get(templateUrl); |
| 103 | + |
| 104 | + if (template) { |
| 105 | + return templateFactory.wrap(template, scope); |
| 106 | + } |
| 107 | + |
| 108 | + return null; |
| 109 | + |
| 110 | + }; |
| 111 | + |
| 112 | + |
| 113 | + return templateFactory; |
| 114 | + |
| 115 | + }]); |
| 116 | + |
85 | 117 | app.controller('TourController', ['$filter', function ($filter) {
|
86 | 118 |
|
87 | 119 | var self = this,
|
|
137 | 169 |
|
138 | 170 | }]);
|
139 | 171 |
|
140 |
| - app.directive('tour', [function () { |
| 172 | + app.directive('tour', ['TourTemplateFactory', function (TourTemplateFactory) { |
141 | 173 |
|
142 | 174 | return {
|
143 | 175 | restrict: 'EA',
|
|
157 | 189 | placement: attrs.placement || 'right',
|
158 | 190 | backdrop: attrs.backdrop || false,
|
159 | 191 | orphan: attrs.orphan || false
|
160 |
| - }; |
| 192 | + }, |
| 193 | + template; |
161 | 194 |
|
162 | 195 | attachEventHandlers(scope, attrs, options);
|
163 | 196 |
|
|
197 | 230 | };
|
198 | 231 | }
|
199 | 232 |
|
| 233 | + if (attrs.template) { |
| 234 | + template = TourTemplateFactory.wrap(scope.$eval(attrs.template), scope); |
| 235 | + } |
| 236 | + |
| 237 | + if (attrs.templateUrl) { |
| 238 | + template = TourTemplateFactory.get(attrs.templateUrl, scope); |
| 239 | + } |
| 240 | + |
| 241 | + if (template) { |
| 242 | + options.template = template; |
| 243 | + } |
| 244 | + |
200 | 245 | scope.$watchCollection(ctrl.getSteps, function (steps) {
|
201 | 246 | scope.stepCount = steps.length;
|
202 | 247 | });
|
|
212 | 257 |
|
213 | 258 | }]);
|
214 | 259 |
|
215 |
| - app.directive('tourStep', [function () { |
| 260 | + app.directive('tourStep', ['TourTemplateFactory', function (TourTemplateFactory) { |
216 | 261 |
|
217 | 262 | return {
|
218 | 263 | restrict: 'EA',
|
|
223 | 268 | var step = {
|
224 | 269 | element: element,
|
225 | 270 | order: attrs.order || 0
|
226 |
| - }; |
| 271 | + }, |
| 272 | + template; |
227 | 273 |
|
228 | 274 | if (attrs.path) { step.path = attrs.path; }
|
229 | 275 | if (attrs.animation) { step.animation = attrs.animation; }
|
|
244 | 290 | step.content = title;
|
245 | 291 | });
|
246 | 292 |
|
| 293 | + if (attrs.template) { |
| 294 | + template = TourTemplateFactory.wrap(scope.$eval(attrs.template), scope); |
| 295 | + } |
| 296 | + |
| 297 | + if (attrs.templateUrl) { |
| 298 | + template = TourTemplateFactory.get(attrs.templateUrl, scope); |
| 299 | + } |
| 300 | + |
| 301 | + if (template) { |
| 302 | + options.template = template; |
| 303 | + } |
247 | 304 |
|
248 | 305 | function stepIsSkipped() {
|
249 | 306 | if (attrs.skip) {
|
|
0 commit comments