File tree Expand file tree Collapse file tree 4 files changed +42
-4
lines changed Expand file tree Collapse file tree 4 files changed +42
-4
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,8 @@ import {
2323 mousemoveCallBack ,
2424 mousePosition ,
2525 mouseInteractionCallBack ,
26+ mouseInteractionParam ,
27+ clickParam ,
2628 MouseInteractions ,
2729 listenerHandler ,
2830 scrollCallback ,
@@ -286,12 +288,30 @@ function initMouseInteractionObserver(
286288 }
287289 const id = mirror . getId ( target as INode ) ;
288290 const { clientX, clientY } = e ;
289- cb ( {
291+ let emissionEvent : mouseInteractionParam | clickParam = {
290292 type : MouseInteractions [ eventKey ] ,
291293 id,
292294 x : clientX ,
293295 y : clientY ,
294- } ) ;
296+ }
297+ const htarget = ( target as Element ) ;
298+ if ( MouseInteractions [ eventKey ] === MouseInteractions . Click ) {
299+ let href : string | null = null ;
300+ if ( htarget . tagName . toLowerCase ( ) === 'a' &&
301+ ( htarget as HTMLAnchorElement ) . href ) {
302+ href = ( htarget as HTMLAnchorElement ) . href ;
303+ } else if ( htarget . tagName . toLowerCase ( ) === 'area' &&
304+ ( htarget as HTMLAreaElement ) . href ) {
305+ href = ( htarget as HTMLAreaElement ) . href ;
306+ }
307+ if ( href !== null ) {
308+ emissionEvent = {
309+ ...emissionEvent ,
310+ href : href ,
311+ } ;
312+ }
313+ }
314+ cb ( emissionEvent ) ;
295315 } ;
296316 } ;
297317 Object . keys ( MouseInteractions )
Original file line number Diff line number Diff line change @@ -365,14 +365,18 @@ export enum MouseInteractions {
365365 TouchEnd ,
366366}
367367
368- type mouseInteractionParam = {
368+ export type mouseInteractionParam = {
369369 type : MouseInteractions ;
370370 id : number ;
371371 x : number ;
372372 y : number ;
373373} ;
374374
375- export type mouseInteractionCallBack = ( d : mouseInteractionParam ) => void ;
375+ export type clickParam = mouseInteractionParam & {
376+ href ?: string ;
377+ } ;
378+
379+ export type mouseInteractionCallBack = ( d : mouseInteractionParam | clickParam ) => void ;
376380
377381export type scrollPosition = {
378382 id : number ;
Original file line number Diff line number Diff line change @@ -2992,6 +2992,7 @@ exports[`link 1`] = `
29922992 \\" source\\ " : 2 ,
29932993 \\" type\\ " : 2 ,
29942994 \\" id\\ " : 21 ,
2995+ \\" href\\ " : \\" about:blank#clicked\\ "
29952996 }
29962997 }
29972998]"
Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 " />
5+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 " />
6+ < meta http-equiv ="X-UA-Compatible " content ="ie=edge " />
7+ < title > Link click</ title >
8+ </ head >
9+ < body >
10+ < span id ="not-a-link "> not link</ span >
11+ < a href ="#clicked "> link</ a >
12+ </ body >
13+ </ html >
You can’t perform that action at this time.
0 commit comments