Browse files

adding suppport for parent() to api

  • Loading branch information...
1 parent 6531144 commit 3d13c37a933e0af3c0cd8c4437e9d587c0331854 @dnewcome committed Apr 12, 2012
Showing with 48 additions and 0 deletions.
  1. +4 −0 donatello.js
  2. +2 −0 rect.js
  3. +42 −0 tests/api.html
View
4 donatello.js
@@ -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.
View
2 rect.js
@@ -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 );
}
@@ -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)';
}
View
42 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.