forked from benmarch/angular-ui-tour
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtour-service.js
81 lines (68 loc) · 2.15 KB
/
tour-service.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
(function (module) {
'use strict';
module.factory('uiTourService', ['$controller', function ($controller) {
var service = {},
tours = [];
/**
* If there is only one tour, returns the tour
*/
service.getTour = function () {
return tours[0];
};
/**
* Look up a specific tour by name
*
* @param {string} name Name of tour
*/
service.getTourByName = function (name) {
return tours.filter(function (tour) {
return tour.options.name === name;
})[0];
};
/**
* Finds the tour available to a specific element
*
* @param {jqLite | HTMLElement} element Element to use to look up tour
* @returns {*}
*/
service.getTourByElement = function (element) {
return angular.element(element).controller('uiTour');
};
/**
* Creates a tour that is not attached to a DOM element (experimental)
*
* @param {string} name Name of the tour (required)
* @param {{}=} config Options to override defaults
*/
service.createDetachedTour = function (name, config) {
if (!name) {
throw {
name: 'ParameterMissingError',
message: 'A unique tour name is required for creating a detached tour.'
};
}
config = config || {};
config.name = name;
return $controller('uiTourController').init(config);
};
/**
* Used by uiTourController to register a tour
*
* @protected
* @param tour
*/
service._registerTour = function (tour) {
tours.push(tour);
};
/**
* Used by uiTourController to remove a destroyed tour from the registry
*
* @protected
* @param tour
*/
service._unregisterTour = function (tour) {
tours.splice(tours.indexOf(tour), 1);
};
return service;
}]);
}(angular.module('bm.uiTour')));