Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into brush-clip-path
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaMan123 committed Jul 1, 2021
2 parents 251a5df + 3b99a2d commit 8fe3e37
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- fix(fabric.Object): support `excludeFromExport` set on `clipPath` [#7148](https://github.com/fabricjs/fabric.js/pull/7148).
- fix(fabric.Group): support `excludeFromExport` set on objects [#7148](https://github.com/fabricjs/fabric.js/pull/7148).
- fix(fabric.StaticCanvas): support `excludeFromExport` set on `backgroundColor`, `overlayColor`, `clipPath` [#7148](https://github.com/fabricjs/fabric.js/pull/7148).
- feat(fabric.Collection): the `contains` method now accepts a second boolean parameter `deep`, checking all descendants, `collection.contains(obj, true)` [#7139](https://github.com/fabricjs/fabric.js/pull/7139).
- feat(fabric.BaseBrush): added `clipPath` property [#7175](https://github.com/fabricjs/fabric.js/pull/7175).
- feat(fabric.CircleBrush): added `clipPath` property [#7175](https://github.com/fabricjs/fabric.js/pull/7175).
- feat(fabric.PencilBrush): added `clipPath` property [#7175](https://github.com/fabricjs/fabric.js/pull/7175).
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ These are the optional modules that could be specified for inclusion, when build
- **easing** — Adds support for animation easing functions
- **node** — Adds support for running fabric under node.js, with help of [jsdom](https://github.com/tmpvar/jsdom) and [node-canvas](https://github.com/learnboost/node-canvas) libraries.
- **freedrawing** — Adds support for free drawing
- **erasing** — Adds support for object erasing using an eraser brush
- **gestures** — Adds support for multitouch gestures with help of [Event.js](https://github.com/mudcube/Event.js)
- **object_straightening** — Adds support for rotating an object to one of 0, 90, 180, 270, etc. depending on which is angle is closer.
- **animation** — Adds support for animation (`fabric.util.animate`, `fabric.util.requestAnimFrame`, `fabric.Object#animate`, `fabric.Canvas#fxCenterObjectH/#fxCenterObjectV/#fxRemove`)
Expand Down Expand Up @@ -250,6 +251,7 @@ For example:

- [Fabric on Bountysource](https://www.bountysource.com/trackers/23217-fabric-js)
- [Fabric on CodeTriage](http://www.codetriage.com/kangax/fabric.js)
- [Contributing](./CONTRIBUTING.md)

### Staying in touch

Expand Down
13 changes: 11 additions & 2 deletions src/mixins/collection.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,19 @@ fabric.Collection = {
/**
* Returns true if collection contains an object
* @param {Object} object Object to check against
* @param {Boolean} [deep=false] `true` to check all descendants, `false` to check only `_objects`
* @return {Boolean} `true` if collection contains an object
*/
contains: function(object) {
return this._objects.indexOf(object) > -1;
contains: function (object, deep) {
if (this._objects.indexOf(object) > -1) {
return true;
}
else if (deep) {
return this._objects.some(function (obj) {
return typeof obj.contains === 'function' && obj.contains(object, true);
});
}
return false;
},

/**
Expand Down
13 changes: 12 additions & 1 deletion test/unit/collection.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(function() {

var collection = fabric.Collection;
var collection2 = fabric.util.object.clone(collection);

QUnit.module('fabric.Collection', {
beforeEach: function() {
Expand All @@ -9,6 +10,7 @@
delete collection.renderOnAddRemove;
delete collection._onObjectAdded;
delete collection._onObjectRemoved;
collection2._objects = [];
}
});

Expand Down Expand Up @@ -173,7 +175,16 @@
assert.equal(returned, false, 'collection is empty so does not contains obj');
collection.add(obj);
returned = collection.contains(obj);
assert.equal(returned, true, 'collection contais obj');
assert.equal(returned, true, 'collection contains obj');
var obj2 = { type: 'b' };
collection2.add(obj2);
collection.add(collection2);
returned = collection.contains(obj2);
assert.equal(returned, false, 'collection deeply contains obj, this check is shallow');
returned = collection.contains(obj2, false);
assert.equal(returned, false, 'collection deeply contains obj, this check is shallow');
returned = collection.contains(obj2, true);
assert.equal(returned, true, 'collection deeply contains obj');
});

QUnit.test('complexity', function(assert) {
Expand Down

0 comments on commit 8fe3e37

Please sign in to comment.