MOBILE-2442 dom: Prevent http requests when parsing HTML
parent
39ef7cf0e1
commit
c971b991a8
|
@ -35,6 +35,8 @@ export class CoreDomUtilsProvider {
|
||||||
'search', 'tel', 'text', 'time', 'url', 'week'];
|
'search', 'tel', 'text', 'time', 'url', 'week'];
|
||||||
protected INSTANCE_ID_ATTR_NAME = 'core-instance-id';
|
protected INSTANCE_ID_ATTR_NAME = 'core-instance-id';
|
||||||
|
|
||||||
|
protected template = document.createElement('template'); // A template element to convert HTML to element.
|
||||||
|
|
||||||
protected matchesFn: string; // Name of the "matches" function to use when simulating a closest call.
|
protected matchesFn: string; // Name of the "matches" function to use when simulating a closest call.
|
||||||
protected instances: {[id: string]: any} = {}; // Store component/directive instances by id.
|
protected instances: {[id: string]: any} = {}; // Store component/directive instances by id.
|
||||||
protected lastInstanceId = 0;
|
protected lastInstanceId = 0;
|
||||||
|
@ -125,17 +127,15 @@ export class CoreDomUtilsProvider {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert some HTML as text into an HTMLElement. This HTML is put inside a div or a body.
|
* Convert some HTML as text into an HTMLElement. This HTML is put inside a div or a body.
|
||||||
* @todo: Try to use DOMParser or similar since this approach will send a request to all embedded media.
|
|
||||||
* We removed DOMParser solution because it isn't synchronous, document.body wasn't always loaded at start.
|
|
||||||
*
|
*
|
||||||
* @param {string} html Text to convert.
|
* @param {string} html Text to convert.
|
||||||
* @return {HTMLElement} Element.
|
* @return {HTMLElement} Element.
|
||||||
*/
|
*/
|
||||||
convertToElement(html: string): HTMLElement {
|
convertToElement(html: string): HTMLElement {
|
||||||
const element = document.createElement('div');
|
// Add a div to hold the content, that's the element that will be returned.
|
||||||
element.innerHTML = html;
|
this.template.innerHTML = '<div>' + html + '</div>';
|
||||||
|
|
||||||
return element;
|
return <HTMLElement> this.template.content.children[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -68,6 +68,8 @@ export class CoreTextUtilsProvider {
|
||||||
{old: /_mmaModWorkshop/g, new: '_AddonModWorkshop'},
|
{old: /_mmaModWorkshop/g, new: '_AddonModWorkshop'},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
protected template = document.createElement('template'); // A template element to convert HTML to element.
|
||||||
|
|
||||||
constructor(private translate: TranslateService, private langProvider: CoreLangProvider, private modalCtrl: ModalController) { }
|
constructor(private translate: TranslateService, private langProvider: CoreLangProvider, private modalCtrl: ModalController) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -177,17 +179,15 @@ export class CoreTextUtilsProvider {
|
||||||
/**
|
/**
|
||||||
* Convert some HTML as text into an HTMLElement. This HTML is put inside a div or a body.
|
* Convert some HTML as text into an HTMLElement. This HTML is put inside a div or a body.
|
||||||
* This function is the same as in DomUtils, but we cannot use that one because of circular dependencies.
|
* This function is the same as in DomUtils, but we cannot use that one because of circular dependencies.
|
||||||
* @todo: Try to use DOMParser or similar since this approach will send a request to all embedded media.
|
|
||||||
* We removed DOMParser solution because it isn't synchronous, document.body wasn't always loaded at start.
|
|
||||||
*
|
*
|
||||||
* @param {string} html Text to convert.
|
* @param {string} html Text to convert.
|
||||||
* @return {HTMLElement} Element.
|
* @return {HTMLElement} Element.
|
||||||
*/
|
*/
|
||||||
protected convertToElement(html: string): HTMLElement {
|
protected convertToElement(html: string): HTMLElement {
|
||||||
const element = document.createElement('div');
|
// Add a div to hold the content, that's the element that will be returned.
|
||||||
element.innerHTML = html;
|
this.template.innerHTML = '<div>' + html + '</div>';
|
||||||
|
|
||||||
return element;
|
return <HTMLElement> this.template.content.children[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue