Skip to content

Instantly share code, notes, and snippets.

@atsu85
Created December 29, 2015 01:02
Show Gist options
  • Save atsu85/03b1d053d9467e227dd5 to your computer and use it in GitHub Desktop.
Save atsu85/03b1d053d9467e227dd5 to your computer and use it in GitHub Desktop.
export class CustomElementUtil {
/**
* workaround for @containerless subclasses (custom elements) - waiting for https://github.com/aurelia/templating/issues/140
* @return previousElementSibling when given element is comment node (as it is in case of @containerless custom elements) or given element otherwise
*/
public static getRealElement(element: Element): Element {
if(element.nodeType === 8) {
element = this.getPreviusElementSibling(element)
}
return element;
}
private static getPreviusElementSibling(e: Element): Element {
if (e.previousElementSibling) {
return e.previousElementSibling;
}
var prev: Node = e.previousSibling;
while (prev) {
if (prev.nodeType === 1){
return <Element>prev;
}
prev = prev.previousSibling;
}
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment