aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md4
-rw-r--r--dist/svg.js14
-rw-r--r--spec/spec/element.js13
-rw-r--r--src/elements/Element.js18
4 files changed, 28 insertions, 21 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b8c78c7..94fff52 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -29,12 +29,13 @@ The document follows the conventions described in [“Keep a CHANGELOG”](http:
- added `ax(), ay(), amove()` to change texts x and y values directly (#787)
- added possibility to pass attributes into a constructor like: `new SVG.Rect({width:100})`
- added possibility to pass in additional attribues to element creators e.g. `canvas.rect({x:100})` or `canvas.rect(100, 100, {x:100})` (#796)
+- added `SVG.List` (#645)
### Removed
- removed `SVG.Array.split()` function
- removed workaround for browser bug with stroke-width
- removed polyfills
-- removed `SVG.Set`
+- removed `SVG.Set` in favour of `SVG.List`
- removed feature to set style with css string (e.g. "fill:none;display:block;")
- removed `loaded()` and `error()` method on `SVG.Image` (#706)
- removed sub-pixel offset fix
@@ -84,6 +85,7 @@ The document follows the conventions described in [“Keep a CHANGELOG”](http:
- `attr()` excepts array now to get multiple values at once
- `SVG.Text.rebuild()` now takes every font-size into account (#512)
- `fill()` and `stroke()` return the fill and stroke attribute when called as getter (#789)
+- `parents()` now gives back all parents until the passed one or document
### Fixed
- fixed a bug in clipping and masking where empty nodes persists after removal -> __TODO!__
diff --git a/dist/svg.js b/dist/svg.js
index 8670803..3a2d11a 100644
--- a/dist/svg.js
+++ b/dist/svg.js
@@ -6,7 +6,7 @@
* @copyright Wout Fierens <wout@mick-wout.com>
* @license MIT
*
-* BUILT: Mon Nov 12 2018 13:26:51 GMT+0100 (GMT+01:00)
+* BUILT: Mon Nov 12 2018 13:58:37 GMT+0100 (GMT+01:00)
*/;
var SVG = (function () {
'use strict';
@@ -1925,15 +1925,15 @@ var SVG = (function () {
}, {
key: "parents",
- value: function parents(type) {
- var parents = [];
+ value: function parents() {
+ var until = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : globals.document;
+ until = makeInstance(until);
+ var parents = new List();
var parent = this;
- do {
- parent = parent.parent(type);
- if (!parent || parent instanceof getClass('HtmlNode')) break;
+ while ((parent = parent.parent()) && parent.node !== until.node && parent.node !== globals.document) {
parents.push(parent);
- } while (parent.parent);
+ }
return parents;
} // Get referenced element form attribute value
diff --git a/spec/spec/element.js b/spec/spec/element.js
index 1cb754e..b36ea82 100644
--- a/spec/spec/element.js
+++ b/spec/spec/element.js
@@ -651,15 +651,16 @@ describe('Element', function() {
})
describe('parents()', function() {
- it('returns array of parent up to but not including the dom element filtered by type', function() {
+ it('returns array of parents until the passed element or document', function() {
var group1 = draw.group().addClass('test')
, group2 = group1.group()
- , rect = group2.rect(100,100)
+ , group3 = group2.group()
+ , rect = group3.rect(100,100)
- expect(rect.parents('.test')[0]).toBe(group1)
- expect(rect.parents(SVG.G)[0]).toBe(group2)
- expect(rect.parents(SVG.G)[1]).toBe(group1)
- expect(rect.parents().length).toBe(3)
+ expect(rect.parents('.test')[0]).toBe(group3)
+ expect(rect.parents('.test')[1]).toBe(group2)
+ expect(rect.parents(group2)[0]).toBe(group3)
+ expect(rect.parents(group1).length).toBe(2)
})
})
diff --git a/src/elements/Element.js b/src/elements/Element.js
index 03b5f07..3b96bf4 100644
--- a/src/elements/Element.js
+++ b/src/elements/Element.js
@@ -1,7 +1,9 @@
import { getClass, makeInstance, register, root } from '../utils/adopter.js'
+import { globals } from '../utils/window.js'
import { proportionalSize } from '../utils/utils.js'
import { reference } from '../modules/core/regex.js'
import Dom from './Dom.js'
+import List from '../types/List.js'
import SVGNumber from '../types/SVGNumber.js'
const Doc = getClass(root)
@@ -75,16 +77,18 @@ export default class Element extends Dom {
}
// return array of all ancestors of given type up to the root svg
- parents (type) {
- let parents = []
+ parents (until = globals.document) {
+ until = makeInstance(until)
+ let parents = new List()
let parent = this
- do {
- parent = parent.parent(type)
- if (!parent || parent instanceof getClass('HtmlNode')) break
-
+ while (
+ (parent = parent.parent()) &&
+ parent.node !== until.node &&
+ parent.node !== globals.document
+ ) {
parents.push(parent)
- } while (parent.parent)
+ }
return parents
}