-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
285 lines (261 loc) · 14.2 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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
<title>XFinityMedia</title>
<style>
.drawing-area{
position: absolute;
top: 60px;
left: 122px;
z-index: 10;
width: 200px;
height: 400px;
}
.canvas-container{
width: 200px;
height: 400px;
position: relative;
user-select: none;
}
#tshirt-div{
width: 452px;
height: 548px;
position: relative;
background-color: #fff;
}
#canvas{
position: absolute;
width: 200px;
height: 400px;
left: 0px;
top: 0px;
user-select: none;
cursor: default;
}
</style>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="#">Design Tool</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link active" href="#">Design Tool</a>
</li>
</ul>
<form class="d-flex">
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-primary" type="submit">Search</button>
</form>
</div>
</div>
</nav>
<div class="container" style="padding: 20px 5px;">
<div class="card mb-3" style="max-width: auto;">
<div class="card-body">
<center><h4 class="card-title">Custom T-Shirt Design Tool</h4></center><br>
<div class="row" style="padding: 10px 0px;">
<div class="col-md-4">
<div id="tshirt-div">
<!--
Initially, the image will have the background tshirt that has transparency
So we can simply update the color with CSS or JavaScript dinamically
-->
<div id= "tshirt-backgroundpicture">
<img id="tshirt-backgroundpicture1" src="./background_tshirt.png" width="" />
<img id="tshirt-backgroundpicture2" src="./red.png" width="" style="display: none"/>
<img id="tshirt-backgroundpicture3" src="./blue.png" width="" style="display: none;"/>
<img id="tshirt-backgroundpicture4" src="./green.png" width="" style="display: none;"/>
</div>
<div id="drawingArea" class="drawing-area">
<div class="canvas-container">
<canvas id="tshirt-canvas" width="250" height="400"></canvas>
</div>
</div>
<center>
<button type="button" class="btn btn-dark" onclick="function1()"></button>
<button type="button" class="btn btn-danger" onclick="function2()"></button>
</center>
</div>
</div>
<div class="col-md-4" style="padding: 2% 8%">
<!-- The select that will allow the user to pick one of the static designs -->
<label for="tshirt-design">T-Shirt Logo:</label>
<select id="tshirt-design">
<option value="">Select One of Our Logo</option>
<option value="./batman.png">Batman</option>
</select>
<!-- The Select that allows the user to change the color of the T-Shirt -->
<br><br>
<label for="tshirt-text">T-Shirt Text:</label>
<button type="button" id="tshirt-text" onclick="fun()" style="border: 1px solid black; border-radius: 3px;">Add Text</button>
<br><br>
<!--<label for="tshirt-color">T-Shirt Color:</label>
<select id="tshirt-color">
<option value="#fff">White</option>
<option value="#000">Black</option>
<option value="#f00">Red</option>
<option value="#008000">Green</option>
<option value="#ff0">Yellow</option>
</select>-->
<label for="tshirt-custompicture">Upload Your Own Design:</label>
<input type="file" id="tshirt-custompicture" />
</div>
<div class="col-md-4" style="padding: 2% 1% 2% 0%">
<form class="row g-3">
<div class="col-md-6">
<p style="text-align: center;">Size</p>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="flexCheckDefault1">
<label class="form-check-label" for="flexCheckDefault1">
S
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="flexCheckDefault2">
<label class="form-check-label" for="flexCheckDefault2">
M
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="flexCheckDefault3">
<label class="form-check-label" for="flexCheckDefault3">
L
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="flexCheckDefault4">
<label class="form-check-label" for="flexCheckDefault4">
XL
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="flexCheckDefault5">
<label class="form-check-label" for="flexCheckDefault5">
XXL
</label>
</div>
</div>
<div class="col-md-6">
<p style="text-align: center;">Quantity</p>
<input type="number" class="form-control" id="inputPassword4" placeholder="Enter the Quantity">
</div>
<div class="col-12">
<br>
<center>
<button type="" class="btn btn-primary">Preview</button>
<button type="submit" class="btn btn-primary">Proceed</button></center>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<!-- Include Fabric.js in the page -->
<script src="./fabric.min.js"></script>
<!-- Optional JavaScript; choose one of the two! -->
<!-- Option 1: Bootstrap Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/js/bootstrap.bundle.min.js" integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW" crossorigin="anonymous"></script>
<!-- Option 2: Separate Popper and Bootstrap JS -->
<!--
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.4/dist/umd/popper.min.js" integrity="sha384-q2kxQ16AaE6UbzuKqyBE9/u/KzioAlnx2maXQHiDX9d4/zp8Ok3f+M7DPm+Ib6IU" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/js/bootstrap.min.js" integrity="sha384-pQQkAEnwaBkjpqZ8RU1fF1AKtTcHJwFl3pblpTlHXybJjHpMYo79HY3hIi4NKxyj" crossorigin="anonymous"></script>
-->
<script>
var y=null;
let canvas = new fabric.Canvas('tshirt-canvas');
function updateTshirtImage(imageURL){
fabric.Image.fromURL(imageURL, function(img) {
img.scaleToHeight(300);
img.scaleToWidth(300);
canvas.centerObject(img);
canvas.add(img);
canvas.renderAll();
});
}
// Update the TShirt color according to the selected color by the user
document.getElementById("tshirt-design").addEventListener("change", function(){
document.getElementById("tshirt-backgroundpicture").style.filter = this.value;
}, false);
// Update the TShirt color according to the selected color by the user
document.getElementById("tshirt-design").addEventListener("change", function(){
// Call the updateTshirtImage method providing as first argument the URL
// of the image provided by the select
y= (this.value);
updateTshirtImage(this.value);
}, false);
function fun() {
var x= prompt("Enter The Text:");
var text = new fabric.IText(x, { left: 40, top: 100, color: y });
canvas.add(text);
}
// When the user clicks on upload a custom picture
document.getElementById('tshirt-custompicture').addEventListener("change", function(e){
var reader = new FileReader();
reader.onload = function (event){
var imgObj = new Image();
imgObj.src = event.target.result;
// When the picture loads, create the image in Fabric.js
imgObj.onload = function () {
var img = new fabric.Image(imgObj);
img.scaleToHeight(300);
img.scaleToWidth(300);
canvas.centerObject(img);
canvas.add(img);
canvas.renderAll();
};
};
// If the user selected a picture, load it
if(e.target.files[0]){
reader.readAsDataURL(e.target.files[0]);
}
}, false);
// When the user selects a picture that has been added and press the DEL key
// The object will be removed !
document.addEventListener("keydown", function(e) {
var keyCode = e.keyCode;
if(keyCode == 46){
console.log("Removing selected element on Fabric.js on DELETE key !");
canvas.remove(canvas.getActiveObject());
}
}, false);
function function1() {
document.getElementById("tshirt-backgroundpicture1").style.display="block";
document.getElementById("tshirt-backgroundpicture2").style.display="none";
document.getElementById("tshirt-backgroundpicture3").style.display="none";
document.getElementById("tshirt-backgroundpicture4").style.display="none";
}
function function2() {
document.getElementById("tshirt-backgroundpicture1").style.display="none";
document.getElementById("tshirt-backgroundpicture2").style.display="block";
document.getElementById("tshirt-backgroundpicture3").style.display="none";
document.getElementById("tshirt-backgroundpicture4").style.display="none";
}
function function3() {
document.getElementById("tshirt-backgroundpicture1").style.display="none";
document.getElementById("tshirt-backgroundpicture2").style.display="none";
document.getElementById("tshirt-backgroundpicture3").style.display="block";
document.getElementById("tshirt-backgroundpicture4").style.display="none";
}
function function4() {
document.getElementById("tshirt-backgroundpicture1").style.display="none";
document.getElementById("tshirt-backgroundpicture2").style.display="none";
document.getElementById("tshirt-backgroundpicture3").style.display="none";
document.getElementById("tshirt-backgroundpicture4").style.display="block";
}
</script>
</body>
</html>