|
@@ -293,8 +293,9 @@ export class Template {
|
|
|
*/
|
|
|
public initPromise: Promise<Template>;
|
|
|
|
|
|
- private _fragment: DocumentFragment;
|
|
|
+ private _fragment: DocumentFragment | Element;
|
|
|
private _htmlTemplate: string;
|
|
|
+ private _rawHtml: string;
|
|
|
|
|
|
private loadRequests: Array<IFileRequest>;
|
|
|
|
|
@@ -317,8 +318,14 @@ export class Template {
|
|
|
this._htmlTemplate = htmlTemplate;
|
|
|
let compiledTemplate = Handlebars.compile(htmlTemplate);
|
|
|
let config = this._configuration.params || {};
|
|
|
- let rawHtml = compiledTemplate(config);
|
|
|
- this._fragment = document.createRange().createContextualFragment(rawHtml);
|
|
|
+ this._rawHtml = compiledTemplate(config);
|
|
|
+ try {
|
|
|
+ this._fragment = document.createRange().createContextualFragment(this._rawHtml);
|
|
|
+ } catch (e) {
|
|
|
+ let test = document.createElement(this.name);
|
|
|
+ test.innerHTML = this._rawHtml;
|
|
|
+ this._fragment = test;
|
|
|
+ }
|
|
|
this.isLoaded = true;
|
|
|
this.isShown = true;
|
|
|
this.onLoaded.notifyObservers(this);
|
|
@@ -342,8 +349,14 @@ export class Template {
|
|
|
}
|
|
|
let compiledTemplate = Handlebars.compile(this._htmlTemplate);
|
|
|
let config = this._configuration.params || {};
|
|
|
- let rawHtml = compiledTemplate(config);
|
|
|
- this._fragment = document.createRange().createContextualFragment(rawHtml);
|
|
|
+ this._rawHtml = compiledTemplate(config);
|
|
|
+ try {
|
|
|
+ this._fragment = document.createRange().createContextualFragment(this._rawHtml);
|
|
|
+ } catch (e) {
|
|
|
+ let test = document.createElement(this.name);
|
|
|
+ test.innerHTML = this._rawHtml;
|
|
|
+ this._fragment = test;
|
|
|
+ }
|
|
|
if (this.parent) {
|
|
|
this.appendTo(this.parent, true);
|
|
|
}
|
|
@@ -363,10 +376,16 @@ export class Template {
|
|
|
public getChildElements(): Array<string> {
|
|
|
let childrenArray: string[] = [];
|
|
|
//Edge and IE don't support frage,ent.children
|
|
|
- let children = this._fragment.children;
|
|
|
+ let children: HTMLCollection | NodeListOf<Element> = this._fragment && this._fragment.children;
|
|
|
+ if (!this._fragment) {
|
|
|
+ let fragment = this.parent.querySelector(this.name);
|
|
|
+ if (fragment) {
|
|
|
+ children = fragment.querySelectorAll('*');
|
|
|
+ }
|
|
|
+ }
|
|
|
if (!children) {
|
|
|
// casting to HTMLCollection, as both NodeListOf and HTMLCollection have 'item()' and 'length'.
|
|
|
- children = <HTMLCollection>this._fragment.querySelectorAll('*');
|
|
|
+ children = this._fragment.querySelectorAll('*');
|
|
|
}
|
|
|
for (let i = 0; i < children.length; ++i) {
|
|
|
childrenArray.push(kebabToCamel(children.item(i).nodeName.toLowerCase()));
|
|
@@ -382,7 +401,7 @@ export class Template {
|
|
|
*/
|
|
|
public appendTo(parent: HTMLElement, forceRemove?: boolean) {
|
|
|
if (this.parent) {
|
|
|
- if (forceRemove) {
|
|
|
+ if (forceRemove && this._fragment) {
|
|
|
this.parent.removeChild(this._fragment);
|
|
|
} else {
|
|
|
return;
|
|
@@ -393,7 +412,11 @@ export class Template {
|
|
|
if (this._configuration.id) {
|
|
|
this.parent.id = this._configuration.id;
|
|
|
}
|
|
|
- this._fragment = this.parent.appendChild(this._fragment);
|
|
|
+ if (this._fragment) {
|
|
|
+ this._fragment = this.parent.appendChild(this._fragment);
|
|
|
+ } else {
|
|
|
+ this.parent.insertAdjacentHTML("beforeend", this._rawHtml);
|
|
|
+ }
|
|
|
// appended only one frame after.
|
|
|
setTimeout(() => {
|
|
|
this._registerEvents();
|