mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Some minor fixes in new #getItems() code.
This commit is contained in:
parent
f2a44a5832
commit
f2f34c3b75
2 changed files with 13 additions and 16 deletions
|
@ -1877,6 +1877,7 @@ var Item = Base.extend(Emitter, /** @lends Item# */{
|
|||
if (name.hasOwnProperty(key) && !this.matches(key, name[key]))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} else if (type === 'function') {
|
||||
return name(this);
|
||||
} else if (name === 'match') {
|
||||
|
@ -1892,25 +1893,21 @@ var Item = Base.extend(Emitter, /** @lends Item# */{
|
|||
: name === 'type'
|
||||
? Base.hyphenate(this._class)
|
||||
: this[name];
|
||||
if (/^(constructor|class)$/.test(name)) {
|
||||
if (typeof compare === 'function') {
|
||||
if (name === 'class') {
|
||||
if (typeof compare === 'function')
|
||||
return this instanceof compare;
|
||||
} else {
|
||||
// Compare further with the _class property value instead.
|
||||
value = this._class;
|
||||
}
|
||||
}
|
||||
if (compare instanceof RegExp) {
|
||||
return compare.test(value);
|
||||
} else if (typeof compare === 'function') {
|
||||
return !!compare(value);
|
||||
} else if (Base.isPlainObject(compare)) {
|
||||
return matchObject(compare, value);
|
||||
} else if (!Base.equals(value, compare)) {
|
||||
return false;
|
||||
}
|
||||
return Base.equals(value, compare);
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -46,7 +46,7 @@ test('Project#getItems()', function() {
|
|||
var layer = new Layer();
|
||||
|
||||
var matches = paper.project.getItems({
|
||||
type: 'layer'
|
||||
class: Layer
|
||||
});
|
||||
equals(function() {
|
||||
return matches.length == 1 && matches[0] == layer;
|
||||
|
@ -61,20 +61,20 @@ test('Project#getItems()', function() {
|
|||
|
||||
var path = new Path();
|
||||
var matches = paper.project.getItems({
|
||||
type: 'path'
|
||||
class: Path
|
||||
});
|
||||
equals(function() {
|
||||
return matches.length == 1 && matches[0] == path;
|
||||
}, true);
|
||||
|
||||
var group = new Group();
|
||||
var matches = paper.project.getItems({
|
||||
constructor: Path
|
||||
className: 'Group'
|
||||
});
|
||||
equals(function() {
|
||||
return matches.length == 1 && matches[0] === path;
|
||||
return matches.length == 1 && matches[0] === group
|
||||
}, true);
|
||||
|
||||
var group = new Group();
|
||||
var matches = paper.project.getItems({
|
||||
type: 'group'
|
||||
});
|
||||
|
@ -84,7 +84,7 @@ test('Project#getItems()', function() {
|
|||
|
||||
var raster = new Raster();
|
||||
var matches = paper.project.getItems({
|
||||
type: 'raster'
|
||||
class: Raster
|
||||
});
|
||||
equals(function() {
|
||||
return matches.length == 1 && matches[0] === raster
|
||||
|
@ -107,7 +107,7 @@ test('Project#getItems()', function() {
|
|||
equals(function() {
|
||||
return paper.project.getItems({
|
||||
selected: true,
|
||||
type: 'raster'
|
||||
class: Raster
|
||||
}).length;
|
||||
}, 1);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue