-
Notifications
You must be signed in to change notification settings - Fork 1
/
bitmoji.html
211 lines (189 loc) · 6.4 KB
/
bitmoji.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
<!DOCTYPE html>
<html>
<head>
<title>Bitmoji Generator</title>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://unpkg.com/tooltip.js/dist/umd/tooltip.min.js"></script>
<script src="https://unpkg.com/popper.js/dist/umd/popper.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" />
<style>
body {
font-family: Arial, sans-serif;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
.card {
margin: 20px 0;
border: none;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
}
.card-header {
background-color: #007bff;
color: #fff;
}
.card-body {
padding: 20px;
}
.form-group {
margin-bottom: 20px;
}
.form-control {
width: 100%;
}
.comic-img-container {
position: relative;
display: inline-block;
margin: 5px;
}
.comic-img-container img {
display: block;
max-width: 100%;
height: auto;
}
.comic-img-overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
color: white;
display: none;
justify-content: center;
align-items: center;
text-align: center;
cursor: pointer;
}
.comic-img-container:hover .comic-img-overlay {
display: flex;
}
.download-button {
cursor: pointer;
}
.download-button a {
color: white;
text-decoration: none;
}
#loading {
display: none;
}
</style>
</head>
<body>
<div class="container mt-3">
<div class="card">
<div class="card-header">
<h2>Bitmoji Generator</h2>
</div>
<div class="card-body">
<div class="form-group">
<input type="text" id="tag-search" class="form-control" placeholder="Search tags..." onkeyup="searchFilter()" />
</div>
<div id="container" class="row"></div>
<div id="loading" class="text-center mt-3">
<div class="spinner-border text-primary" role="status">
<span class="sr-only">Loading...</span>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
var searchFilter = function () {};
function getUrlParams(prop) {
var params = {};
var search = decodeURIComponent(window.location.href.slice(window.location.href.indexOf("?") + 1));
var definitions = search.split("&");
definitions.forEach(function (val, key) {
var parts = val.split("=", 2);
params[parts[0]] = parts[1];
});
return prop && prop in params ? params[prop] : "";
}
$(function () {
var firstID = getUrlParams("firstid");
if (firstID == "") {
alert('You must assign both a url param for "firstid"');
return false;
}
var lastImageIndex = 0;
// var displayImages = function (comicData, endIndex) {
// if (endIndex < comicData["imoji"].length) {
// $.each(comicData["imoji"].slice(lastImageIndex, endIndex), function (_, comicInfo) {
// var imgURL = comicInfo.src.replace("%s", firstID);
// var imgContainer = $("<div class='comic-img-container'></div>");
// var imgElement = $("<img src='" + imgURL + "' width='100' data-tags='" + comicInfo.tags + "'/>");
// var overlay = $("<div class='comic-img-overlay'><div class='download-button'><a href='" + imgURL + "' download='image.jpg'>Download</a></div></div>");
// imgContainer.append(imgElement).append(overlay);
// $("#container").append(imgContainer);
// });
// } else {
// console.log("All images loaded");
// }
// lastImageIndex = endIndex;
// }
var displayImages = function (comicData, endIndex) {
if (endIndex < comicData["imoji"].length) {
$.each(comicData["imoji"].slice(lastImageIndex, endIndex), function (_, comicInfo) {
var imgURL = comicInfo.src.replace("%s", firstID);
var imgContainer = $("<div class='comic-img-container' data-tags='" + comicInfo.tags + "'></div>");
var imgElement = $("<img src='" + imgURL + "' width='100' />");
var overlay = $(
"<div class='comic-img-overlay'><div class='download-button'><a href='" +
imgURL +
"' target='_blank'>" +
comicInfo.alt_text +
"</a></div></div>"
);
imgContainer.append(imgElement).append(overlay);
$("#container").append(imgContainer);
});
} else {
console.log("All images loaded");
}
lastImageIndex = endIndex;
};
var activeImages = 0;
var waitToLoad = 0;
$.getJSON("api.json", function (data) {
displayImages(data, 80);
searchFilter = function () {
displayImages(data, data["imoji"].length - 1);
var searchTerm = $("#tag-search").val();
$(".comic-img-container").each(function (_, comicElem) {
var display = 0;
if (searchTerm == "") {
$(this).show();
return true;
}
tags = $(this).attr("data-tags");
$.each(tags.split(","), function (_, tag) {
if (tag.includes(searchTerm)) {
display = 1;
return false;
}
});
if (display == 0) {
$(this).hide();
} else {
$(this).show();
}
});
};
$(window).scroll(function () {
if ($(window).scrollTop() + screen.height >= $("#container").height() && !waitToLoad) {
displayImages(data, lastImageIndex + 40);
waitToLoad = 1;
setTimeout(function () {
waitToLoad = 0;
}, 250);
}
});
});
});
</script>
</body>
</html>