Skip to content

Commit e76a64d

Browse files
Inject SVG sprite via ajax (#10320)
* AJAX SVG * Fix PWA * Remove unused PWA assets Signed-off-by: jolheiser <[email protected]> Co-Authored-by: silverwind <[email protected]>
1 parent 05c1f2b commit e76a64d

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

modules/templates/helper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ func NewFuncMap() []template.FuncMap {
287287
return false
288288
},
289289
"svg": func(icon string, size int) template.HTML {
290-
return template.HTML(fmt.Sprintf(`<svg class="svg %s" width="%d" height="%d" aria-hidden="true"><use xlink:href="%s/img/svg/icons.svg#%s" /></svg>`, icon, size, size, setting.StaticURLPrefix, icon))
290+
return template.HTML(fmt.Sprintf(`<svg class="svg %s" width="%d" height="%d" aria-hidden="true"><use xlink:href="#%s" /></svg>`, icon, size, size, icon))
291291
},
292292
}}
293293
}

templates/pwa/serviceworker_js.tmpl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ var urlsToCache = [
2222
'{{StaticUrlPrefix}}/css/swagger.css?v={{MD5 AppVer}}',
2323
'{{StaticUrlPrefix}}/fomantic/semantic.min.css?v={{MD5 AppVer}}',
2424
'{{StaticUrlPrefix}}/vendor/assets/font-awesome/css/font-awesome.min.css',
25-
'{{StaticUrlPrefix}}/vendor/assets/octicons/octicons.min.css',
2625
'{{StaticUrlPrefix}}/vendor/plugins/dropzone/dropzone.css',
2726
'{{StaticUrlPrefix}}/vendor/plugins/jquery.datetimepicker/jquery.datetimepicker.css',
2827
'{{StaticUrlPrefix}}/vendor/plugins/jquery.minicolors/jquery.minicolors.css',
@@ -41,11 +40,10 @@ var urlsToCache = [
4140
'{{StaticUrlPrefix}}/img/gitea-lg.png',
4241

4342
// svg
44-
'{{StaticUrlPrefix}}/img/svg/icons.svg'
43+
'{{StaticUrlPrefix}}/img/svg/icons.svg',
4544

4645
// fonts
4746
'{{StaticUrlPrefix}}/fomantic/themes/default/assets/fonts/icons.woff2',
48-
'{{StaticUrlPrefix}}/vendor/assets/octicons/octicons.woff2?ef21c39f0ca9b1b5116e5eb7ac5eabe6',
4947
'{{StaticUrlPrefix}}/vendor/assets/roboto-fonts/roboto-v20-latin-ext_cyrillic-ext_latin_greek_vietnamese_cyrillic_greek-ext-regular.woff2',
5048
'{{StaticUrlPrefix}}/vendor/assets/roboto-fonts/roboto-v20-latin-ext_cyrillic-ext_latin_greek_vietnamese_cyrillic_greek-ext-italic.woff2',
5149
'{{StaticUrlPrefix}}/vendor/assets/roboto-fonts/roboto-v20-latin-ext_cyrillic-ext_latin_greek_vietnamese_cyrillic_greek-ext-700.woff2',

web_src/js/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3581,3 +3581,12 @@ window.onOAuthLoginClick = function () {
35813581
oauthNav.show();
35823582
}, 5000);
35833583
};
3584+
3585+
// Pull SVGs via AJAX to workaround CORS issues with <use> tags
3586+
// https://css-tricks.com/ajaxing-svg-sprite/
3587+
$.get(`${window.config.StaticUrlPrefix}/img/svg/icons.svg`, (data) => {
3588+
const div = document.createElement('div');
3589+
div.style.display = 'none';
3590+
div.innerHTML = new XMLSerializer().serializeToString(data.documentElement);
3591+
document.body.insertBefore(div, document.body.childNodes[0]);
3592+
});

0 commit comments

Comments
 (0)