Skip to content

Commit

Permalink
adding suppport for parent() to api
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Newcome committed Apr 13, 2012
1 parent 6531144 commit 3d13c37
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
4 changes: 4 additions & 0 deletions donatello.js
Expand Up @@ -209,6 +209,10 @@ Donatello.prototype.node = function() {
return this.dom;
}

Donatello.prototype.parent = function() {
return this._parent;
}

/**
* Setting attributes looks for mapped attributes first, then
* passes attribute through as a CSS attribute.
Expand Down
2 changes: 2 additions & 0 deletions rect.js
Expand Up @@ -22,6 +22,7 @@ Donatello.Pgram = function( parent, x, y, dx, dy, skew, a ) {
'fill': f
};
parent.dom.appendChild( el );
this._parent = parent;
this.dom = el;
this.attr( a );
}
Expand All @@ -36,6 +37,7 @@ Donatello.Pgram.prototype.draw = function() {
el.style.borderWidth = this.properties['stroke-width'] + 'px';

if( skew != null ) {
console.log( 'setting skew ' + skew );
el.style[ Donatello.getTransform() ] += 'skew(' + skew + 'deg)';
}

Expand Down
42 changes: 42 additions & 0 deletions tests/api.html
@@ -0,0 +1,42 @@
<!doctype html>
<html>
<head>
<!-- test the donatello api features. -->
<script src="../donatello.js" type="text/javascript"></script>
<script src="../rect.js" type="text/javascript"></script>
<script>
var line;

function main() {
var paper = Donatello.paper('paper-div', 20, 20, 300, 300 );

// common attributes
var attrs = {
stroke:'red',
'stroke-width':5
};

// nested objects using chaining
paper
.rect( 0, 0, 50, 50, attrs )
.rect( 10, 10, 50, 50, attrs );

// sibling objects using chaining
paper
.rect( 20, 20, 50, 50, attrs ).parent()
.rect( 40, 40, 50, 50, attrs );
}

</script>
<style>
#paper-div {
border: 1px solid black
}
</style>

</head>
<body onload='main();'>
<div id="paper-div">
</div>
</body>
</html>

0 comments on commit 3d13c37

Please sign in to comment.