mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-29 10:57:44 +09:00 
			
		
		
		
	[Fix] Resolve the problem of commit_statuses not being loaded at the top - right when switching files from the file tree (#34079)
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
		| @@ -1,10 +1,10 @@ | |||||||
| {{if .Statuses}} | {{if .Statuses}} | ||||||
| 	{{if and (eq (len .Statuses) 1) .Status.TargetURL}} | 	{{if and (eq (len .Statuses) 1) .Status.TargetURL}} | ||||||
| 		<a class="flex-text-inline tw-no-underline {{.AdditionalClasses}}" data-tippy="commit-statuses" href="{{.Status.TargetURL}}"> | 		<a class="flex-text-inline tw-no-underline {{.AdditionalClasses}}" data-global-init="initCommitStatuses" href="{{.Status.TargetURL}}"> | ||||||
| 			{{template "repo/commit_status" .Status}} | 			{{template "repo/commit_status" .Status}} | ||||||
| 		</a> | 		</a> | ||||||
| 	{{else}} | 	{{else}} | ||||||
| 		<span class="flex-text-inline {{.AdditionalClasses}}" data-tippy="commit-statuses" tabindex="0"> | 		<span class="flex-text-inline {{.AdditionalClasses}}" data-global-init="initCommitStatuses" tabindex="0"> | ||||||
| 			{{template "repo/commit_status" .Status}} | 			{{template "repo/commit_status" .Status}} | ||||||
| 		</span> | 		</span> | ||||||
| 	{{end}} | 	{{end}} | ||||||
|   | |||||||
| @@ -240,7 +240,7 @@ func TestRepoCommitsStatusMultiple(t *testing.T) { | |||||||
| 	resp = session.MakeRequest(t, req, http.StatusOK) | 	resp = session.MakeRequest(t, req, http.StatusOK) | ||||||
|  |  | ||||||
| 	doc = NewHTMLParser(t, resp.Body) | 	doc = NewHTMLParser(t, resp.Body) | ||||||
| 	// Check that the data-tippy="commit-statuses" (for trigger) and commit-status (svg) are present | 	// Check that the data-global-init="initCommitStatuses" (for trigger) and commit-status (svg) are present | ||||||
| 	sel := doc.doc.Find("#commits-table .message [data-tippy=\"commit-statuses\"] .commit-status") | 	sel := doc.doc.Find(`#commits-table .message [data-global-init="initCommitStatuses"] .commit-status`) | ||||||
| 	assert.Equal(t, 1, sel.Length()) | 	assert.Equal(t, 1, sel.Length()) | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,6 +1,6 @@ | |||||||
| import {createTippy} from '../modules/tippy.ts'; | import {createTippy} from '../modules/tippy.ts'; | ||||||
| import {toggleElem} from '../utils/dom.ts'; | import {toggleElem} from '../utils/dom.ts'; | ||||||
| import {registerGlobalEventFunc} from '../modules/observer.ts'; | import {registerGlobalEventFunc, registerGlobalInitFunc} from '../modules/observer.ts'; | ||||||
|  |  | ||||||
| export function initRepoEllipsisButton() { | export function initRepoEllipsisButton() { | ||||||
|   registerGlobalEventFunc('click', 'onRepoEllipsisButtonClick', async (el: HTMLInputElement, e: Event) => { |   registerGlobalEventFunc('click', 'onRepoEllipsisButtonClick', async (el: HTMLInputElement, e: Event) => { | ||||||
| @@ -12,15 +12,15 @@ export function initRepoEllipsisButton() { | |||||||
| } | } | ||||||
|  |  | ||||||
| export function initCommitStatuses() { | export function initCommitStatuses() { | ||||||
|   for (const element of document.querySelectorAll('[data-tippy="commit-statuses"]')) { |   registerGlobalInitFunc('initCommitStatuses', (el: HTMLElement) => { | ||||||
|     const top = document.querySelector('.repository.file.list') || document.querySelector('.repository.diff'); |     const nextEl = el.nextElementSibling; | ||||||
|  |     if (!nextEl.matches('.tippy-target')) throw new Error('Expected next element to be a tippy target'); | ||||||
|     createTippy(element, { |     createTippy(el, { | ||||||
|       content: element.nextElementSibling, |       content: nextEl, | ||||||
|       placement: top ? 'top-start' : 'bottom-start', |       placement: 'bottom-start', | ||||||
|       interactive: true, |       interactive: true, | ||||||
|       role: 'dialog', |       role: 'dialog', | ||||||
|       theme: 'box-with-header', |       theme: 'box-with-header', | ||||||
|     }); |     }); | ||||||
|   } |   }); | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user