|
1 | | -var ngIntroDirective = angular.module('angular-intro',[]); |
2 | | - |
3 | | -// TODO: Use isolate scope, but requires angular 1.2: http://plnkr.co/edit/a2c14O?p=preview |
4 | | -// See: http://stackoverflow.com/questions/18796023/in-a-directive-handle-calls-to-a-user-defined-method-name |
5 | | - |
6 | | -ngIntroDirective.directive('ngIntroOptions', ['$timeout', function ($timeout) { |
7 | | - |
8 | | - return { |
9 | | - restrict: 'A', |
10 | | - |
11 | | - link: function(scope, element, attrs){ |
12 | | - |
13 | | - scope[attrs.ngIntroMethod] = function(step) { |
14 | | - |
15 | | - if(typeof(step)=="string"){ |
16 | | - var intro = introJs(step); |
17 | | - } |
18 | | - else{ |
19 | | - var intro = introJs(); |
20 | | - } |
21 | | - |
22 | | - intro.setOptions(scope.$eval(attrs.ngIntroOptions)); |
23 | | - |
24 | | - if(attrs.ngIntroOncomplete){ |
25 | | - intro.oncomplete(scope[attrs.ngIntroOncomplete]); |
26 | | - } |
27 | | - |
28 | | - if(attrs.ngIntroOnexit){ |
29 | | - intro.onexit(scope[attrs.ngIntroOnexit]); |
30 | | - } |
31 | | - |
32 | | - if(attrs.ngIntroOnchange){ |
33 | | - intro.onchange(scope[attrs.ngIntroOnchange]); |
34 | | - } |
35 | | - |
36 | | - if(attrs.ngIntroOnbeforechange){ |
37 | | - intro.onbeforechange(scope[attrs.ngIntroOnbeforechange]); |
38 | | - } |
39 | | - |
40 | | - if(attrs.ngIntroOnafterchange){ |
41 | | - intro.onafterchange(scope[attrs.ngIntroOnafterchange]); |
42 | | - } |
43 | | - |
44 | | - if(typeof(step)=="number"){ |
45 | | - intro.goToStep(step).start(); |
46 | | - } |
47 | | - else{ |
48 | | - intro.start(); |
49 | | - } |
50 | | - |
51 | | - }; |
52 | | - |
53 | | - |
54 | | - if(attrs.ngIntroAutostart == "true"){ |
55 | | - //Only runs when DOM is ready |
56 | | - $timeout(function() {scope[attrs.ngIntroMethod]();}, 0); |
57 | | - } |
58 | | - } |
59 | | - } |
| 1 | +var ngIntroDirective = angular.module('angular-intro', []); |
| 2 | + |
| 3 | +/** |
| 4 | + * TODO: Use isolate scope, but requires angular 1.2: http://plnkr.co/edit/a2c14O?p=preview |
| 5 | + * See: http://stackoverflow.com/q/18796023/237209 |
| 6 | + */ |
| 7 | + |
| 8 | +ngIntroDirective.directive('ngIntroOptions', ['$timeout', '$parse', function ($timeout, $parse) { |
| 9 | + |
| 10 | + return { |
| 11 | + restrict: 'A', |
| 12 | + link: function(scope, element, attrs) { |
| 13 | + |
| 14 | + scope[attrs.ngIntroMethod] = function(step) { |
| 15 | + |
| 16 | + if(typeof(step) === 'string') { |
| 17 | + var intro = introJs(step); |
| 18 | + } else { |
| 19 | + var intro = introJs(); |
| 20 | + } |
| 21 | + |
| 22 | + intro.setOptions(scope.$eval(attrs.ngIntroOptions)); |
| 23 | + |
| 24 | + if(attrs.ngIntroOncomplete) { |
| 25 | + intro.oncomplete($parse(attrs.ngIntroOncomplete)(scope)); |
| 26 | + } |
| 27 | + |
| 28 | + if(attrs.ngIntroOnexit) { |
| 29 | + intro.onexit($parse(attrs.ngIntroOnexit)(scope)); |
| 30 | + } |
| 31 | + |
| 32 | + if(attrs.ngIntroOnchange) { |
| 33 | + intro.onchange($parse(attrs.ngIntroOnchange)(scope)); |
| 34 | + } |
| 35 | + |
| 36 | + if(attrs.ngIntroOnbeforechange) { |
| 37 | + intro.onbeforechange($parse(attrs.ngIntroOnbeforechange)(scope)); |
| 38 | + } |
| 39 | + |
| 40 | + if(attrs.ngIntroOnafterchange) { |
| 41 | + intro.onafterchange($parse(attrs.ngIntroOnafterchange)(scope)); |
| 42 | + } |
| 43 | + |
| 44 | + if(typeof(step) === 'number') { |
| 45 | + intro.goToStep(step).start(); |
| 46 | + } else { |
| 47 | + intro.start(); |
| 48 | + } |
| 49 | + }; |
| 50 | + |
| 51 | + if(attrs.ngIntroAutostart == 'true') { |
| 52 | + $timeout(function() { |
| 53 | + $parse(attrs.ngIntroMethod)(scope)(); |
| 54 | + }); |
| 55 | + } |
| 56 | + } |
| 57 | + } |
60 | 58 | }]); |
0 commit comments