-
Notifications
You must be signed in to change notification settings - Fork 98
/
app.js
83 lines (63 loc) · 1.83 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
77
78
79
80
81
var app = angular.module('myApp', []);
app.config(function ($sceDelegateProvider) {
$sceDelegateProvider.resourceUrlWhitelist(['self', '**']);
});
app.constant('URL', 'data/');
app.factory('DataService', function ($http, URL) {
var getData = function () {
return $http.get(URL + 'content.json');
};
return {
getData: getData
};
});
app.factory('TemplateService', function ($http, URL) {
var getTemplates = function () {
return $http.get(URL + 'templates.json');
};
return {
getTemplates: getTemplates
};
});
app.controller('ContentCtrl', function (DataService) {
var ctrl = this;
ctrl.content = [];
ctrl.fetchContent = function () {
DataService.getData().then(function (result) {
ctrl.content = result.data;
});
};
ctrl.fetchContent();
});
app.directive('contentItem', function ($compile, TemplateService) {
var getTemplate = function (templates, contentType) {
var template = '';
switch (contentType) {
case 'image':
template = templates.imageTemplate;
break;
case 'video':
template = templates.videoTemplate;
break;
case 'notes':
template = templates.noteTemplate;
break;
}
return template;
};
var linker = function (scope, element, attrs) {
scope.rootDirectory = 'images/';
TemplateService.getTemplates().then(function (response) {
var templates = response.data;
element.html(getTemplate(templates, scope.content.content_type));
$compile(element.contents())(scope);
});
};
return {
restrict: 'E',
link: linker,
scope: {
content: '='
}
};
});