forked from angular/angular.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdirectives.js
53 lines (45 loc) · 1.29 KB
/
directives.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
angular.module('directives', [])
/**
* scrollTo Directive
*
* @description
* Upon click, scroll to the target element (identified by the selector provided via the `scroll-to`
* attribute).
*/
.directive('scrollTo', ['$document', '$location', function($document, $location) {
var doc = $document[0];
return {
restrict: 'A',
link: function scrollToPostLink(scope, elem, attrs) {
elem.on('click', onClick);
function onClick() {
var targetSelector = attrs.scrollTo;
var targetElem = doc.querySelector(targetSelector);
if (targetElem) {
targetElem.scrollIntoView();
}
}
}
};
}])
.directive('code', ['$window', function($window) {
return {
restrict: 'E',
terminal: true,
compile: function(element) {
var linenums = element.hasClass('linenum');// || element.parent()[0].nodeName === 'PRE';
var match = /lang-(\S+)/.exec(element[0].className);
var lang = match && match[1];
var html = element.html();
element.html($window.prettyPrintOne(html, lang, linenums));
}
};
}])
// TODO: Probably not needed any more
.directive('scrollYOffsetElement', ['$anchorScroll', function($anchorScroll) {
return {
link: function(scope, element) {
$anchorScroll.yOffset = element;
}
};
}]);