-
Notifications
You must be signed in to change notification settings - Fork 0
/
reactions.js
178 lines (146 loc) · 5.17 KB
/
reactions.js
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
(function(window) {
var reactionFrameHtml;
var gifProvider = new GifProvider(true);
var $lastGifImg;
$.get(chrome.extension.getURL('/reactions.html'), function(data) {
reactionFrameHtml = data;
console.debug('Retrieved reactions html');
});
// Start code for EVENTS
var onClickPreviewGif = function(evt) {
var gifId = $(this).data('id');
var $gifContainer = $('#r-gif-container');
$gifContainer.find('.gif-container-overlay').addClass('show');
var gif = gifProvider.findById( gifId );
$gifContainer.find('.gif-container-overlay img').attr('src', gifProvider.getImagePathFor(gif));
$gifContainer.find('.gif-inner-container').hide();
$gifContainer.find('#gif-overlay-use').data('id', gifId);
$lastGifImg = $(this);
console.debug('onClickPreviewGif()');
}
var onClickGifPreviewOverlay = function(evt) {
// Fired when you exit the preview screen for a gif
$('#r-gif-container .gif-inner-container').show();
$('#r-gif-container .gif-container-overlay').removeClass('show');
// Shows a bouncy animation to highlight the last GIF the user just viewed
var lastGif = $lastGifImg;
lastGif.addClass('bounce').one('webkitAnimationEnd', function() {
lastGif.removeClass('bounce');
});
}
var onClickGifPost = function(evt) {
var gifId = $(this).data('id');
var gif = gifProvider.findById(gifId);
var imgurLink = gif.link;
var textarea = evt.data.textarea;
var prepare = evt.data.prepare;
// TODO: Uncomment when ready
// CommentInjector.addPost( imgurLink );
prepare();
textarea.text(imgurLink);
textarea.removeClass("DOMControl_placeholder");
hideReactionsPanel();
}
var onClickCreate = function(evt) {
$('#video-container').show();
Uploader.prepare();
// Add a small delay for the webcam to get ready
setTimeout(function() {
Uploader.recordAndUpload(function(imgurLink, localLink) {
console.debug('Gif uploaded to: ' + imgurLink);
$('#video-source').hide();
$('#video-preview').attr('src', localLink).show();
$('#video-preview').css("display", "block");
$('.r-timer-bar-text').text('Done!');
// Bad solution, but okay for now
$('.r-timer-bar-text').click(function() {
Uploader.cleanup();
evt.data.prepare();
evt.data.textarea.text(imgurLink);
evt.data.textarea.removeClass("DOMControl_placeholder");
hideReactionsPanel();
});
});
}, 500);
}
var setupEvents = function(data) {
var data = {
prepare: data.prepare,
textarea: data.textarea,
};
$('body').on('click', '#r-gif-container .gif-inner-container .r-img', onClickPreviewGif);
$('body').on('click', '#r-gif-container .gif-container-overlay', onClickGifPreviewOverlay);
$('body').on('click', '#r-gif-container #gif-overlay-use', data, onClickGifPost);
$('body').on('click', '#create-gif', data, onClickCreate);
}
// End code for EVENTS
function hideReactionsPanel() {
$('.r-panel').stop(0, 0).fadeOut(250, function() {
$('.r-background').fadeOut(250, function() {
$('.r-background').remove();
$('#r-panel').remove();
$(window).off('keyup').off('mousedown');
$('body').removeClass('stop-scrolling');
});
});
console.debug('hideReactionsPanel()');
}
function showAllTags() {
$('#r-tag-container').slideDown();
$('#r-tag-disgust').click(function() {
$('#r-tag-container').slideUp(400, function() {
$('#r-gif-container').slideDown();
var gifs = gifProvider.get('disgust');
var imageHtml = '';
gifs.forEach(function(gif) {
var imgSrc = gifProvider.getPreviewImagePathFor( gif );
imageHtml += '<img src="' + imgSrc + '" class="r-img" data-id="' + gif.id + '" />';
});
$('#r-gif-container .gif-inner-container').html(imageHtml);
});
});
}
function showReactionsPanel(data) {
$('body').addClass('stop-scrolling').append(reactionFrameHtml);
Uploader.prepare();
/*
$('#create-gif').click(function() {
Uploader.init(function(data) {
if (data) {
var url = 'https://imgur.com/gallery/' + data;
prepare();
input.text(url);
hideReactionsPanel();
}
});
});
*/
$('.r-background').fadeIn(250, function() {
$('.r-panel').fadeIn(250, function() {
$('#r-search').click(function() {
$('#r-search').addClass('selected');
showAllTags();
});
$(window).on('keyup', function(evt) {
if (evt.keyCode === 27) {
hideReactionsPanel();
}
});
$(window).on('mousedown', function(evt) {
// Hide panel if they click anywhere outside the panel
if ($(evt.target).closest('.r-panel').length === 0) {
hideReactionsPanel();
}
});
console.debug('showReactionsPanel()');
});
});
}
$(document).ready(function() {
var pageListener = new FBPageListener();
pageListener.init(function(event) {
setupEvents(event.data);
showReactionsPanel(event.data);
});
});
})(this);