-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
299 lines (276 loc) · 8.9 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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
---
layout: default
---
{% assign perPage = 8 %}
{% assign memeTemplates = site.meme-templates | sort: 'template_id' | reverse %}
<!-- infinity scroll script -->
<script>
$(function() {
var memeTemplates = [{% for item in memeTemplates %}{
title: '{{ item.title | replace: "'", "\\'" }}',
url: '{{ item.url }}',
template_id: '{{ item.template_id }}'
},{% endfor %}];
var foundMemeTemplates = memeTemplates;
var perPage = {{ perPage }};
var loadedNum = perPage;
var scrollThreshold = 300;
var shouldLoadOnScroll = false;
var $previews = $('.js-previews');
var $loadMoreBtn = $('.js-load-more');
$loadMoreBtn.on('click', function(e) {
e.preventDefault();
loadMemeTemplates();
$loadMoreBtn.hide();
shouldLoadOnScroll = true;
});
$(window).scroll(function() {
if (!shouldLoadOnScroll) return;
var windowHeight = $(window).height(),
windowScrollPosition = $(window).scrollTop(),
bottomScrollPosition = windowHeight + windowScrollPosition,
documentHeight = $(document).height();
// If we've scrolled past the scrollThreshold, fetch memeTemplates
if ((documentHeight - scrollThreshold) < bottomScrollPosition) {
loadMemeTemplates();
}
});
var $searchInput = $('.js-search-input');
$searchInput.on('input', search);
$('.js-search-form').on('submit', function(e) {
e.preventDefault();
});
function loadMemeTemplates() {
if (loadedNum >= foundMemeTemplates.length) {
shouldLoadOnScroll = false;
return;
}
for (var i = 0; i < perPage; i++) {
var data = foundMemeTemplates[loadedNum];
if (!data) {
break;
}
appendMemeTemplates(data);
loadedNum++;
}
}
function appendMemeTemplates(data) {
var html = tmpl('tmpl-meme-template-preview', data);
$previews.append(html);
}
var $searchErrorLabel = $('.js-search-error');
function search() {
$searchErrorLabel.hide();
var text = $searchInput.val().trim();
if (text.length === 0) {
foundMemeTemplates = memeTemplates
} else {
var re = new RegExp(text, 'i');
foundMemeTemplates = memeTemplates.filter(function(item) {
return item.title.match(re);
});
}
showFoundMemes();
}
function showFoundMemes() {
$previews.empty();
loadedNum = 0;
shouldLoadOnScroll = false;
if (foundMemeTemplates.length === 0) {
$searchErrorLabel.text('Nothing found :(').show();
} else {
loadMemeTemplates();
}
if (foundMemeTemplates.length > perPage) {
$loadMoreBtn.show();
} else {
$loadMoreBtn.hide();
}
scrollToMemeTemplateList();
}
var $memeTemplateList = $('.js-meme-template-list');
var $htmlBody = $('html, body');
function scrollToMemeTemplateList() {
$htmlBody.animate({
scrollTop: $memeTemplateList.offset().top
}, 0);
}
var searchInterval;
var searchDots;
var $clearImageSearch = $('.js-clear-image-search');
var $clearImageSearchName = $clearImageSearch.find('.js-name');
if (!$.support.fileInput) {
$('.js-image-search-btn').hide();
}
$('.js-image-search-input').fileupload({
url: 'https://bot-search.meming.world/search',
dataType: 'json',
paramName: 'meme',
autoUpload: false,
add: function(e, data) {
var limit = 5 * 1024 * 1024;
if (data.files[0] && data.files[0]['size'] > limit) {
return showError('File is too large. Maximum file size is 5MB.');
}
data.submit();
},
start: function() {
$searchInput.prop('disabled', true).show();
$clearImageSearch.hide();
searchDots = '...';
$searchInput.val('Searching' + searchDots);
searchInterval = setInterval(function() {
searchDots += '.'
if (searchDots.length > 3) {
searchDots = '.'
}
$searchInput.val('Searching' + searchDots);
}, 500);
},
done: function(e, data) {
$searchErrorLabel.hide();
foundMemeTemplates = data.result.data.map(function(item) {
return memeTemplates.filter(function(meme) {
return meme.template_id === item.id;
})[0];
});
showFoundMemes();
},
fail: function(e, data) {
var errorMessage = data.errorThrown;
if (data.jqXHR.responseJSON && data.jqXHR.responseJSON.message) {
errorMessage = data.jqXHR.responseJSON.message;
}
showError(errorMessage);
},
always: function(e, data) {
clearInterval(searchInterval);
$searchInput.hide();
$clearImageSearchName.text(data.files[0].name || 'image.jpg');
$clearImageSearch.show();
}
});
function showError(errorMessage) {
$previews.empty();
loadedNum = 0;
shouldLoadOnScroll = false;
$loadMoreBtn.hide();
scrollToMemeTemplateList();
$searchErrorLabel.text(errorMessage).show();
}
$clearImageSearch.on('click', function() {
$clearImageSearch.hide();
$searchInput.val('').prop('disabled', false).show();
search();
});
var $slick = $('#tutorial-slick');
var tutorialSend = $('#tutorial-send')[0];
var tutorialAdd = $('#tutorial-add')[0];
$slick.on('init', function() {
$slick.addClass('visible')
tutorialSend.play()
});
$slick.on('afterChange', function(e, slick, slide) {
if (slide == 0) {
tutorialSend.play()
tutorialAdd.pause()
tutorialAdd.currentTime = 0
} else if (slide == 1) {
tutorialAdd.play()
tutorialSend.pause()
tutorialSend.currentTime = 0
}
});
$slick.slick({
draggable: false,
swipe: false,
infinite: false,
touchMove: false,
adaptiveHeight: true
});
});
</script>
{% raw %}
<script type="text/x-tmpl" id="tmpl-meme-template-preview">
<article class="meme-template-preview">
<div class="meme-template-name">
<a class="meme-template-link" href="{%#o.url%}">{%#o.title%}</a>
</div>
<a class="meme-template-thumb" href="{%#o.url%}">
<img src="/assets/templates/{%#o.template_id%}/thumb.jpg" alt="{%#o.title%}">
</a>
<a href="https://t.me/memingbot?start={%#o.template_id%}" target="_blank" class="btn-add-meme">
add template <i class="icon-paper-plane"></i>
</a>
</article>
</script>
{% endraw %}
<div class="about-container">
<img class="profile-picture" src="/assets/img/ava.svg">
<hr>
<p class="light italic small">Hi, I am a simple meme generator for <a href="https://telegram.org/">telegram</a>. This is how I do.</p>
<hr>
<div id="tutorial-slick">
<div>
<div class="tutorial-wrapper">
<video id="tutorial-send" autoplay loop muted playsinline>
<source src="/assets/tutorial/send.mp4" type="video/mp4">
<source src="/assets/tutorial/send.webm" type="video/webm">
</video>
</div>
<p>
Enter @memingbot, enter meme's text and I'll create a funny picture. <br>
For example: <span class="highlight-span">@memingbot hello. bro!</span>
</p>
</div>
<div>
<div class="tutorial-wrapper">
<video id="tutorial-add" autoplay loop muted playsinline>
<source src="/assets/tutorial/add.mp4" type="video/mp4">
<source src="/assets/tutorial/add.webm" type="video/webm">
</video>
</div>
<p>
Add your own templates. <br>
Send me <span class="highlight-span">/add</span> and I will help you.
</p>
</div>
</div>
<a href="https://t.me/memingbot" target="_blank" class="btn-send-meme">
send meme <i class="icon-paper-plane"></i>
</a>
</div>
<section class="js-meme-template-list meme-template-list">
<div class="container">
<h1 class="page-heading">Meme Templates</h1>
<form class="js-search-form search-form">
<div class="clear-image-search js-clear-image-search" style="display: none;">
<span class="name js-name"></span>
<div class="cancel"><i class="icon-cancel"></i></div>
</div>
<input class="js-search-input" type="text" placeholder="Search..." value="" autocomplete="off">
<div class="btn first js-image-search-btn">
<i class="icon-camera"></i>
<input class="js-image-search-input" type="file" accept="image/*">
</div>
<div class="btn second"><i class="icon-search"></i></div>
</form>
<ul class="js-previews">
{% for item in memeTemplates limit: perPage %}
<article class="meme-template-preview">
<div class="meme-template-name">
<a class="meme-template-link" href="{{ item.url }}">{{ item.title }}</a>
</div>
<a class="meme-template-thumb" href="{{ item.url }}">
<img src="/assets/templates/{{ item.template_id }}/thumb.jpg" alt="{{ item.title }}">
</a>
<a href="https://t.me/memingbot?start={{ item.template_id }}" target="_blank" class="btn-add-meme">
add template <i class="icon-paper-plane"></i>
</a>
</article>
{% endfor %}
</ul>
<a class="js-load-more" href="">LOAD MORE</a>
<div class="js-search-error" style="display: none;"></div>
</div>
</section>