-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmid2-1.html
85 lines (85 loc) · 2.44 KB
/
mid2-1.html
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
<!DOCTYPE HTML>
<html>
<head>
<title>Midterm 2 part 1</title>
<meta charset="UTF-8">
<style type="text/css">
pre span { background-color: lightskyblue; }
.advanced { background-color: aliceblue; visibility: hidden; }
.fixed { visibility: visible; }
.code { background-color: white; font-family: courier, sans-serif; font-size: 80%; }
p { font-family: courier, sans-serif; }
</style>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
</head>
<body>
<p><script type="text/javascript">document.write(location.href)</script></p>
<table>
<tr>
<th>HTML</th>
<th>JavaScript</th>
</tr>
<tr>
<td valign="top" style="border-right:1px dashed silver">
<pre>
<body ng-app="<span>comment</span>" ng-controller="<span>MainCtrl</span>">
...
<form ng-submit="<span>addComment</span>()" style = "margin-top30px;">
<span class="advanced"> <input type="text" ng-model="picture"></input></span>
<input type="text" ng-model="<span>formContent</span>"></input>
<button type="submit">Add Comment</button>
</form>
<div ng-repeat="comment in <span>comments</span> | orderBy: '-upvotes'">
<span class="glyphicon glyphicon-remove"
ng-click="delete(comment)"></span>
<span class="glyphicon glyphicon-thumbs-up"
ng-click="<span>incrementUpvotes</span>(comment)"></span>
<span class="advanced"> <img src="{{comment.picture}}" width="40"></span>
{{comment.title}} - upvotes: {{comment.upvotes}}
</div>
...
</body>
</pre>
</td>
<td valign="top">
<pre>
angular.module('<span>comment</span>', [])
.controller('<span>MainCtrl</span>', [
'$scope','$http',
function($scope,$http){
<span>$scope.comments</span> = [];
<span>$scope.addComment</span> = function() {
var newcomment = {
<span class="advanced"> picture:$scope.picture,</span>
title:<span>$scope.formContent</span>,
upvotes:0
};
<span class="advanced"> $scope.picture='';</span>
<span>$scope.formContent</span>='';
$http.post('/comments', newcomment).success(function(data){
<span>$scope.comments</span>.push(data);
});
};
<span>$scope.incrementUpvotes</span> = function(comment) {
...
};
...
}
]);
</pre>
</td>
</tr>
<tr>
<td></td>
<td>
<button id="fixer">fix</button>
</td>
</tr>
</table>
<script type="text/javascript">
$("#fixer").click(function(){
$(".advanced").toggleClass("fixed");
});
</script>
</body>
</html>