Skip to content

Instantly share code, notes, and snippets.

@stryju
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stryju/12467dc7860fea7ef65c to your computer and use it in GitHub Desktop.
Save stryju/12467dc7860fea7ef65c to your computer and use it in GitHub Desktop.
get inline SVG size in Firefox (AMD way)
/* 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