Permalink
Browse files

Move the updateSize and updateProps methods up into RendererBase as t…

…hey do the same thing for every renderer
  • Loading branch information...
1 parent 1e1b0fa commit 29243e2acb55f618f63d28689edae024a3e5fd65 Jason Johnston committed Nov 3, 2010
@@ -23,19 +23,6 @@ PIE.BackgroundRenderer = PIE.RendererBase.newRenderer( {
( si.boxShadowInfo.isActive() && si.boxShadowInfo.getProps().inset );
},
- updateSize: function() {
- if( this.isActive() ) {
- this.draw();
- }
- },
-
- updateProps: function() {
- this.destroy();
- if( this.isActive() ) {
- this.draw();
- }
- },
-
/**
* Draw the shapes
*/
@@ -19,84 +19,73 @@ PIE.BorderImageRenderer = PIE.RendererBase.newRenderer( {
return this.styleInfos.borderImageInfo.isActive();
},
- updateSize: function() {
- if( this.isActive() ) {
- var props = this.styleInfos.borderImageInfo.getProps(),
- bounds = this.boundsInfo.getBounds(),
- box = this.getBox(), //make sure pieces are created
- el = this.targetElement,
- pieces = this.pieces;
-
- PIE.Util.withImageSize( props.src, function( imgSize ) {
- var elW = bounds.w,
- elH = bounds.h,
-
- widths = props.width,
- widthT = widths.t.pixels( el ),
- widthR = widths.r.pixels( el ),
- widthB = widths.b.pixels( el ),
- widthL = widths.l.pixels( el ),
- slices = props.slice,
- sliceT = slices.t.pixels( el ),
- sliceR = slices.r.pixels( el ),
- sliceB = slices.b.pixels( el ),
- sliceL = slices.l.pixels( el );
-
- // Piece positions and sizes
- function setSizeAndPos( piece, w, h, x, y ) {
- var s = pieces[piece].style;
- s.width = w;
- s.height = h;
- s.left = x;
- s.top = y;
- }
- setSizeAndPos( 'tl', widthL, widthT, 0, 0 );
- setSizeAndPos( 't', elW - widthL - widthR, widthT, widthL, 0 );
- setSizeAndPos( 'tr', widthR, widthT, elW - widthR, 0 );
- setSizeAndPos( 'r', widthR, elH - widthT - widthB, elW - widthR, widthT );
- setSizeAndPos( 'br', widthR, widthB, elW - widthR, elH - widthB );
- setSizeAndPos( 'b', elW - widthL - widthR, widthB, widthL, elH - widthB );
- setSizeAndPos( 'bl', widthL, widthB, 0, elH - widthB );
- setSizeAndPos( 'l', widthL, elH - widthT - widthB, 0, widthT );
- setSizeAndPos( 'c', elW - widthL - widthR, elH - widthT - widthB, widthL, widthT );
-
-
- // image croppings
- function setCrops( sides, crop, val ) {
- for( var i=0, len=sides.length; i < len; i++ ) {
- pieces[ sides[i] ]['imagedata'][ crop ] = val;
- }
+ draw: function() {
+ var props = this.styleInfos.borderImageInfo.getProps(),
+ bounds = this.boundsInfo.getBounds(),
+ box = this.getBox(), //make sure pieces are created
+ el = this.targetElement,
+ pieces = this.pieces;
+
+ PIE.Util.withImageSize( props.src, function( imgSize ) {
+ var elW = bounds.w,
+ elH = bounds.h,
+
+ widths = props.width,
+ widthT = widths.t.pixels( el ),
+ widthR = widths.r.pixels( el ),
+ widthB = widths.b.pixels( el ),
+ widthL = widths.l.pixels( el ),
+ slices = props.slice,
+ sliceT = slices.t.pixels( el ),
+ sliceR = slices.r.pixels( el ),
+ sliceB = slices.b.pixels( el ),
+ sliceL = slices.l.pixels( el );
+
+ // Piece positions and sizes
+ function setSizeAndPos( piece, w, h, x, y ) {
+ var s = pieces[piece].style;
+ s.width = w;
+ s.height = h;
+ s.left = x;
+ s.top = y;
+ }
+ setSizeAndPos( 'tl', widthL, widthT, 0, 0 );
+ setSizeAndPos( 't', elW - widthL - widthR, widthT, widthL, 0 );
+ setSizeAndPos( 'tr', widthR, widthT, elW - widthR, 0 );
+ setSizeAndPos( 'r', widthR, elH - widthT - widthB, elW - widthR, widthT );
+ setSizeAndPos( 'br', widthR, widthB, elW - widthR, elH - widthB );
+ setSizeAndPos( 'b', elW - widthL - widthR, widthB, widthL, elH - widthB );
+ setSizeAndPos( 'bl', widthL, widthB, 0, elH - widthB );
+ setSizeAndPos( 'l', widthL, elH - widthT - widthB, 0, widthT );
+ setSizeAndPos( 'c', elW - widthL - widthR, elH - widthT - widthB, widthL, widthT );
+
+
+ // image croppings
+ function setCrops( sides, crop, val ) {
+ for( var i=0, len=sides.length; i < len; i++ ) {
+ pieces[ sides[i] ]['imagedata'][ crop ] = val;
}
+ }
- // corners
- setCrops( [ 'tl', 't', 'tr' ], 'cropBottom', ( imgSize.h - sliceT ) / imgSize.h );
- setCrops( [ 'tl', 'l', 'bl' ], 'cropRight', ( imgSize.w - sliceL ) / imgSize.w );
- setCrops( [ 'bl', 'b', 'br' ], 'cropTop', ( imgSize.h - sliceB ) / imgSize.h );
- setCrops( [ 'tr', 'r', 'br' ], 'cropLeft', ( imgSize.w - sliceR ) / imgSize.w );
-
- // edges and center
- if( props.repeat.v === 'stretch' ) {
- setCrops( [ 'l', 'r', 'c' ], 'cropTop', sliceT / imgSize.h );
- setCrops( [ 'l', 'r', 'c' ], 'cropBottom', sliceB / imgSize.h );
- }
- if( props.repeat.h === 'stretch' ) {
- setCrops( [ 't', 'b', 'c' ], 'cropLeft', sliceL / imgSize.w );
- setCrops( [ 't', 'b', 'c' ], 'cropRight', sliceR / imgSize.w );
- }
+ // corners
+ setCrops( [ 'tl', 't', 'tr' ], 'cropBottom', ( imgSize.h - sliceT ) / imgSize.h );
+ setCrops( [ 'tl', 'l', 'bl' ], 'cropRight', ( imgSize.w - sliceL ) / imgSize.w );
+ setCrops( [ 'bl', 'b', 'br' ], 'cropTop', ( imgSize.h - sliceB ) / imgSize.h );
+ setCrops( [ 'tr', 'r', 'br' ], 'cropLeft', ( imgSize.w - sliceR ) / imgSize.w );
- // center fill
- pieces['c'].style.display = props.fill ? '' : 'none';
- }, this );
- } else {
- this.destroy();
- }
- },
+ // edges and center
+ if( props.repeat.v === 'stretch' ) {
+ setCrops( [ 'l', 'r', 'c' ], 'cropTop', sliceT / imgSize.h );
+ setCrops( [ 'l', 'r', 'c' ], 'cropBottom', sliceB / imgSize.h );
+ }
+ if( props.repeat.h === 'stretch' ) {
+ setCrops( [ 't', 'b', 'c' ], 'cropLeft', sliceL / imgSize.w );
+ setCrops( [ 't', 'b', 'c' ], 'cropRight', sliceR / imgSize.w );
+ }
- updateProps: function() {
- this.destroy();
- if( this.isActive() ) {
- this.updateSize();
- }
+ // center fill
+ pieces['c'].style.display = props.fill ? '' : 'none';
+ }, this );
},
getBox: function() {
@@ -46,24 +46,10 @@ PIE.BorderRenderer = PIE.RendererBase.newRenderer( {
si.borderInfo.isActive(); //check BorderStyleInfo last because it's the most expensive
},
- updateSize: function() {
- if( this.isActive() ) {
- this.drawBorder();
- }
- },
-
- updateProps: function() {
- this.destroy();
- if( this.isActive() ) {
- this.drawBorder();
- }
- },
-
-
/**
* Draw the border shape(s)
*/
- drawBorder: function() {
+ draw: function() {
var el = this.targetElement,
cs = el.currentStyle,
props = this.styleInfos.borderInfo.getProps(),
Oops, something went wrong. Retry.

0 comments on commit 29243e2

Please sign in to comment.