diff options
author | Saivan <savian@me.com> | 2018-02-27 01:14:06 +1100 |
---|---|---|
committer | Saivan <savian@me.com> | 2018-02-27 01:14:06 +1100 |
commit | 15637375c5a00b64ae6b493187e5791cfadbc94f (patch) | |
tree | 44374e3a4e943de6d3382c9a99f01dc3c052c9ee /src/parent.js | |
parent | bec7881979149425a9c1b894f4741413b28c8141 (diff) | |
download | svg.js-15637375c5a00b64ae6b493187e5791cfadbc94f.tar.gz svg.js-15637375c5a00b64ae6b493187e5791cfadbc94f.zip |
All files now loosely abide by standard linting
This commit completes the rest of the files, making sure they are
in the standard linting format. Next we will add the linter to
the build process of our application.
Diffstat (limited to 'src/parent.js')
-rw-r--r-- | src/parent.js | 68 |
1 files changed, 36 insertions, 32 deletions
diff --git a/src/parent.js b/src/parent.js index f8b6ee1..4583ebf 100644 --- a/src/parent.js +++ b/src/parent.js @@ -1,82 +1,86 @@ SVG.Parent = SVG.invent({ // Initialize node - create: function(node) { + create: function (node) { this.constructor.call(this, node) - } + }, // Inherit from -, inherit: SVG.Element + inherit: SVG.Element, // Add class methods -, extend: { + extend: { // Returns all child elements - children: function() { - return SVG.utils.map(this.node.children, function(node) { + children: function () { + return SVG.utils.map(this.node.children, function (node) { return SVG.adopt(node) }) - } + }, // Add given element at a position - , add: function(element, i) { + add: function (element, i) { element = createElement(element) - if (i == null) + if (i == null) { this.node.appendChild(element.node) - else if (element.node != this.node.children[i]) + } else if (element.node !== this.node.children[i]) { this.node.insertBefore(element.node, this.node.children[i]) + } return this - } + }, // Basically does the same as `add()` but returns the added element instead - , put: function(element, i) { + put: function (element, i) { this.add(element, i) return element.instance || element - } + }, // Checks if the given element is a child - , has: function(element) { + has: function (element) { return this.index(element) >= 0 - } + }, // Gets index of given element - , index: function(element) { + index: function (element) { return [].slice.call(this.node.children).indexOf(element.node) - } + }, // Get a element at the given index - , get: function(i) { + get: function (i) { return SVG.adopt(this.node.children[i]) - } + }, // Get first child - , first: function() { + first: function () { return this.get(0) - } + }, // Get the last child - , last: function() { + last: function () { return this.get(this.node.children.length - 1) - } + }, // Iterates over all children and invokes a given block - , each: function(block, deep) { + each: function (block, deep) { + var children = this.children() var i, il - , children = this.children() for (i = 0, il = children.length; i < il; i++) { - if (children[i] instanceof SVG.Element) + if (children[i] instanceof SVG.Element) { block.apply(children[i], [i, children]) + } - if (deep && (children[i] instanceof SVG.Parent)) + if (deep && (children[i] instanceof SVG.Parent)) { children[i].each(block, deep) + } } return this - } + }, // Remove a given child - , removeElement: function(element) { + removeElement: function (element) { this.node.removeChild(element.node) return this - } + }, // Remove all elements in this container - , clear: function() { + clear: function () { // remove children - while(this.node.hasChildNodes()) + while (this.node.hasChildNodes()) { this.node.removeChild(this.node.lastChild) + } // remove defs reference delete this._defs |