UNPKG

browsernizr

Version:

Modernizr wrapper for use with browserify

40 lines (32 loc) 1.21 kB
/** * wrapper around getComputedStyle, to fix issues with Firefox returning null when * called inside of a hidden iframe * * @access private * @function computedStyle * @param {HTMLElement|SVGElement} elem - The element we want to find the computed styles of * @param {string|null} [pseudo] - An optional pseudo element selector (e.g. :before), of null if none * @param {string} prop - A CSS property * @returns {CSSStyleDeclaration} the value of the specified CSS property */ function computedStyle(elem, pseudo, prop) { var result; if ('getComputedStyle' in window) { result = getComputedStyle.call(window, elem, pseudo); var console = window.console; if (result !== null) { if (prop) { result = result.getPropertyValue(prop); } } else { if (console) { var method = console.error ? 'error' : 'log'; console[method].call(console, 'getComputedStyle returning null, its possible modernizr test results are inaccurate'); } } } else { result = !pseudo && elem.currentStyle && elem.currentStyle[prop]; } return result; } module.exports = computedStyle;