Skip to content

Commit 91610a9

Browse files
authored
Fix various Fomantic UI and htmx problems (go-gitea#33851)
Also fix go-gitea#31328, fix go-gitea#33854
1 parent 651ef66 commit 91610a9

File tree

8 files changed

+16
-68
lines changed

8 files changed

+16
-68
lines changed

.dockerignore

-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ cpu.out
7979
/public/assets/fonts
8080
/public/assets/img/avatar
8181
/vendor
82-
/web_src/fomantic
8382
/VERSION
8483
/.air
8584
/.go-licenses

web_src/fomantic/build/components/api.js

+3-11
Original file line numberDiff line numberDiff line change
@@ -754,17 +754,9 @@ $.api = $.fn.api = function(parameters) {
754754
;
755755
},
756756
urlEncodedValue: function(value) {
757-
var
758-
decodedValue = window.decodeURIComponent(value),
759-
encodedValue = window.encodeURIComponent(value),
760-
alreadyEncoded = (decodedValue !== value)
761-
;
762-
if(alreadyEncoded) {
763-
module.debug('URL value is already encoded, avoiding double encoding', value);
764-
return value;
765-
}
766-
module.verbose('Encoding value using encodeURIComponent', value, encodedValue);
767-
return encodedValue;
757+
// GITEA-PATCH: always encode the value.
758+
// Old code does "decodeURIComponent" first to guess whether the value is encoded, it is not right.
759+
return window.encodeURIComponent(value);
768760
},
769761
defaultData: function() {
770762
var

web_src/fomantic/build/components/dropdown.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ $.fn.dropdown = function(parameters) {
3131
moduleSelector = $allModules.selector || '',
3232

3333
hasTouch = ('ontouchstart' in document.documentElement),
34-
clickEvent = hasTouch
35-
? 'touchstart'
36-
: 'click',
34+
// GITEA-PATCH: always "click" as clickEvent, old code used "touchstart" as clickEvent, it is wrong,
35+
// because "touchstart" caused problems when users try to scroll and the touch point is in the dropdown.
36+
clickEvent = 'click',
3737

3838
time = new Date().getTime(),
3939
performance = [],
@@ -768,7 +768,7 @@ $.fn.dropdown = function(parameters) {
768768
preSelected = preSelected && preSelected!=="" ? preSelected.split(settings.delimiter) : [];
769769
}
770770
$.each(preSelected,function(index,value){
771-
$item.filter('[data-value="'+value+'"]')
771+
$item.filter('[data-value="'+CSS.escape(value)+'"]') // GITEA-PATCH: use "CSS.escape" for query selector
772772
.addClass(className.filtered)
773773
;
774774
});
@@ -1027,7 +1027,7 @@ $.fn.dropdown = function(parameters) {
10271027
$input.append('<option disabled selected value></option>');
10281028
$.each(values, function(index, item) {
10291029
var
1030-
value = settings.templates.deQuote(item[fields.value]),
1030+
value = settings.templates.escape(item[fields.value]), // GITEA-PATCH: use "escape" for attribute value
10311031
name = settings.templates.escape(
10321032
item[fields.name] || '',
10331033
settings.preserveHTML
@@ -4180,13 +4180,14 @@ $.fn.dropdown.settings.templates = {
41804180
if( itemType === 'item' ) {
41814181
var
41824182
maybeText = (option[fields.text])
4183-
? ' data-text="' + deQuote(option[fields.text]) + '"'
4183+
? ' data-text="' + escape(option[fields.text]) + '"' // GITEA-PATCH: use "escape" for attribute value
41844184
: '',
41854185
maybeDisabled = (option[fields.disabled])
41864186
? className.disabled+' '
41874187
: ''
41884188
;
4189-
html += '<div class="'+ maybeDisabled + (option[fields.class] ? deQuote(option[fields.class]) : className.item)+'" data-value="' + deQuote(option[fields.value]) + '"' + maybeText + '>';
4189+
// GITEA-PATCH: use "escape" for attribute value
4190+
html += '<div class="'+ maybeDisabled + (option[fields.class] ? deQuote(option[fields.class]) : className.item)+'" data-value="' + escape(option[fields.value]) + '"' + maybeText + '>';
41904191
if(option[fields.image]) {
41914192
html += '<img class="'+(option[fields.imageClass] ? deQuote(option[fields.imageClass]) : className.image)+'" src="' + deQuote(option[fields.image]) + '">';
41924193
}

web_src/fomantic/build/fomantic.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,4 @@ import './components/dropdown.js';
33
import './components/modal.js';
44
import './components/search.js';
55

6-
// Hard forked from Fomantic 2.8.7
7-
8-
// TODO: need to apply the patch from Makefile
9-
// # fomantic uses "touchstart" as click event for some browsers, it's not ideal, so we force fomantic to always use "click" as click event
10-
// $(SED_INPLACE) -e 's/clickEvent[ \t]*=/clickEvent = "click", unstableClickEvent =/g' $(FOMANTIC_WORK_DIR)/build/semantic.js
6+
// Hard-forked from Fomantic UI 2.8.7, patches are commented with "GITEA-PATCH"

web_src/js/features/repo-diff.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,9 @@ function initRepoDiffShowMore() {
196196
const resp = await response.text();
197197
const respDoc = parseDom(resp, 'text/html');
198198
const respFileBody = respDoc.querySelector('#diff-file-boxes .diff-file-body .file-body');
199-
el.parentElement.replaceWith(...Array.from(respFileBody.children));
199+
const respFileBodyChildren = Array.from(respFileBody.children); // respFileBody.children will be empty after replaceWith
200+
el.parentElement.replaceWith(...respFileBodyChildren);
201+
for (const el of respFileBodyChildren) window.htmx.process(el);
200202
// FIXME: calling onShowMoreFiles is not quite right here.
201203
// But since onShowMoreFiles mixes "init diff box" and "init diff body" together,
202204
// so it still needs to call it to make the "ImageDiff" and something similar work.

web_src/js/globals.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ interface Window {
6464
jQuery: typeof import('@types/jquery'),
6565
htmx: Omit<typeof import('htmx.org/dist/htmx.esm.js').default, 'config'> & {
6666
config?: Writable<typeof import('htmx.org').default.config>,
67+
process?: (elt: Element | string) => void,
6768
},
6869
_globalHandlerErrors: Array<ErrorEvent & PromiseRejectionEvent> & {
6970
_inited: boolean,

web_src/js/modules/fomantic.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import $ from 'jquery';
2-
import {initFomanticApiPatch} from './fomantic/api.ts';
32
import {initAriaCheckboxPatch} from './fomantic/checkbox.ts';
43
import {initAriaFormFieldPatch} from './fomantic/form.ts';
54
import {initAriaDropdownPatch} from './fomantic/dropdown.ts';
@@ -27,7 +26,6 @@ export function initGiteaFomantic() {
2726
initFomanticTransition();
2827
initFomanticDimmer();
2928
initFomanticTab();
30-
initFomanticApiPatch();
3129

3230
// Use the patches to improve accessibility, these patches are designed to be as independent as possible, make it easy to modify or remove in the future.
3331
initAriaCheckboxPatch();

web_src/js/modules/fomantic/api.ts

-41
This file was deleted.

0 commit comments

Comments
 (0)