Created
December 29, 2015 01:02
-
-
Save atsu85/03b1d053d9467e227dd5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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