MOBILE-2235 iframe: Fix clicks in deep iframe links
parent
56faa66adc
commit
69e4fdd036
|
@ -319,10 +319,32 @@ export class CoreIframeUtilsProvider {
|
|||
while (el && el.tagName !== 'A') {
|
||||
el = el.parentElement;
|
||||
}
|
||||
if (!el || el.tagName !== 'A') {
|
||||
|
||||
const link = <CoreIframeHTMLAnchorElement> el;
|
||||
if (!link || link.treated) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Add click listener to the link, this way if the iframe has added a listener to the link it will be executed first.
|
||||
link.treated = true;
|
||||
link.addEventListener('click', this.linkClicked.bind(this, element, link));
|
||||
}, {
|
||||
capture: true // Use capture to fix this listener not called if the element clicked is too deep in the DOM.
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* A link inside a frame was clicked.
|
||||
*
|
||||
* @param element Frame element.
|
||||
* @param link Link clicked.
|
||||
* @param event Click event.
|
||||
*/
|
||||
protected linkClicked(element: HTMLFrameElement | HTMLObjectElement, link: HTMLAnchorElement, event: Event): void {
|
||||
if (event.defaultPrevented) {
|
||||
// Event already prevented by some other code.
|
||||
return;
|
||||
}
|
||||
const link = <HTMLAnchorElement> el;
|
||||
|
||||
const scheme = this.urlUtils.getUrlScheme(link.href);
|
||||
if (!link.href || (scheme && scheme == 'javascript')) {
|
||||
|
@ -334,7 +356,7 @@ export class CoreIframeUtilsProvider {
|
|||
// Scheme suggests it's an external resource.
|
||||
event.preventDefault();
|
||||
|
||||
const frameSrc = element.src || element.data,
|
||||
const frameSrc = (<HTMLFrameElement> element).src || (<HTMLObjectElement> element).data,
|
||||
frameScheme = this.urlUtils.getUrlScheme(frameSrc);
|
||||
|
||||
// If the frame is not local, check the target to identify how to treat the link.
|
||||
|
@ -371,6 +393,12 @@ export class CoreIframeUtilsProvider {
|
|||
element.setAttribute('src', link.href);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtype of HTMLAnchorElement, with some calculated data.
|
||||
*/
|
||||
type CoreIframeHTMLAnchorElement = HTMLAnchorElement & {
|
||||
treated?: boolean; // Whether the element has been treated already.
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue