-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy patheditor.html
241 lines (205 loc) · 7.71 KB
/
editor.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
<html style="background-color: #0a0f14">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<title>Mixmax · Giphy</title>
<!-- Mixmax SDK -->
<script defer src="https://d1xa36cy0xt122.cloudfront.net/v1/Mixmax.js"></script>
<link rel="stylesheet" href="/styles.css">
<link href='//fonts.googleapis.com/css?family=Merriweather:400,700,400italic,700italic,900,900italic,300italic,300' rel='stylesheet' type='text/css'>
<script src="//code.jquery.com/jquery-2.1.3.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.2/underscore-min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.2/backbone-min.js"></script>
<script src="/lib/masonry.js"></script>
</head>
<body data-current-theme="gmail">
<div class="app-popup app-giphy">
<div class="toolbar text--reverse text--caps toolbar--app ui-face flexbox">
<div class="toolbar__title flex-fill">
<form class="search">
<input class="search-field js-giphy-search" autofocus type="text" placeholder="Search giphy" value="">
<button type="submit" class="js-search-gifs btn btn--pill text--caps search-button"><i class="fa fa-search"></i></button>
</form>
</div>
<div class="giphy-branding">
<img src="/img/giphy.gif" width="240">
</div>
</div>
<div class="js-image-gallery image-gallery softest">
<div class="js-image-results image-results">
</div>
<ul class="spinner-bokeh hidden">
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
</div>
<script>
var GiphyEditor = Backbone.View.extend({
// The current XHR search request.
_currentXhr: null,
_currentImages: null,
// This is the public API key from https://github.com/giphy/GiphyAPI. Replace with yours!
_apiKey: 'dc6zaTOxFJmzC',
events: {
'click .js-gif': '_done',
'click .js-search-gifs': '_search',
'submit .js-search-gifs': '_search',
'mouseenter .js-gif': '_play',
'mouseleave .js-gif': '_pause'
},
render: function() {
var self = this,
body = document.body,
gallery = $('.js-image-results'),
timer;
this._currentImages = [];
// Show loading spinner
$('.spinner-bokeh').removeClass('hidden');
// Disable pointer events while scrolling to improve performance.
$(window).on('scroll', function() {
clearTimeout(timer);
if(!body.classList.contains('disable-hover')) {
body.classList.add('disable-hover')
}
timer = setTimeout(function(){
body.classList.remove('disable-hover')
},300);
}, false);
gallery.masonry({
itemSelector: 'figure',
columnWidth: function() {
return gallery.width() / 3;
}
});
this._currentXhr = $.ajax({
url:'https://api.giphy.com/v1/gifs/trending?api_key=' + this._apiKey + '&limit=100',
success:function(result){
if (result.data.length > 0) {
$(result.data).each(function(index, result) {
var gifStillUrl = result.images.downsized_still.url;
var gifAnimatedUrl = result.images.downsized.url;
var gifAnimatedFullUrl = result.images.original.url;
var gifAnimatedFullWidth = result.images.original.width;
self._loadImage(gifStillUrl, gifAnimatedUrl, gifAnimatedFullUrl, gifAnimatedFullWidth, gallery);
});
}
}
});
},
_done: function(e) {
var target = $(e.target);
var gif = target.attr('data-gif-animated-full');
var width = target.attr('data-gif-animated-full-width');
// Let Mixmax know it was done.
Mixmax.done({
src: gif,
width: width
});
},
_cancel: function() {
Mixmax.cancel();
},
_search: function(e) {
e.preventDefault();
var self = this,
term = $('.js-giphy-search').val(),
gallery = $('.js-image-results');
// Cancel last Ajax request
if (this._currentXhr) this._currentXhr.abort();
// Clear images any images currently loading
if (this._currentImages) {
var currentImages = $(this._currentImages);
currentImages.each(function(index, image){
image.src = '';
image.onload = null;
});
currentImages = [];
}
$('.spinner-bokeh').removeClass('hidden');
$('.js-no-results').remove();
gallery.empty().masonry().masonry('remove', gallery.find('.js-gif'));
gallery.masonry().masonry('destroy');
gallery.masonry({
itemSelector: 'figure',
columnWidth: function() {
return gallery.width() / 3;
}
});
this._currentXhr = $.ajax({
url:'https://api.giphy.com/v1/gifs/search?q=' + encodeURIComponent(term) + '&api_key=' + this._apiKey + '&limit=100',
success:function(result){
if (result.data.length > 0) {
$(result.data).each(function(index, result) {
var gifStillUrl = result.images.downsized_still.url;
var gifAnimatedUrl = result.images.downsized.url;
var gifAnimatedFullUrl = result.images.original.url;
var gifAnimatedFullWidth = result.images.original.width;
self._loadImage(gifStillUrl, gifAnimatedUrl, gifAnimatedFullUrl, gifAnimatedFullWidth, gallery);
});
} else {
$('.spinner-bokeh').addClass('hidden');
var phrase = term.length == 0 ? 'for you' : 'for <strong>“' + term + '”</strong>'
var noResultsHTML = $('<div class="js-no-results text--reverse m++ p++">'
+ '<h2 class="text--normal mb++">We couldn’t find any results ' + phrase + ', but we did find Taylor Lautner.</h2>'
+ '<img src="' + Environment.getRootUrl() +'/img/giphy/taylor.gif"></div>');
noResultsHTML.hide();
gallery.append(noResultsHTML);
noResultsHTML.fadeIn(150);
}
}
});
},
_loadImage: function(gifStillUrl, gifAnimatedUrl, gifAnimatedFullUrl, gifAnimatedFullWidth, container){
var imgStill = new Image();
var imgAnimated = new Image();
var el = $('<figure><img '
+ 'data-gif-animated="' + gifAnimatedUrl + '" '
+ 'data-gif-animated-full="' + gifAnimatedFullUrl + '" '
+ 'data-gif-animated-full-width="' + gifAnimatedFullWidth + '" '
+ 'class="js-gif" src="' + gifStillUrl + '"></figure>');
el.hide();
container.append(el);
imgStill.onload = function(){
imgStill.loaded = true;
loadIfDone();
};
imgAnimated.onload = function(){
imgAnimated.loaded = true;
loadIfDone();
};
imgStill.src = gifStillUrl;
imgAnimated.src = gifAnimatedUrl;
this._currentImages.push(imgStill, imgAnimated);
function loadIfDone(){
if (!imgStill.loaded || !imgAnimated.loaded) return;
container.masonry( 'appended', el ).fadeIn();
el.fadeIn(200);
$('.spinner-bokeh').addClass('hidden');
}
},
_play: function(e) {
var target = $(e.target);
var gifStill = target.attr('src');
var gifAnimated = target.data('gifAnimated');
target.attr('src', gifAnimated);
target.data('gifStill', gifStill);
},
_pause: function(e) {
var target = $(e.target);
var gifStill = target.data('gifStill');
var gifAnimated = target.attr('src');
target.attr('src', gifStill);
target.data('gifAnimated', gifAnimated);
}
});
// Create
new GiphyEditor({
el: document.body
}).render();
</script>
</body>
</html>