-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
114 lines (111 loc) · 5.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ImgCheckBox</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/normalize.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link rel="shortcut icon" href="https://carry0987.github.io/favicon.png" type="image/x-icon">
</head>
<body>
<div class="d-flex flex-column justify-content-center align-items-center">
<div id="app">
<h1 class="mb-3">ImgCheckBox</h1>
</div>
<!--//Number of selected images//-->
<div class="d-flex flex-row justify-content-center align-items-center">
<div class="d-flex flex-column justify-content-center align-items-center">
<h4>Number of selected images:</h4>
<div id="selectedImages">0</div>
</div>
</div>
<div class="d-flex justify-content-center">
<div id="imgList" class="d-flex flex-row justify-content-evenly">
<div class="image">
<!-- Added h-100 and w-100 so that the image is resized in proportion. -->
<img src="img/meme-1.jpg" alt="image" class="img-fluid" style="max-width: 100px;">
</div>
<div class="image mx-3">
<img src="img/meme-2.jpg" alt="image" class="img-fluid" style="max-width: 100px;">
</div>
<div class="image">
<img src="img/meme-3.jpg" alt="image" class="img-fluid" style="max-width: 100px;">
</div>
</div>
</div>
<div class="d-flex flex-column justify-content-center align-items-center mt-4">
<form id="imgCheckBoxForm">
<fieldset>
<legend>Form Test</legend>
<div class="d-flex flex-row justify-content-evenly">
<div class="image">
<img name="images[]" data-id="1" src="img/meme-1.jpg" alt="image" class="img-fluid" style="max-width: 100px;">
</div>
<div class="image mx-3">
<img name="images[]" data-id="2" src="img/meme-2.jpg" alt="image" class="img-fluid" style="max-width: 100px;">
</div>
<div class="image">
<img name="images[]" data-id="3" src="img/meme-3.jpg" alt="image" class="img-fluid" style="max-width: 100px;">
</div>
</div>
</fieldset>
<button type="submit" class="btn btn-primary mt-3">Submit</button>
</form>
</div>
</div>
<script src="dist/imgCheckBox.min.js"></script>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', () => {
const imgCheckBox = new ImgCheckBox('#imgList img', {
graySelected: false,
scaleSelected: true,
checkMarkPosition: 'center',
checkMarkSize: '50px',
styles: {
'span.imgCheckbox img': { 'border-radius': '0px' },
'.image-box .image-layer ~ .imgChked': { 'background-color': 'transparent' }
}
});
imgCheckBox.on('change', (el, checked) => {
console.log('Fake', imgCheckBox.getChecked());
});
imgCheckBox.clearListener('change');
imgCheckBox.on('change', (el, checked) => {
console.log('Change', imgCheckBox.getChecked());
const selectedImages = document.getElementById('selectedImages');
selectedImages.innerHTML = parseInt(imgCheckBox.getChecked().length);
});
imgCheckBox.on('selectAll', (els) => {
console.log('Select All', els);
});
imgCheckBox.selectAll();
const imgCheckBoxForm = new ImgCheckBox('#imgCheckBoxForm img', {
scaleSelected: true,
checkMarkPosition: 'center',
checkMarkSize: '50px',
addToForm: true,
inputValueAttribute: 'data-id',
radio: false,
preselect: [0, 2],
styles: {
'span.imgCheckbox img': { 'border-radius': '0px' },
'.image-box .image-layer ~ .imgChked': { 'background-color': 'transparent' }
}
});
document.getElementById('imgCheckBoxForm').addEventListener('submit', function(e) {
e.preventDefault();
// Create FormData from the form
const formData = new FormData(this);
// Use Array.from() to convert the entries iterator to an array for easier logging
const formDataEntries = Array.from(formData.entries());
console.log('Form Data:', formDataEntries);
// Now, pretty print each key-value pair
formDataEntries.forEach(([key, value]) => {
console.log(`${key}: ${value}`);
});
});
});
</script>
</body>
</html>