@@ -6,6 +6,7 @@ import 'jquery.are-you-sure';
6
6
import './publicPath.js' ;
7
7
import './polyfills.js' ;
8
8
import './vendor/semanticDropdown.js' ;
9
+ import { svg } from './utils.js' ;
9
10
10
11
import initContextPopups from './features/contextPopup.js' ;
11
12
import initHighlight from './features/highlight.js' ;
@@ -14,17 +15,13 @@ import initClipboard from './features/clipboard.js';
14
15
15
16
import ActivityTopAuthors from './components/ActivityTopAuthors.vue' ;
16
17
18
+ const { AppSubUrl, StaticUrlPrefix } = window . config ;
19
+
17
20
function htmlEncode ( text ) {
18
21
return jQuery ( '<div />' ) . text ( text ) . html ( ) ;
19
22
}
20
23
21
- function svg ( name , size ) {
22
- return `<svg class="svg ${ name } " width="${ size } " height="${ size } " aria-hidden="true"><use xlink:href="${ staticPrefix } /img/svg/icons.svg#${ name } "/></svg>` ;
23
- }
24
-
25
24
let csrf ;
26
- let suburl ;
27
- let staticPrefix ;
28
25
let previewFileModes ;
29
26
let simpleMDEditor ;
30
27
const commentMDEditors = { } ;
@@ -157,7 +154,7 @@ function initRepoStatusChecker() {
157
154
}
158
155
$ . ajax ( {
159
156
type : 'GET' ,
160
- url : `${ suburl } /${ repo_name } /status` ,
157
+ url : `${ AppSubUrl } /${ repo_name } /status` ,
161
158
data : {
162
159
_csrf : csrf ,
163
160
} ,
@@ -293,7 +290,7 @@ function uploadFile(file, callback) {
293
290
}
294
291
} ;
295
292
296
- xhr . open ( 'post' , `${ suburl } /attachments` , true ) ;
293
+ xhr . open ( 'post' , `${ AppSubUrl } /attachments` , true ) ;
297
294
xhr . setRequestHeader ( 'X-Csrf-Token' , csrf ) ;
298
295
const formData = new FormData ( ) ;
299
296
formData . append ( 'file' , file , file . name ) ;
@@ -313,7 +310,7 @@ function initImagePaste(target) {
313
310
insertAtCursor ( field , `![${ name } ]()` ) ;
314
311
uploadFile ( img , ( res ) => {
315
312
const data = JSON . parse ( res ) ;
316
- replaceAndKeepCursor ( field , `![${ name } ]()` , `` ) ;
313
+ replaceAndKeepCursor ( field , `![${ name } ]()` , `` ) ;
317
314
const input = $ ( `<input id="${ data . uuid } " name="files" type="hidden">` ) . val ( data . uuid ) ;
318
315
$ ( '.files' ) . append ( input ) ;
319
316
} ) ;
@@ -329,7 +326,7 @@ function initSimpleMDEImagePaste(simplemde, files) {
329
326
uploadFile ( img , ( res ) => {
330
327
const data = JSON . parse ( res ) ;
331
328
const pos = simplemde . codemirror . getCursor ( ) ;
332
- simplemde . codemirror . replaceRange ( `` , pos ) ;
329
+ simplemde . codemirror . replaceRange ( `` , pos ) ;
333
330
const input = $ ( `<input id="${ data . uuid } " name="files" type="hidden">` ) . val ( data . uuid ) ;
334
331
files . append ( input ) ;
335
332
} ) ;
@@ -2059,7 +2056,7 @@ function searchUsers() {
2059
2056
$searchUserBox . search ( {
2060
2057
minCharacters : 2 ,
2061
2058
apiSettings : {
2062
- url : `${ suburl } /api/v1/users/search?q={query}` ,
2059
+ url : `${ AppSubUrl } /api/v1/users/search?q={query}` ,
2063
2060
onResponse ( response ) {
2064
2061
const items = [ ] ;
2065
2062
$ . each ( response . data , ( _i , item ) => {
@@ -2086,7 +2083,7 @@ function searchTeams() {
2086
2083
$searchTeamBox . search ( {
2087
2084
minCharacters : 2 ,
2088
2085
apiSettings : {
2089
- url : `${ suburl } /api/v1/orgs/${ $searchTeamBox . data ( 'org' ) } /teams/search?q={query}` ,
2086
+ url : `${ AppSubUrl } /api/v1/orgs/${ $searchTeamBox . data ( 'org' ) } /teams/search?q={query}` ,
2090
2087
headers : { 'X-Csrf-Token' : csrf } ,
2091
2088
onResponse ( response ) {
2092
2089
const items = [ ] ;
@@ -2110,7 +2107,7 @@ function searchRepositories() {
2110
2107
$searchRepoBox . search ( {
2111
2108
minCharacters : 2 ,
2112
2109
apiSettings : {
2113
- url : `${ suburl } /api/v1/repos/search?q={query}&uid=${ $searchRepoBox . data ( 'uid' ) } ` ,
2110
+ url : `${ AppSubUrl } /api/v1/repos/search?q={query}&uid=${ $searchRepoBox . data ( 'uid' ) } ` ,
2114
2111
onResponse ( response ) {
2115
2112
const items = [ ] ;
2116
2113
$ . each ( response . data , ( _i , item ) => {
@@ -2180,7 +2177,7 @@ function initU2FAuth() {
2180
2177
}
2181
2178
u2fApi . ensureSupport ( )
2182
2179
. then ( ( ) => {
2183
- $ . getJSON ( `${ suburl } /user/u2f/challenge` ) . success ( ( req ) => {
2180
+ $ . getJSON ( `${ AppSubUrl } /user/u2f/challenge` ) . success ( ( req ) => {
2184
2181
u2fApi . sign ( req . appId , req . challenge , req . registeredKeys , 30 )
2185
2182
. then ( u2fSigned )
2186
2183
. catch ( ( err ) => {
@@ -2193,12 +2190,12 @@ function initU2FAuth() {
2193
2190
} ) ;
2194
2191
} ) . catch ( ( ) => {
2195
2192
// Fallback in case browser do not support U2F
2196
- window . location . href = `${ suburl } /user/two_factor` ;
2193
+ window . location . href = `${ AppSubUrl } /user/two_factor` ;
2197
2194
} ) ;
2198
2195
}
2199
2196
function u2fSigned ( resp ) {
2200
2197
$ . ajax ( {
2201
- url : `${ suburl } /user/u2f/sign` ,
2198
+ url : `${ AppSubUrl } /user/u2f/sign` ,
2202
2199
type : 'POST' ,
2203
2200
headers : { 'X-Csrf-Token' : csrf } ,
2204
2201
data : JSON . stringify ( resp ) ,
@@ -2215,7 +2212,7 @@ function u2fRegistered(resp) {
2215
2212
return ;
2216
2213
}
2217
2214
$ . ajax ( {
2218
- url : `${ suburl } /user/settings/security/u2f/register` ,
2215
+ url : `${ AppSubUrl } /user/settings/security/u2f/register` ,
2219
2216
type : 'POST' ,
2220
2217
headers : { 'X-Csrf-Token' : csrf } ,
2221
2218
data : JSON . stringify ( resp ) ,
@@ -2274,7 +2271,7 @@ function initU2FRegister() {
2274
2271
}
2275
2272
2276
2273
function u2fRegisterRequest ( ) {
2277
- $ . post ( `${ suburl } /user/settings/security/u2f/request_register` , {
2274
+ $ . post ( `${ AppSubUrl } /user/settings/security/u2f/request_register` , {
2278
2275
_csrf : csrf ,
2279
2276
name : $ ( '#nickname' ) . val ( )
2280
2277
} ) . success ( ( req ) => {
@@ -2337,7 +2334,7 @@ function initTemplateSearch() {
2337
2334
$ ( '#repo_template_search' )
2338
2335
. dropdown ( {
2339
2336
apiSettings : {
2340
- url : `${ suburl } /api/v1/repos/search?q={query}&template=true&priority_owner_id=${ $ ( '#uid' ) . val ( ) } ` ,
2337
+ url : `${ AppSubUrl } /api/v1/repos/search?q={query}&template=true&priority_owner_id=${ $ ( '#uid' ) . val ( ) } ` ,
2341
2338
onResponse ( response ) {
2342
2339
const filteredResponse = { success : true , results : [ ] } ;
2343
2340
filteredResponse . results . push ( {
@@ -2365,8 +2362,6 @@ function initTemplateSearch() {
2365
2362
2366
2363
$ ( document ) . ready ( async ( ) => {
2367
2364
csrf = $ ( 'meta[name=_csrf]' ) . attr ( 'content' ) ;
2368
- suburl = $ ( 'meta[name=_suburl]' ) . attr ( 'content' ) ;
2369
- staticPrefix = $ ( 'meta[name=_staticprefix]' ) . attr ( 'content' ) ;
2370
2365
2371
2366
// Show exact time
2372
2367
$ ( '.time-since' ) . each ( function ( ) {
@@ -2455,7 +2450,7 @@ $(document).ready(async () => {
2455
2450
2456
2451
// Emojify
2457
2452
emojify . setConfig ( {
2458
- img_dir : `${ suburl } /vendor/plugins/emojify/images` ,
2453
+ img_dir : `${ AppSubUrl } /vendor/plugins/emojify/images` ,
2459
2454
ignore_emoticons : true
2460
2455
} ) ;
2461
2456
const hasEmoji = document . getElementsByClassName ( 'has-emoji' ) ;
@@ -2575,7 +2570,7 @@ $(document).ready(async () => {
2575
2570
initPullRequestReview ( ) ;
2576
2571
initRepoStatusChecker ( ) ;
2577
2572
initTemplateSearch ( ) ;
2578
- initContextPopups ( suburl ) ;
2573
+ initContextPopups ( ) ;
2579
2574
2580
2575
// Repo clone url.
2581
2576
if ( $ ( '#repo-clone-url' ) . length > 0 ) {
@@ -2785,7 +2780,7 @@ function initVueComponents() {
2785
2780
reposFilter : 'all' ,
2786
2781
searchQuery : '' ,
2787
2782
isLoading : false ,
2788
- staticPrefix,
2783
+ staticPrefix : StaticUrlPrefix ,
2789
2784
repoTypes : {
2790
2785
all : {
2791
2786
count : 0 ,
@@ -2891,6 +2886,8 @@ function initVueComponents() {
2891
2886
return 'octicon-repo-forked' ;
2892
2887
} if ( repo . mirror ) {
2893
2888
return 'octicon-repo-clone' ;
2889
+ } if ( repo . template ) {
2890
+ return `octicon-repo-template${ repo . private ? '-private' : '' } ` ;
2894
2891
} if ( repo . private ) {
2895
2892
return 'octicon-lock' ;
2896
2893
}
@@ -2921,7 +2918,7 @@ function initVueApp() {
2921
2918
el,
2922
2919
data : {
2923
2920
searchLimit : ( document . querySelector ( 'meta[name=_search_limit]' ) || { } ) . content ,
2924
- suburl : document . querySelector ( 'meta[name=_suburl]' ) . content ,
2921
+ suburl : AppSubUrl ,
2925
2922
uid : Number ( ( document . querySelector ( 'meta[name=_context_uid]' ) || { } ) . content ) ,
2926
2923
activityTopAuthors : window . ActivityTopAuthors || [ ] ,
2927
2924
} ,
@@ -3037,7 +3034,7 @@ window.initHeatmap = function (appElementId, heatmapUser, locale) {
3037
3034
el,
3038
3035
3039
3036
data : {
3040
- suburl : document . querySelector ( 'meta[name=_suburl]' ) . content ,
3037
+ suburl : AppSubUrl ,
3041
3038
heatmapUser,
3042
3039
locale
3043
3040
} ,
@@ -3283,7 +3280,7 @@ function initTopicbar() {
3283
3280
const last = viewDiv . children ( 'a' ) . last ( ) ;
3284
3281
for ( let i = 0 ; i < topicArray . length ; i ++ ) {
3285
3282
const link = $ ( '<a class="ui repo-topic small label topic"></a>' ) ;
3286
- link . attr ( 'href' , `${ suburl } /explore/repos?q=${ encodeURIComponent ( topicArray [ i ] ) } &topic=1` ) ;
3283
+ link . attr ( 'href' , `${ AppSubUrl } /explore/repos?q=${ encodeURIComponent ( topicArray [ i ] ) } &topic=1` ) ;
3287
3284
link . text ( topicArray [ i ] ) ;
3288
3285
link . insertBefore ( last ) ;
3289
3286
}
@@ -3331,7 +3328,7 @@ function initTopicbar() {
3331
3328
label : 'ui small label'
3332
3329
} ,
3333
3330
apiSettings : {
3334
- url : `${ suburl } /api/v1/topics/search?q={query}` ,
3331
+ url : `${ AppSubUrl } /api/v1/topics/search?q={query}` ,
3335
3332
throttle : 500 ,
3336
3333
cache : false ,
3337
3334
onResponse ( res ) {
@@ -3488,9 +3485,9 @@ function initIssueList() {
3488
3485
const repoId = $ ( '#repoId' ) . val ( ) ;
3489
3486
const crossRepoSearch = $ ( '#crossRepoSearch' ) . val ( ) ;
3490
3487
const tp = $ ( '#type' ) . val ( ) ;
3491
- let issueSearchUrl = `${ suburl } /api/v1/repos/${ repolink } /issues?q={query}&type=${ tp } ` ;
3488
+ let issueSearchUrl = `${ AppSubUrl } /api/v1/repos/${ repolink } /issues?q={query}&type=${ tp } ` ;
3492
3489
if ( crossRepoSearch === 'true' ) {
3493
- issueSearchUrl = `${ suburl } /api/v1/repos/issues/search?q={query}&priority_repo_id=${ repoId } &type=${ tp } ` ;
3490
+ issueSearchUrl = `${ AppSubUrl } /api/v1/repos/issues/search?q={query}&priority_repo_id=${ repoId } &type=${ tp } ` ;
3494
3491
}
3495
3492
$ ( '#new-dependency-drop-list' )
3496
3493
. dropdown ( {
0 commit comments