This repository has been archived by the owner on Jan 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
186 lines (164 loc) · 4.79 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
180
181
182
183
184
185
186
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<style>
body {
margin: 0;
padding: 0;
}
button {
color: black;
padding: 15px;
border: solid 2px black;
}
.disabledButton {
background: gray;
}
.product {
border: 1px solid black;
padding: 15px;
margin: 15px auto;
max-width: 600px;
}
.product:hover {
background-color: lightgoldenrodyellow;
}
.header {
position: relative;
width: 100%;
height: 100px;
background: green;
}
.cart {
color: white;
position: absolute;
right: 0;
top: 0;
margin: 10px;
}
.preview-images img {
max-width: 100px;
padding: 15px;
margin: 5px;
border: 1px solid black;
}
.image {
max-width: 385px;
padding: 15px;
margin: 5px;
border: 1px solid black;
}
</style>
</head>
<body>
<div id="app">
<div class="header">
<cart :cart="this.cart" :inventory="this.inventory" @empty-cart="cart = 0"></cart>
</div>
<div v-for="product in products" class="product">
<h4>{{product.name}}</h4>
<div v-if="product.images">
<div class="preview-images">
<img v-for="image in product.images" :src="image" :alt="imageDesc(product)" :title="imageDesc(product)" @mouseover="product.bigImage = image">
</div>
<img class="image" :src="product.bigImage" :alt="imageDesc(product)" :title="imageDesc(product)">
</div>
<p>{{product.description}}</p>
<ul>
<li v-for="ingredient in product.ingredients">{{ingredient}}</li>
</ul>
<p v-if="product.stock > 10">In Stock</p>
<p v-else-if="product.stock < 10 && product.stock > 0">Almost sold out!</p>
<p v-else="product.stock">Out of Stock</p>
<p v-if="product.stock">{{product.price.currency + product.price.main + '.' + product.price.fractional }}</p>
<button @click="cart = cart + 1" :class="{ disabledButton: !product.stock }" :disabled="!product.stock">Add to Cart</button>
<twitter-button :title="product.name"></twitter-button>
</div>
</div>
<script>
Vue.component('cart', {
props: ['cart', 'inventory'],
methods: {
emptyCart: function () {
this.$emit("empty-cart");
}
},
template: '<div class="cart" :style="{ fontSize: 16 + (cart *2) + \'px\' }">Cart: {{cart}} / {{inventory}} (<span @click="emptyCart">leeren</span>)</div>'
})
Vue.component('twitter-button', {
props: ['title'],
data: function () {
return {
text: "Twitter"
}
},
computed: {
twitterLink: function () {
return "https://twitter.com/intent/tweet?text=" + this.title;
}
},
template: '<a :href="twitterLink"><button style="background: lightblue; color: white;">{{text}}</button></a>'
})
var data = {
cart: 0,
selectedImage: '',
products: [
{
name: 'Toller Artikel',
description: 'Sein Geld wert.',
ingredients: ['good stuff', 'bad stuff'], // A list.
price: {
main: 10,
fractional: 20,
currency: 'US$'
},
stock: 100,
images: [
'https://upload.wikimedia.org/wikipedia/commons/thumb/2/27/Toastbrot-1.jpg/475px-Toastbrot-1.jpg',
'https://upload.wikimedia.org/wikipedia/commons/thumb/a/a3/Mischbrot-1.jpg/480px-Mischbrot-1.jpg',
'https://upload.wikimedia.org/wikipedia/commons/thumb/2/2c/Wei%C3%9Fbrot-1.jpg/480px-Wei%C3%9Fbrot-1.jpg'
],
bigImage: 'https://upload.wikimedia.org/wikipedia/commons/thumb/2/27/Toastbrot-1.jpg/475px-Toastbrot-1.jpg'
},
{
name: 'Schöner Artikel',
description: 'Wunderbar.',
ingredients: ['nice stuff', 'ugly stuff'],
price: {
main: 20,
fractional: 10,
currency: 'British£'
},
stock: 100
}
]
};
var app = new Vue({
el: '#app',
data: data,
computed: {
inventory: function () {
var counter = 0;
this.products.forEach(function (product) {
counter += product.stock;
});
return counter;
}
},
methods: {
imageDesc: function (product) {
return product.name + ' - ' + product.description;
},
selectImage: function (image) {
this.selectedImage = image;
}
}
})
</script>
</body>
</html>