2011-07-01 06:17:45 -04:00
|
|
|
/*
|
|
|
|
* Paper.js
|
|
|
|
*
|
|
|
|
* This file is part of Paper.js, a JavaScript Vector Graphics Library,
|
|
|
|
* based on Scriptographer.org and designed to be largely API compatible.
|
|
|
|
* http://paperjs.org/
|
|
|
|
* http://scriptographer.org/
|
|
|
|
*
|
|
|
|
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
|
|
|
|
* http://lehni.org/ & http://jonathanpuckey.com/
|
|
|
|
*
|
|
|
|
* Distributed under the MIT license. See LICENSE file for details.
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2011-02-16 16:11:26 -05:00
|
|
|
module('Layer');
|
|
|
|
|
|
|
|
test('previousSibling / nextSibling', function() {
|
2011-05-20 09:08:17 -04:00
|
|
|
var project = paper.project;
|
|
|
|
var firstLayer = project.activeLayer;
|
2011-02-16 16:11:26 -05:00
|
|
|
var secondLayer = new Layer();
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
|
|
|
return secondLayer.previousSibling == firstLayer;
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return secondLayer.nextSibling == null;
|
|
|
|
}, true);
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2011-02-16 16:11:26 -05:00
|
|
|
// Move another layer into secondLayer and check nextSibling /
|
|
|
|
// previousSibling:
|
|
|
|
var path = new Path();
|
|
|
|
var thirdLayer = new Layer();
|
2011-06-17 10:58:22 -04:00
|
|
|
secondLayer.insertChild(0, thirdLayer);
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
|
|
|
return secondLayer.children.length;
|
|
|
|
}, 2);
|
|
|
|
equals(function() {
|
|
|
|
return thirdLayer.nextSibling == path;
|
|
|
|
}, true);
|
2011-06-17 10:58:22 -04:00
|
|
|
secondLayer.addChild(thirdLayer);
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
|
|
|
return thirdLayer.nextSibling == null;
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return thirdLayer.previousSibling == path;
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
2011-05-20 09:08:17 -04:00
|
|
|
return project.layers.length == 2;
|
2011-05-07 12:46:06 -04:00
|
|
|
}, true);
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2011-06-17 10:58:22 -04:00
|
|
|
firstLayer.addChild(secondLayer);
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
2011-05-20 09:08:17 -04:00
|
|
|
return project.layers.length == 1;
|
2011-05-07 12:46:06 -04:00
|
|
|
}, true);
|
2011-02-16 16:11:26 -05:00
|
|
|
});
|
|
|
|
|
2011-06-17 10:58:22 -04:00
|
|
|
test('insertAbove / insertBelow', function() {
|
2011-05-20 09:08:17 -04:00
|
|
|
var project = paper.project;
|
|
|
|
var firstLayer = project.activeLayer;
|
2011-02-16 16:11:26 -05:00
|
|
|
var secondLayer = new Layer();
|
2012-11-19 23:41:04 -05:00
|
|
|
var thirdLayer = new Layer();
|
|
|
|
|
|
|
|
thirdLayer.insertBelow(firstLayer);
|
|
|
|
equals(function() {
|
|
|
|
return thirdLayer.previousSibling == null;
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return thirdLayer.nextSibling == firstLayer;
|
|
|
|
}, true);
|
|
|
|
|
2011-06-17 10:58:22 -04:00
|
|
|
secondLayer.insertBelow(firstLayer);
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
2012-11-19 23:41:04 -05:00
|
|
|
return secondLayer.previousSibling == thirdLayer;
|
2011-05-07 12:46:06 -04:00
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return secondLayer.nextSibling == firstLayer;
|
|
|
|
}, true);
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2011-02-16 16:11:26 -05:00
|
|
|
var path = new Path();
|
2011-06-17 10:58:22 -04:00
|
|
|
firstLayer.addChild(path);
|
2011-02-16 16:11:26 -05:00
|
|
|
|
|
|
|
// move the layer above the path, inside the firstLayer:
|
2011-06-17 10:58:22 -04:00
|
|
|
secondLayer.insertAbove(path);
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
2012-03-13 11:01:07 -04:00
|
|
|
return secondLayer.nextSibling == path;
|
2011-05-07 12:46:06 -04:00
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return secondLayer.parent == firstLayer;
|
|
|
|
}, true);
|
2012-11-19 23:41:04 -05:00
|
|
|
// There should now only be two layers left:
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
2011-05-20 09:08:17 -04:00
|
|
|
return project.layers.length;
|
2012-11-19 23:41:04 -05:00
|
|
|
}, 2);
|
2011-05-20 09:08:17 -04:00
|
|
|
});
|
|
|
|
|
2011-06-17 10:58:22 -04:00
|
|
|
test('addChild / appendBottom / nesting', function() {
|
2011-05-20 09:08:17 -04:00
|
|
|
var project = paper.project;
|
|
|
|
var firstLayer = project.activeLayer;
|
|
|
|
var secondLayer = new Layer();
|
|
|
|
// There should be two layers now in project.layers
|
|
|
|
equals(function() {
|
|
|
|
return project.layers.length;
|
2011-05-20 19:42:33 -04:00
|
|
|
}, 2);
|
2011-06-17 10:58:22 -04:00
|
|
|
firstLayer.addChild(secondLayer);
|
2011-05-20 09:08:17 -04:00
|
|
|
equals(function() {
|
|
|
|
return secondLayer.parent == firstLayer;
|
|
|
|
}, true);
|
2011-05-20 19:42:33 -04:00
|
|
|
// There should only be the firsLayer now in project.layers
|
2011-05-20 09:08:17 -04:00
|
|
|
equals(function() {
|
2011-05-20 19:42:33 -04:00
|
|
|
return project.layers.length;
|
|
|
|
}, 1);
|
2011-05-20 09:08:17 -04:00
|
|
|
equals(function() {
|
2011-05-20 19:42:33 -04:00
|
|
|
return project.layers[0] == firstLayer;
|
2011-05-20 09:08:17 -04:00
|
|
|
}, true);
|
2011-05-20 19:42:33 -04:00
|
|
|
// Now move secondLayer bellow the first again, in which case it should
|
|
|
|
// reappear in project.layers
|
2011-06-17 10:58:22 -04:00
|
|
|
secondLayer.insertBelow(firstLayer);
|
2011-05-20 19:42:33 -04:00
|
|
|
// There should be two layers now in project.layers again now
|
2011-05-20 09:08:17 -04:00
|
|
|
equals(function() {
|
|
|
|
return project.layers.length;
|
2011-05-20 19:42:33 -04:00
|
|
|
}, 2);
|
|
|
|
equals(function() {
|
2011-05-21 09:28:20 -04:00
|
|
|
return project.layers[0] == secondLayer
|
|
|
|
&& project.layers[1] == firstLayer;
|
2011-05-20 19:42:33 -04:00
|
|
|
}, true);
|
2012-11-19 23:41:04 -05:00
|
|
|
});
|