Last active
August 29, 2015 14:02
-
-
Save stryju/12467dc7860fea7ef65c to your computer and use it in GitHub Desktop.
get inline SVG size in Firefox (AMD way)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* global | |
define: false | |
*/ | |
define( function ( ) { | |
'use strict'; | |
function px( cs, prop ) { | |
return parseInt( cs.getPropertyValue( prop ) || 0, 10 ); | |
} | |
function getWidth( cs, sizing ) { | |
var width = px( cs, 'width' ); | |
if ( ! /border-box/i.test( sizing ) ) { | |
width += px( cs, 'borderLeftWidth' ); | |
width += px( cs, 'paddingLeft' ); | |
width += px( cs, 'paddingRight' ); | |
width += px( cs, 'borderRightWidth' ); | |
} | |
return width; | |
} | |
function getHeight( cs, sizing ) { | |
var height = px( cs, 'height' ); | |
if ( ! /border-box/i.test( sizing ) ) { | |
height += px( cs, 'borderTopWidth' ); | |
height += px( cs, 'paddingTop' ); | |
height += px( cs, 'paddingBottom' ); | |
height += px( cs, 'borderBottomWidth' ); | |
} | |
return height; | |
} | |
function size( element ) { | |
var cs = getComputedStyle( element ); | |
var sizing = cs.boxSizing || cs.webkitBoxSizing || cs.MozBoxSizing; | |
return { | |
width : getWidth( cs, sizing ), | |
height : getHeight( cs, sizing ) | |
}; | |
} | |
return size; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment