Skip to content

Commit 393eaf0

Browse files
committed
Wrapped intro.js into directive with hardcoded values
1 parent 97aedf1 commit 393eaf0

File tree

3 files changed

+74
-40
lines changed

3 files changed

+74
-40
lines changed

angular-intro.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
var ngIntroDirective = angular.module('angular-intro',[]);
2+
3+
ngIntroDirective.directive('ngIntro', [function () {
4+
5+
6+
7+
return {
8+
restrict: 'A',
9+
10+
scope:
11+
{
12+
callmethod: '=ngIntroFunction',
13+
opts: '=ngIntroOptions'
14+
15+
},
16+
link: function(scope, element, attrs){
17+
18+
scope.callmethod = function() {
19+
attrs.$observe('IntroSnippets', function(actualValue){
20+
console.log(actualValue);
21+
});
22+
23+
var intro = introJs();
24+
intro.setOptions({
25+
steps:[
26+
{
27+
element: document.querySelector('#step1'),
28+
intro: "This is a tooltip."
29+
},
30+
{
31+
element: document.querySelectorAll('#step2')[0],
32+
intro: "Ok, wasn't that fun?",
33+
position: 'right'
34+
},
35+
{
36+
element: '#step3',
37+
intro: 'More features, more fun.',
38+
position: 'left'
39+
},
40+
{
41+
element: '#step4',
42+
intro: "Another step.",
43+
position: 'bottom'
44+
},
45+
{
46+
element: '#step5',
47+
intro: 'Get it, use it.'
48+
}
49+
]
50+
});
51+
intro.start();
52+
};
53+
}
54+
}
55+
}]);

example/index.html

Lines changed: 13 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
<!DOCTYPE html>
2-
<html lang="en">
2+
<html lang="en" data-ng-app="myApp">
33
<head>
44
<meta charset="utf-8">
5-
<title>Defining with JSON configuration</title>
5+
<title>Port of intro.js to Angular</title>
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
77
<meta name="description" content="Intro.js - Better introductions for websites and features with a step-by-step guide for your projects.">
88
<meta name="author" content="Afshin Mehrabani (@afshinmeh) in usabli.ca group">
99

1010
<!-- styles -->
1111
<link href="assets/css/bootstrap.min.css" rel="stylesheet">
1212
<link href="assets/css/demo.css" rel="stylesheet">
13+
<link href="assets/css/bootstrap-responsive.min.css" rel="stylesheet">
1314

1415
<!-- Add IntroJs styles -->
1516
<link href="../lib/introjs.css" rel="stylesheet">
1617

17-
<link href="assets/css/bootstrap-responsive.min.css" rel="stylesheet">
18+
1819
</head>
1920

20-
<body>
21+
<body >
2122

22-
<div class="container-narrow">
23+
<div class="container-narrow" ng-controller="MyController" ng-intro ng-intro-options="IntroSnippets" ng-intro-function="StartTheTour">
2324

2425
<div class="masthead">
2526
<ul id="step5" class="nav nav-pills pull-right">
@@ -35,7 +36,7 @@ <h3 class="muted">Intro.js</h3>
3536
<div class="jumbotron">
3637
<h1 id="step1">Programmatic</h1>
3738
<p id="step4" class="lead">In this example we are going to define steps with JSON configuration.</p>
38-
<a class="btn btn-large btn-success" href="javascript:void(0);" onclick="startIntro();">Show me how</a>
39+
<a class="btn btn-large btn-success" ng-click="StartTheTour();">Show me how</a>
3940
</div>
4041

4142
<hr>
@@ -69,39 +70,11 @@ <h4>Section Six</h4>
6970

7071
</div>
7172
<script type="text/javascript" src="../lib/intro.min.js"></script>
72-
<script type="text/javascript">
73-
function startIntro(){
74-
var intro = introJs();
75-
intro.setOptions({
76-
steps: [
77-
{
78-
element: document.querySelector('#step1'),
79-
intro: "This is a tooltip."
80-
},
81-
{
82-
element: document.querySelectorAll('#step2')[0],
83-
intro: "Ok, wasn't that fun?",
84-
position: 'right'
85-
},
86-
{
87-
element: '#step3',
88-
intro: 'More features, more fun.',
89-
position: 'left'
90-
},
91-
{
92-
element: '#step4',
93-
intro: "Another step.",
94-
position: 'bottom'
95-
},
96-
{
97-
element: '#step5',
98-
intro: 'Get it, use it.'
99-
}
100-
]
101-
});
102-
103-
intro.start();
104-
}
105-
</script>
73+
74+
75+
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js"></script>
76+
<script src="../angular-intro.js"></script>
77+
<script src="../lib/app.js"></script>
78+
10679
</body>
10780
</html>

lib/app.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
var app = angular.module('myApp', ['angular-intro']);
2+
3+
app.controller('MyController', function ($scope) {
4+
5+
});
6+

0 commit comments

Comments
 (0)