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]))
|
if (name.hasOwnProperty(key) && !this.matches(key, name[key]))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
} else if (type === 'function') {
|
} else if (type === 'function') {
|
||||||
return name(this);
|
return name(this);
|
||||||
} else if (name === 'match') {
|
} else if (name === 'match') {
|
||||||
|
@ -1892,13 +1893,11 @@ var Item = Base.extend(Emitter, /** @lends Item# */{
|
||||||
: name === 'type'
|
: name === 'type'
|
||||||
? Base.hyphenate(this._class)
|
? Base.hyphenate(this._class)
|
||||||
: this[name];
|
: this[name];
|
||||||
if (/^(constructor|class)$/.test(name)) {
|
if (name === 'class') {
|
||||||
if (typeof compare === 'function') {
|
if (typeof compare === 'function')
|
||||||
return this instanceof compare;
|
return this instanceof compare;
|
||||||
} else {
|
// Compare further with the _class property value instead.
|
||||||
// Compare further with the _class property value instead.
|
value = this._class;
|
||||||
value = this._class;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (compare instanceof RegExp) {
|
if (compare instanceof RegExp) {
|
||||||
return compare.test(value);
|
return compare.test(value);
|
||||||
|
@ -1906,11 +1905,9 @@ var Item = Base.extend(Emitter, /** @lends Item# */{
|
||||||
return !!compare(value);
|
return !!compare(value);
|
||||||
} else if (Base.isPlainObject(compare)) {
|
} else if (Base.isPlainObject(compare)) {
|
||||||
return matchObject(compare, value);
|
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 layer = new Layer();
|
||||||
|
|
||||||
var matches = paper.project.getItems({
|
var matches = paper.project.getItems({
|
||||||
type: 'layer'
|
class: Layer
|
||||||
});
|
});
|
||||||
equals(function() {
|
equals(function() {
|
||||||
return matches.length == 1 && matches[0] == layer;
|
return matches.length == 1 && matches[0] == layer;
|
||||||
|
@ -61,20 +61,20 @@ test('Project#getItems()', function() {
|
||||||
|
|
||||||
var path = new Path();
|
var path = new Path();
|
||||||
var matches = paper.project.getItems({
|
var matches = paper.project.getItems({
|
||||||
type: 'path'
|
class: Path
|
||||||
});
|
});
|
||||||
equals(function() {
|
equals(function() {
|
||||||
return matches.length == 1 && matches[0] == path;
|
return matches.length == 1 && matches[0] == path;
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
|
var group = new Group();
|
||||||
var matches = paper.project.getItems({
|
var matches = paper.project.getItems({
|
||||||
constructor: Path
|
className: 'Group'
|
||||||
});
|
});
|
||||||
equals(function() {
|
equals(function() {
|
||||||
return matches.length == 1 && matches[0] === path;
|
return matches.length == 1 && matches[0] === group
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
var group = new Group();
|
|
||||||
var matches = paper.project.getItems({
|
var matches = paper.project.getItems({
|
||||||
type: 'group'
|
type: 'group'
|
||||||
});
|
});
|
||||||
|
@ -84,7 +84,7 @@ test('Project#getItems()', function() {
|
||||||
|
|
||||||
var raster = new Raster();
|
var raster = new Raster();
|
||||||
var matches = paper.project.getItems({
|
var matches = paper.project.getItems({
|
||||||
type: 'raster'
|
class: Raster
|
||||||
});
|
});
|
||||||
equals(function() {
|
equals(function() {
|
||||||
return matches.length == 1 && matches[0] === raster
|
return matches.length == 1 && matches[0] === raster
|
||||||
|
@ -107,7 +107,7 @@ test('Project#getItems()', function() {
|
||||||
equals(function() {
|
equals(function() {
|
||||||
return paper.project.getItems({
|
return paper.project.getItems({
|
||||||
selected: true,
|
selected: true,
|
||||||
type: 'raster'
|
class: Raster
|
||||||
}).length;
|
}).length;
|
||||||
}, 1);
|
}, 1);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue