diff options
Diffstat (limited to 'src/tools.js')
-rw-r--r-- | src/tools.js | 56 |
1 files changed, 0 insertions, 56 deletions
diff --git a/src/tools.js b/src/tools.js deleted file mode 100644 index 14e19a3..0000000 --- a/src/tools.js +++ /dev/null @@ -1,56 +0,0 @@ -import { ns } from './namespaces.js' -import { getClass } from './adopter.js' - -export function nodeOrNew (name, node) { - return node || makeNode(name) -} - -// Method for element creation -export function makeNode (name) { - // create element - return document.createElementNS(ns, name) -} - -// Method for extending objects -export function extend (modules, methods) { - var key, i - - modules = Array.isArray(modules) ? modules : [modules] - - for (i = modules.length - 1; i >= 0; i--) { - for (key in methods) { - modules[i].prototype[key] = methods[key] - } - } -} - -// FIXME: enhanced constructors here -export function addFactory (modules, methods) { - extend(modules, methods) -} - -// Invent new element -export function invent (config) { - // Create element initializer - var initializer = typeof config.create === 'function' ? config.create - : function (node) { - config.inherit.call(this, node || makeNode(config.create)) - } - - // Inherit prototype - if (config.inherit) { - /* eslint new-cap: "off" */ - initializer.prototype = new config.inherit() - initializer.prototype.constructor = initializer - } - - // Extend with methods - if (config.extend) { - extend(initializer, config.extend) - } - - // Attach construct method to parent - if (config.construct) { extend(config.parent || getClass('Container'), config.construct) } - - return initializer -} |