@@ -13,10 +13,7 @@ import LoadingIndicator from './components/loading-indicator.js'
13
13
import GiphyToolbarItem from './components/giphy-toolbar-item.js'
14
14
import Giphy from './lib/giphy.js'
15
15
16
- import {
17
- onDiffFileLoad ,
18
- onCommentEdit
19
- } from './lib/github-events/on-fragment-load.js'
16
+ import observe from './lib/selector-observer.js'
20
17
21
18
// Create a new Giphy Client
22
19
const giphyClient = new Giphy ( 'Mpy5mv1k9JRY2rt7YBME2eFRGNs7EGvQ' )
@@ -36,6 +33,7 @@ async function watchGiphyModals(element) {
36
33
37
34
// If the modal has been opened and there is no search term,
38
35
// and no search results, load the trending gifs
36
+ console . log ( resultsContainer . dataset . hasResults , searchInput . value )
39
37
if (
40
38
searchInput . value === '' &&
41
39
resultsContainer . dataset . hasResults === 'false'
@@ -65,7 +63,6 @@ async function watchGiphyModals(element) {
65
63
columnWidth : 145 ,
66
64
gutter : 10 ,
67
65
transitionDuration : '0.2s'
68
- // FitWidth: true
69
66
} ,
70
67
2000
71
68
) ,
@@ -82,6 +79,7 @@ function addToolbarButton() {
82
79
'form:not(.ghg-has-giphy-field) markdown-toolbar'
83
80
) ) {
84
81
const form = toolbar . closest ( 'form' )
82
+
85
83
const reviewChangesModal = toolbar . closest (
86
84
'#review-changes-modal .SelectMenu-modal'
87
85
)
@@ -111,8 +109,16 @@ function addToolbarButton() {
111
109
if ( toolbarGroup ) {
112
110
// Append the Giphy button to the toolbar
113
111
// cloneNode is necessary, without it, it will only be appended to the last toolbarGroup
114
- toolbarGroup . append ( GiphyToolbarItem . cloneNode ( true ) )
112
+ const clonedNode = GiphyToolbarItem . cloneNode ( true )
113
+ toolbarGroup . append ( clonedNode )
114
+ select ( '.ghg-giphy-results' , clonedNode )
115
+
115
116
form . classList . add ( 'ghg-has-giphy-field' )
117
+
118
+ // Clears the gif search input field and results.
119
+ // We have to do this because when navigating, github will refuse to
120
+ // load the giphy URLs as it violates their Content Security Policy.
121
+ resetGiphyModals ( )
116
122
}
117
123
} )
118
124
}
@@ -122,11 +128,7 @@ function addToolbarButton() {
122
128
* Watches for comments that might be dynamically added, then adds the button the the WYSIWYG when they are.
123
129
*/
124
130
function observeDiscussion ( ) {
125
- const discussionTimeline = select ( '.js-discussion' )
126
-
127
- observeEl ( discussionTimeline , ( ) => {
128
- addToolbarButton ( )
129
- } )
131
+ observe ( 'md-task-list' , ( ) => addToolbarButton ( ) )
130
132
}
131
133
132
134
/**
@@ -137,6 +139,7 @@ function resetGiphyModals() {
137
139
for ( const ghgModal of select . all ( '.ghg-modal' ) ) {
138
140
const resultContainer = select ( '.ghg-giphy-results' , ghgModal )
139
141
const searchInput = select ( '.ghg-search-input' , ghgModal )
142
+ console . log ( { resultContainer} )
140
143
searchInput . value = ''
141
144
resultContainer . innerHTML = ''
142
145
resultContainer . dataset . offset = 0
@@ -207,7 +210,6 @@ function getFormattedGif(gif) {
207
210
)
208
211
209
212
// Generate a random pastel colour to use as an image placeholder
210
-
211
213
const hsl = `hsl(${ 360 * Math . random ( ) } , ${ 25 + 70 * Math . random ( ) } %,${
212
214
85 + 10 * Math . random ( )
213
215
} %)`
@@ -245,18 +247,19 @@ function appendResults(resultsContainer, gifs) {
245
247
resultsContainer . append ( img )
246
248
}
247
249
248
- // eslint-disable-next-line no-new
249
- new Masonry (
250
- resultsContainer ,
251
- {
252
- itemSelector : '.ghg-giphy-results div' ,
253
- columnWidth : 145 ,
254
- gutter : 10 ,
255
- transitionDuration : '0.2s'
256
- // FitWidth: true
257
- } ,
258
- 2000
259
- )
250
+ setTimeout ( ( ) => {
251
+ // eslint-disable-next-line no-new
252
+ new Masonry (
253
+ resultsContainer ,
254
+ {
255
+ itemSelector : '.ghg-giphy-results div' ,
256
+ columnWidth : 145 ,
257
+ gutter : 10 ,
258
+ transitionDuration : '0.2s'
259
+ } ,
260
+ 10
261
+ )
262
+ } )
260
263
}
261
264
262
265
/**
@@ -350,6 +353,7 @@ function listen() {
350
353
// The `open` attribute is added after this handler is run,
351
354
// so the selector is inverted
352
355
delegate ( '.ghg-trigger:not([open]) > summary' , 'click' , ( event ) => {
356
+ console . log ( 'clicked?' , event . delegateTarget )
353
357
// What comes after <summary> is the dropdown
354
358
watchGiphyModals ( event . delegateTarget )
355
359
} )
@@ -361,14 +365,6 @@ const listenOnce = onetime(listen)
361
365
// GitHubInjection fires when there's a pjax:end event
362
366
// on github, this happens when a page is loaded
363
367
gitHubInjection ( ( ) => {
364
- addToolbarButton ( )
365
368
listenOnce ( )
366
369
observeDiscussion ( )
367
- onDiffFileLoad ( addToolbarButton )
368
- onCommentEdit ( addToolbarButton )
369
-
370
- // Clears all gif search input fields and results.
371
- // We have to do this because when navigating, github will refuse to
372
- // load the giphy URLs as it violates their Content Security Policy.
373
- resetGiphyModals ( )
374
370
} )
0 commit comments