Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
Refactor to support older node versions
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbert committed Nov 10, 2016
1 parent 329eff3 commit b6f6ca8
Showing 1 changed file with 7 additions and 27 deletions.
34 changes: 7 additions & 27 deletions src/registry.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"use strict";
var domino = require("domino");
var Document = require('domino/lib/Document');
var Element = require('domino/lib/Element');
Expand Down Expand Up @@ -210,9 +211,11 @@ exports = module.exports = CustomElementRegistry;


//
// Overwrite domino's new element constructor
// - Overwrite domino's new element constructor
// - Patch domino's document.createElement
//
const origHTMLElement = domino.impl.HTMLElement;
const _origCreateElement = Document.prototype.createElement;

const newHTMLElement = function HTMLElement() {
const customElements = _customElements();
Expand All @@ -231,16 +234,6 @@ const newHTMLElement = function HTMLElement() {
}
throw new Error('Unknown constructor. Did you call customElements.define()?');
};
exports.HTMLElement = newHTMLElement;
exports.HTMLElement.prototype = Object.create(domino.impl.HTMLElement.prototype, {
constructor: {value: exports.HTMLElement, configurable: true, writable: true},
});


//
// Patch document.createElement
//
const _origCreateElement = Document.prototype.createElement;

/**
* Creates a new element and upgrades it if it's a custom element.
Expand All @@ -262,23 +255,10 @@ function _createElement(doc, tagName, options, callConstructor) {
}
return element;
}
Document.prototype.createElement = function(tagName, options) {
return _createElement(this, tagName, options, true);
};

//
// Patch doc.createElementNS
//
const HTMLNS = 'http://www.w3.org/1999/xhtml';
const _origCreateElementNS = Document.prototype.createElementNS;

Document.prototype.createElementNS = function(namespaceURI, qualifiedName) {
if (namespaceURI === 'http://www.w3.org/1999/xhtml') {
return this.createElement(qualifiedName);
} else {
return _origCreateElementNS.call(this, namespaceURI, qualifiedName);
}
};

var patched = require('./extend-domino')(newHTMLElement, _createElement);
exports.HTMLElement = patched.HTMLElement;


/**
Expand Down

0 comments on commit b6f6ca8

Please sign in to comment.