mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 21:28:11 +09:00 
			
		
		
		
	| @@ -1,6 +1,5 @@ | ||||
| import {svg} from '../svg.ts'; | ||||
| import {createTippy} from '../modules/tippy.ts'; | ||||
| import {clippie} from 'clippie'; | ||||
| import {toAbsoluteUrl} from '../utils.ts'; | ||||
| import {addDelegatedEventListener} from '../utils/dom.ts'; | ||||
|  | ||||
| @@ -43,7 +42,8 @@ function selectRange(range: string): Element { | ||||
|     if (!copyPermalink) return; | ||||
|     let link = copyPermalink.getAttribute('data-url'); | ||||
|     link = `${link.replace(/#L\d+$|#L\d+-L\d+$/, '')}#${anchor}`; | ||||
|     copyPermalink.setAttribute('data-url', link); | ||||
|     copyPermalink.setAttribute('data-clipboard-text', link); | ||||
|     copyPermalink.setAttribute('data-clipboard-text-type', 'url'); | ||||
|   }; | ||||
|  | ||||
|   const rangeFields = range ? range.split('-') : []; | ||||
| @@ -138,8 +138,4 @@ export function initRepoCodeView() { | ||||
|   }; | ||||
|   onHashChange(); | ||||
|   window.addEventListener('hashchange', onHashChange); | ||||
|  | ||||
|   addDelegatedEventListener(document, 'click', '.copy-line-permalink', (el) => { | ||||
|     clippie(toAbsoluteUrl(el.getAttribute('data-url'))); | ||||
|   }); | ||||
| } | ||||
|   | ||||
| @@ -360,7 +360,11 @@ export function querySingleVisibleElem<T extends HTMLElement>(parent: Element, s | ||||
| export function addDelegatedEventListener<T extends HTMLElement, E extends Event>(parent: Node, type: string, selector: string, listener: (elem: T, e: E) => Promisable<void>, options?: boolean | AddEventListenerOptions) { | ||||
|   parent.addEventListener(type, (e: Event) => { | ||||
|     const elem = (e.target as HTMLElement).closest(selector); | ||||
|     if (!elem || !parent.contains(elem)) return; | ||||
|     // It strictly checks "parent contains the target elem" to avoid side effects of selector running on outside the parent. | ||||
|     // Keep in mind that the elem could have been removed from parent by other event handlers before this event handler is called. | ||||
|     // For example: tippy popup item, the tippy popup could be hidden and removed from DOM before this. | ||||
|     // It is caller's responsibility make sure the elem is still in parent's DOM when this event handler is called. | ||||
|     if (!elem || (parent !== document && !parent.contains(elem))) return; | ||||
|     listener(elem as T, e as E); | ||||
|   }, options); | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user