-
Notifications
You must be signed in to change notification settings - Fork 592
/
subpage-directive.js
96 lines (84 loc) · 2.82 KB
/
subpage-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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
angular
.module('gcloud.subpage', ['gcloud.header', 'hljs'])
.directive('subpage', function($rootScope, $location, $http, $parse, getLinks, versions) {
'use strict';
return {
transclude: true,
templateUrl: 'site/components/subpage/subpage.html',
link: function($scope, elem, attrs) {
$scope.title = attrs.title;
$scope.links = getLinks();
$scope.headerTemplateUrl = attrs.headerTemplateurl;
$scope.versionSelected = $rootScope.ACTIVE_VERSION;
$scope.versions = versions;
$scope.loadDocsVersion = function(newVersion) {
$location.path('docs/' + newVersion);
};
if ($scope.versionSelected === 'master') {
$http.get('https://api.github.com/repos/GoogleCloudPlatform/gcloud-node/commits?sha=gh-pages&per_page=1')
.then(function(resp) {
$scope.lastBuiltDate = moment(resp.data[0].commit.committer.date);
});
}
if (attrs.isActiveUrl) {
$scope.isActiveUrl = $parse(attrs.isActiveUrl)($scope);
} else {
$scope.isActiveUrl = function (url) {
return $location.path() === url.replace('#', '');
};
}
}
};
})
// A special class used in our MD files to tell the front end to syntax
// highlight the code blocks.
.directive('hljsClass', function() {
'use strict';
return {
// Concept borrowed from:
// http://www.bennadel.com/blog/2748-compiling-transcluded-content-in-angularjs-directives.htm
//
// <div class="hljs-class">
// var hi = 'there'; <!-- We want this!
// </div>
//
// We want to replace that with:
//
// <div hljs language="javascript" source="var hi = 'there';"></div>
//
// To get the content we want, we have to use a higher priority than
// another same-named directive that uses transclude. This is our only
// chance to get it before it's clobbered.
priority: 1500.1,
restrict: 'C',
compile: function(element, attrs) {
attrs._contents = element.text();
}
};
})
.directive('hljsClass', function() {
'use strict';
return {
priority: 1500,
restrict: 'C',
transclude: true,
template: '<div hljs language="javascript" source="contents"></div>',
compile: function(element) {
return function($scope, element, attrs) {
$scope.contents = attrs._contents;
};
}
}
})
// Re-compile the Markdown, this time having the "hljs-class" blocks picked
// up.
.directive('highlightMarkdown', function($compile) {
'use strict';
return {
link: function(scope, element, attrs) {
scope.$watch(attrs.ngInclude, function() {
$compile(element.contents())(scope);
}, true);
}
};
});