forked from DanielReid/help-popup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelp-directive.js
63 lines (58 loc) · 1.96 KB
/
help-directive.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
'use strict';
define(['angular', 'angular-foundation-6'], function(angular) {
angular.module('help-directive', ['mm.foundation'])
.factory('HelpPopupService', ['$q', function($q) {
var lexicons = {};
var promises = [];
function getHelpItem(key) {
return $q.all(promises).then(function() {
return lexicons[key];
});
}
function loadLexicon(newLexicon) {
var toLoad = newLexicon.then ? newLexicon : $q.resolve(newLexicon);
promises.push(toLoad);
toLoad.then(function(getResult) {
var lexicon = getResult.data || getResult;
for (var propertyName in lexicon) {
if (lexicon.hasOwnProperty(propertyName)) {
lexicons[propertyName] = lexicon[propertyName];
}
}
});
}
return {
getHelpItem: getHelpItem,
loadLexicon: loadLexicon
};
}])
.directive('inlineHelp', ['HelpPopupService',
function(HelpPopupService) {
return {
restrict: 'AE',
replace: false,
template: '' +
'<a class="has-tip"' +
' tooltip-trigger="click"' +
' tooltip-append-to-body="true"' +
' tooltip-animation="true"' +
' tooltip-html-unsafe="{{helpText}}">' +
' <i class="fa fa-question-circle"></i>' +
'</a>',
scope: {
helpKey: '@'
},
link: function(scope) {
HelpPopupService.getHelpItem(scope.helpKey).then(function(helpItem) {
scope.helpText = '' +
'<h4>' + helpItem.title + '</h4>' +
'<div class="tooltip-content">' + helpItem.text + '</div>' +
'<br><div class="manual-link"><h6><a href="' + helpItem.link +
' " target="_blank">View in manual <i class="fa fa-external-link"></i></a></h6>' +
'</div>';
});
}
};
}
]);
});