@@ -6,22 +6,34 @@ $(document).ready(function () {
66 }
77 window . __githubIssueBound = true ;
88
9+ let currentRenderId = 0 ;
10+
911 $ ( window ) . on ( 'action:ajaxify.end' , renderTopicIssues ) ;
10- if ( window . ajaxify && ajaxify . data ) {
12+ if ( document . readyState === 'complete' && window . ajaxify && ajaxify . data ) {
1113 renderTopicIssues ( ) ;
1214 }
1315
1416 function renderTopicIssues ( ) {
17+ const renderId = ++ currentRenderId ;
1518 $ ( '.github-issue-topic-sidebar' ) . remove ( ) ;
16- if ( ! ajaxify . data || ajaxify . data . template . name !== 'topic' ) {
19+ if ( ! ajaxify . data || ! ajaxify . data . template || ajaxify . data . template . name !== 'topic' ) {
1720 return ;
1821 }
1922 const issues = ajaxify . data . githubIssues ;
2023 if ( ! Array . isArray ( issues ) || ! issues . length ) {
2124 return ;
2225 }
2326 require ( [ 'translator' ] , function ( translator ) {
27+ if ( renderId !== currentRenderId ) {
28+ return ;
29+ }
2430 translator . translate ( '[[github-issue:topic-issues]]|[[github-issue:from-post]]|[[github-issue:state-open]]|[[github-issue:state-closed]]|[[github-issue:state-not-planned]]' , function ( translated ) {
31+ if ( renderId !== currentRenderId ) {
32+ return ;
33+ }
34+ if ( ! ajaxify . data || ! ajaxify . data . template || ajaxify . data . template . name !== 'topic' ) {
35+ return ;
36+ }
2537 const parts = translated . split ( '|' ) ;
2638 const heading = parts [ 0 ] ;
2739 const fromPost = parts [ 1 ] ;
@@ -112,6 +124,7 @@ $(document).ready(function () {
112124 }
113125
114126 function placePanel ( panel ) {
127+ $ ( '.github-issue-topic-sidebar' ) . remove ( ) ;
115128 // harmony's sticky topic sidebar column, hidden below lg
116129 const sticky = $ ( '.sticky-top .flex-column.align-items-end' ) . first ( ) ;
117130 if ( sticky . length ) {
@@ -154,26 +167,33 @@ $(document).ready(function () {
154167 } ) ;
155168
156169 function openDialog ( pid , content , existing , bootbox , alerts , translator ) {
157- const keys = [
158- '[[github-issue:dialog-title]]' ,
159- '[[github-issue:issue-title]]' ,
160- '[[github-issue:issue-body]]' ,
161- '[[github-issue:submit]]' ,
162- '[[modules:bootbox.cancel]]' ,
163- '[[github-issue:created]]' ,
164- '[[github-issue:already-opened]]' ,
165- '[[github-issue:duplicate-title]]' ,
166- '[[github-issue:duplicate-warning]]' ,
167- '[[github-issue:duplicate-suggestion]]' ,
168- '[[github-issue:duplicate-change]]' ,
169- '[[github-issue:duplicate-create-anyway]]' ,
170- '[[github-issue:checking-duplicates]]' ,
171- ] ;
172- Promise . all ( keys . map ( function ( key ) {
170+ const translationKeys = {
171+ dialogTitle : '[[github-issue:dialog-title]]' ,
172+ issueTitle : '[[github-issue:issue-title]]' ,
173+ issueBody : '[[github-issue:issue-body]]' ,
174+ submit : '[[github-issue:submit]]' ,
175+ cancel : '[[modules:bootbox.cancel]]' ,
176+ created : '[[github-issue:created]]' ,
177+ alreadyOpened : '[[github-issue:already-opened]]' ,
178+ duplicateTitle : '[[github-issue:duplicate-title]]' ,
179+ duplicateWarning : '[[github-issue:duplicate-warning]]' ,
180+ duplicateSuggestion : '[[github-issue:duplicate-suggestion]]' ,
181+ duplicateChange : '[[github-issue:duplicate-change]]' ,
182+ duplicateCreateAnyway : '[[github-issue:duplicate-create-anyway]]' ,
183+ checkingDuplicates : '[[github-issue:checking-duplicates]]' ,
184+ creating : '[[github-issue:creating]]' ,
185+ } ;
186+ const keyNames = Object . keys ( translationKeys ) ;
187+ Promise . all ( keyNames . map ( function ( key ) {
173188 return new Promise ( function ( resolve ) {
174- translator . translate ( key , resolve ) ;
189+ translator . translate ( translationKeys [ key ] , resolve ) ;
175190 } ) ;
176- } ) ) . then ( function ( t ) {
191+ } ) ) . then ( function ( results ) {
192+ const t = { } ;
193+ keyNames . forEach ( function ( key , index ) {
194+ t [ key ] = results [ index ] ;
195+ } ) ;
196+
177197 const postUrl = window . location . origin + config . relative_path + '/post/' + encodeURIComponent ( pid ) ;
178198 const defaultTitle = ( ajaxify . data && ( ajaxify . data . titleRaw || ajaxify . data . title ) ) || '' ;
179199 const defaultBody = content + '\n\n---\n' + postUrl ;
@@ -182,7 +202,7 @@ $(document).ready(function () {
182202 if ( existing && existing . url ) {
183203 const warning = $ ( '<div class="alert alert-warning d-flex align-items-center gap-2 mb-3"></div>' ) ;
184204 warning . append ( $ ( '<i class="fa fa-exclamation-triangle"></i>' ) ) ;
185- warning . append ( $ ( '<span></span>' ) . text ( t [ 6 ] ) ) ;
205+ warning . append ( $ ( '<span></span>' ) . text ( t . alreadyOpened ) ) ;
186206 warning . append (
187207 $ ( '<a target="_blank" rel="noopener noreferrer"></a>' )
188208 . attr ( 'href' , existing . url )
@@ -191,11 +211,11 @@ $(document).ready(function () {
191211 form . append ( warning ) ;
192212 }
193213 const titleGroup = $ ( '<div class="mb-3"></div>' ) ;
194- titleGroup . append ( $ ( '<label class="form-label"></label>' ) . text ( t [ 1 ] ) ) ;
214+ titleGroup . append ( $ ( '<label class="form-label"></label>' ) . text ( t . issueTitle ) ) ;
195215 const titleInput = $ ( '<input type="text" class="form-control" maxlength="256">' ) . val ( defaultTitle ) ;
196216 titleGroup . append ( titleInput ) ;
197217 const bodyGroup = $ ( '<div class="mb-3"></div>' ) ;
198- bodyGroup . append ( $ ( '<label class="form-label"></label>' ) . text ( t [ 2 ] ) ) ;
218+ bodyGroup . append ( $ ( '<label class="form-label"></label>' ) . text ( t . issueBody ) ) ;
199219 const bodyInput = $ ( '<textarea class="form-control" rows="12"></textarea>' ) . val ( defaultBody ) ;
200220 bodyGroup . append ( bodyInput ) ;
201221 form . append ( titleGroup ) . append ( bodyGroup ) ;
@@ -204,16 +224,16 @@ $(document).ready(function () {
204224 let confirmedTitle = null ;
205225
206226 const dialog = bootbox . dialog ( {
207- title : t [ 0 ] ,
227+ title : t . dialogTitle ,
208228 message : form ,
209229 onEscape : true ,
210230 buttons : {
211231 cancel : {
212- label : t [ 4 ] ,
232+ label : t . cancel ,
213233 className : 'btn-link' ,
214234 } ,
215235 submit : {
216- label : t [ 3 ] ,
236+ label : t . submit ,
217237 className : 'btn-primary github-issue-submit' ,
218238 // the dialog is closed by hand once the issue is created, so
219239 // that it stays open (with the typed text) on failure and
@@ -228,8 +248,8 @@ $(document).ready(function () {
228248
229249 const submitBtn = dialog . find ( '.github-issue-submit' ) ;
230250
231- function setBusy ( busy ) {
232- submitBtn . prop ( 'disabled' , busy ) . text ( busy ? t [ 11 ] : t [ 3 ] ) ;
251+ function setBusy ( busy , label ) {
252+ submitBtn . prop ( 'disabled' , busy ) . text ( busy ? ( label || t . creating ) : t . submit ) ;
233253 }
234254
235255 function normalize ( value ) {
@@ -247,7 +267,7 @@ $(document).ready(function () {
247267 createIssue ( title , body ) ;
248268 return ;
249269 }
250- setBusy ( true ) ;
270+ setBusy ( true , t . checkingDuplicates ) ;
251271 socket . emit ( 'plugins.githubIssue.findDuplicates' , { title : title } , function ( err , matches ) {
252272 setBusy ( false ) ;
253273 // a failed duplicate check must not block issue creation
@@ -261,7 +281,7 @@ $(document).ready(function () {
261281
262282 function warnDuplicates ( matches , title , body ) {
263283 const message = $ ( '<div></div>' ) ;
264- message . append ( $ ( '<p class="mb-2"></p>' ) . text ( t [ 7 ] ) ) ;
284+ message . append ( $ ( '<p class="mb-2"></p>' ) . text ( t . duplicateWarning ) ) ;
265285 const list = $ ( '<ul class="mb-2"></ul>' ) ;
266286 matches . forEach ( function ( match ) {
267287 list . append (
@@ -273,15 +293,15 @@ $(document).ready(function () {
273293 ) ;
274294 } ) ;
275295 message . append ( list ) ;
276- message . append ( $ ( '<p class="mb-0 text-muted"></p>' ) . text ( t [ 8 ] ) ) ;
296+ message . append ( $ ( '<p class="mb-0 text-muted"></p>' ) . text ( t . duplicateSuggestion ) ) ;
277297
278298 bootbox . dialog ( {
279- title : t [ 6 ] ,
299+ title : t . duplicateTitle ,
280300 message : message ,
281301 onEscape : true ,
282302 buttons : {
283303 change : {
284- label : t [ 9 ] ,
304+ label : t . duplicateChange ,
285305 className : 'btn-primary' ,
286306 callback : function ( ) {
287307 // focus once the confirm dialog has finished closing,
@@ -292,7 +312,7 @@ $(document).ready(function () {
292312 } ,
293313 } ,
294314 createAnyway : {
295- label : t [ 10 ] ,
315+ label : t . duplicateCreateAnyway ,
296316 className : 'btn-link' ,
297317 callback : function ( ) {
298318 confirmedTitle = title ;
@@ -304,7 +324,7 @@ $(document).ready(function () {
304324 }
305325
306326 function createIssue ( title , body ) {
307- setBusy ( true ) ;
327+ setBusy ( true , t . creating ) ;
308328 socket . emit ( 'plugins.githubIssue.create' , {
309329 pid : pid ,
310330 title : title ,
@@ -315,13 +335,13 @@ $(document).ready(function () {
315335 return alerts . error ( err ) ;
316336 }
317337 dialog . modal ( 'hide' ) ;
318- if ( ajaxify . data && ajaxify . data . template . name === 'topic' ) {
338+ if ( ajaxify . data && ajaxify . data . template && ajaxify . data . template . name === 'topic' ) {
319339 ajaxify . data . githubIssues = ( ajaxify . data . githubIssues || [ ] ) . concat ( result ) ;
320340 renderTopicIssues ( ) ;
321341 }
322342 alerts . alert ( {
323343 type : 'success' ,
324- title : t [ 5 ] + ' — #' + result . number ,
344+ title : t . created + ' — #' + result . number ,
325345 message : result . url ,
326346 timeout : 10000 ,
327347 clickfn : function ( ) {
0 commit comments