-
Notifications
You must be signed in to change notification settings - Fork 11
/
app.js
76 lines (69 loc) · 1.76 KB
/
app.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
var app = angular.module('app', ['ngRoute', 'ngAnimate'])
app.directive("markdown", function ($compile, $http) {
var converter = new Showdown.converter()
return {
restrict: 'E',
replace: true,
link: function (scope, element, attrs) {
if ("src" in attrs) {
$http.get(attrs.src).then(function (data) {
element.html(converter.makeHtml(data.data))
})
} else {
element.html(converter.makeHtml(element.text()))
}
}
}
})
app.directive('pager', function () {
return {
restrict: 'E',
transclude: true,
templateUrl: './templates/pager.html',
replace: true,
scope: {
previousPath: '@',
previousTxt: '@',
nextPath: '@',
nextTxt: '@'
}
}
})
app.factory('pages', function ($http) {
return $http.get('./pages.json')
})
app.controller('wikiController', function ($scope, $routeParams, pages) {
$scope.pages = []
$scope.templateUrl = './pages/' + $routeParams.name + '.md'
$scope.previousPage = {}
$scope.nextPage = {}
function populateLinks(json, url) {
for (var i = 0, l = json.length; i < l; i++) {
var data = json[i]
if (data.link && data.link === url) {
$scope.previousPage = json[i - 1]
$scope.nextPage = json[i + 1]
} else if (data.links) {
populateLinks(data.links, url)
}
}
}
pages.success(function (data) {
$scope.pages = data
var path = $routeParams.name
if (path) {
populateLinks(data, '#' + path)
}
})
})
app.config(function($routeProvider) {
$routeProvider
.when('/', {
templateUrl : 'pages/home.html',
controller: 'wikiController'
})
.when('/:name*', {
templateUrl: './templates/markdown.html',
controller: 'wikiController'
})
})