forked from CFGer/taster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrollers.js
63 lines (57 loc) · 1.82 KB
/
controllers.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
var app = angular.module('IntroductionApp', ['ui.codemirror']);
app.directive('item', function() {
return {
restrict: 'E',
scope: {
title: "@"
},
template: '<input id="{{title}}" class="css-checkbox" type="checkbox" ng-click="change(title)"><label for="{{title}}" class="css-label">{{title}}</label><br />',
link: function(scope, element, attrs) {
scope.$parent.add(scope.title);
scope.change = function(title) {
scope.$parent.change(scope.title);
}
},
}
});
app.controller('ContentController', function($scope, $sce) {
$scope.items = [];
$scope.data = {htmlString:"", trustedVersion:""}
$scope.$watch("data.htmlString", function(newValue) {
//debugger;
$scope.data.trustedVersion = $sce.trustAsHtml(newValue);
}, true);
$scope.editorOptions = {
lineWrapping : true,
theme : 'twilight',
lineNumbers: true,
mode: 'htmlmixed',
viewportMargin: 1000
};
$scope.add = function(title) {
var item = {title: title, completed: false}
$scope.items.push(item);
}
$scope.change = function(title) {
//find element
var element = null;
for(var i = 0; i < $scope.items.length; i++) {
var e = $scope.items[i];
if(e.title == title) {
element = e;
}
}
element.completed = !element.completed;
}
$scope.completedPercentage = function() {
var completed = 0;
for(var i = 0; i < $scope.items.length; i++) {
if($scope.items[i].completed) {
completed++;
}
}
return (completed/$scope.items.length)*100;
}
});
app.controller('NavController', function($scope, $anchorScroll) {
});