Permalink
Browse files

raphael compatibility shim and support for gradients

  • Loading branch information...
1 parent 417607f commit 77e7fe556e63e653e1bea4e349a5ab6edf23105a dnewcome committed Sep 3, 2011
Showing with 73 additions and 4 deletions.
  1. +24 −1 donatello.js
  2. +49 −3 rcompat.js
View
25 donatello.js
@@ -172,7 +172,7 @@ Donatello.createLinearGradient = function( deg, color1, color2 ) {
color1 + ',' + color2 + ')';
break;
}
- console.log( 'gradient: ' + retval );
+ // console.log( 'gradient: ' + retval );
return retval;
}
@@ -259,6 +259,29 @@ Donatello.prototype.attr = function( obj ) {
// TODO: see about simplifying this stuff
this.dom.style[mapping[attr]] = obj[attr] + 'px';
}
+ else if( attr == 'fill' ) {
+ // hacky way to check for gradient spec
+ if( obj['fill'] && obj['fill'].length > 7 ) {
+ var str = obj['fill'];
+ this.dom.style['backgroundImage'] = Donatello.createLinearGradient(
+ str.substr( 0, 2 ),
+ str.substr( 3, 7 ),
+ str.substr( 11, 7 )
+ );
+ }
+ else {
+ this.dom.style[mapping[attr]] = obj[attr];
+ }
+ }
+ // scale in raphael has a center point. Need to convert
+ // that to transformOrigin.
+ else if( attr == 'scale' ) {
+ /*
+ Pretty sure this isn't going to work this easily
+ console.log('scaling');
+ this.dom.style['transform'] = 'scale( ' + obj[attr]+ ' )';
+ */
+ }
else {
this.dom.style[mapping[attr]] = obj[attr];
}
View
52 rcompat.js
@@ -10,9 +10,55 @@ Donatello.prototype.drag = function( onmove, onstart, onend ) {
stop: onend,
drag: onmove
} );
+};
+
+Donatello.prototype.click = function( fn ) {
+ $( this.dom ).click( fn );
+}
+
+Donatello.prototype.mousedown = function( fn ) {
+ $( this.dom ).mousedown( fn );
}
-Donatello.prototype.click = function() {}
+Donatello.prototype.mouseup = function( fn ) {
+ $( this.dom ).mouseup( fn );
+}
+
+Donatello.prototype.mousemove = function( fn ) {
+ $( this.dom ).mousemove( fn );
+}
+
+Donatello.prototype.mouseout = function( fn ) {
+ $( this.dom ).mouseout( fn );
+}
+
+Donatello.prototype.mouseover = function( fn ) {
+ $( this.dom ).mouseover( fn );
+}
+
+Donatello.prototype.toFront = function() {
+ // TODO: not a good way to do this in jQuery
+}
+
+Donatello.prototype.remove = function() {
+ $( this.dom ).remove();
+}
+
+Donatello.prototype.clone = function() {
+ var el = $( this.dom ).clone();
+ var don = new Donatello( el );
+ return don;
+}
+
+/**
+* Override rect function to take border radius
+*/
+Donatello.prototype._rect = Donatello.prototype.rect;
+Donatello.prototype.rect = function( x, y, w, h, r, a ) {
+ var a = a || {};
+ a.borderRadius = r + 'px';
+ return this._rect( x, y, w, h, a );
+}
/**
* Named plural to disambiguate from
@@ -23,12 +69,12 @@ Donatello.prototype.click = function() {}
* Not a complete list, just enough to migrate some
* legacy code.
*/
-Donatello.prototype.attrs() {
+Donatello.prototype.attrs = function() {
var retval = {
x: this.dom.offsetLeft,
y: this.dom.offsetTop,
w: this.dom.offsetWidth,
h: this.dom.offsetHeight
};
return retval;
-}
+};

0 comments on commit 77e7fe5

Please sign in to comment.