Custom elements implementation

Implements custom elements as per the spec in #1385.

This should be a complete implementation for HTML5-era browsers. Polyfill for IE6-8 to follow.