-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
179 lines (177 loc) · 6.14 KB
/
index.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<!DOCTYPE html>
<html lang="pt-br" ng-app="ShopCart">
<head>
<link rel="manifest" href="manifest.json">
<style>
body {
background-color: black;
font-family: Verdana, Geneva, Tahoma, sans-serif;
color: #F5F5F5;
}
input {
display: block;
border-radius: 5px;
border: 1px #616161 solid;
padding: 10px 5px;
margin: 10px 0;
width: 100%;
background-color: #212121;
color: #F5F5F5;
font-size: 1em;
box-sizing: border-box;
}
input:focus {
outline: none;
border: 1px #2196F3 solid
}
form {
margin: auto;
padding-top: 10px;
align-content: center;
width: 85%;
}
h2 {
margin-top: 1em;
font-size: 1.5em;
text-align: center;
width: 100%;
}
h3,
h4 {
margin: 10px;
}
button {
display: block;
border-radius: 5px;
font-size: 1em;
border: 1px black;
margin: 5px 0;
padding: 10px;
font-weight: bold;
width: 100%;
color: white;
}
button:active {
outline: none;
filter: brightness(80%)
}
button:focus {
outline: none;
}
.add {
background-color: rgb(20, 77, 21);
}
.remove {
background-color: rgb(148, 30, 21);
}
.total {
font-weight: bold;
color: #4CAF50;
}
.box {
background-color: #212121;
width: 85%;
padding: 1px 2px;
border-radius: 5px;
margin: auto;
margin-top: 5px;
box-sizing: border-box;
border: 1px #616161 solid;
}
.content {
margin-top: 3em
}
</style>
<meta charset="UTF-8">
<meta name="theme-color" content="#212121">
<meta name="description" content="ShopCart - shopping calculator">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Shop Cart</title>
</head>
<body ng-controller="cartCtrl">
<div class="content">
<div class="box">
<h2>Compras</h2>
</div>
<div class="box">
<h3>Total =<span class="total">
{{total | currency : "R$": 2}}</span></h3>
</div>
<div class="box">
<h4>Preço =
{{preco | currency : "R$" : 2}}</h4>
</div>
<form>
<label for="preco">
<span>Valor unitário:</span>
<input
type="number"
class="preco"
name="preco"
ng-model="preco"
step="0.01"
onfocus="this.value=''"
id="preco"
min="0"
autofocus/>
</label>
<label for="quantidade">
<span>Quantidade:</span>
<input
id="quantidade"
type="number"
value="1"
min="1"
name="quantidade"
ng-model="quantidade"
onfocus="this.value=''">
</label>
<button class="add" ng-click="calculaTotal(preco, quantidade)">Adicionar</button>
<button class="remove" ng-click="desfazer()">Remover Último</button>
</form>
</div>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
crossorigin="anonymous"></script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.14.15/jquery.mask.min.js"
integrity="sha256-u7MY6EG5ass8JhTuxBek18r5YG6pllB9zLqE4vZyTn4="
crossorigin="anonymous"></script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.8/angular.min.js"
integrity="sha256-23hi0Ag650tclABdGCdMNSjxvikytyQ44vYGo9HyOrU="
crossorigin="anonymous"></script>
<script>
// $(document).ready(() => { $('.preco').mask('000,00', {reverse: true}) })
angular.module('ShopCart', [])
angular
.module('ShopCart')
.controller('cartCtrl', $scope => {
$scope.total = 0
$scope.preco = ''
$scope.quantidade = 1
$scope.calculaTotal = (p, q) => {
$scope.desfazerValue = p * q
$scope.total = $scope.total + (p * q)
$scope.preco = ''
$scope.quantidade = 1
$('#preco').focus().val('')
}
$scope.desfazer = () => {
$scope.total = $scope.total - $scope.desfazerValue
$scope.desfazerValue = 0
$('#preco').focus().val('')
}
})
</script>
<script>
if (window.location.protocol === 'https:' && !navigator.serviceWorker.controller) {
navigator.serviceWorker.register('pwabuilder-sw.js', {
scope: './'
})
}
</script>
</body>
</html>