From 7c45c30ce958394f6d09f12c79be6f18fbc426f3 Mon Sep 17 00:00:00 2001 From: Sebastian Lasse Date: Wed, 17 Feb 2016 18:56:26 +0100 Subject: [PATCH] getEmSize had wrong Syntax for 'getComputedStyle' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • The function getEmSize had a wrong Syntax for 'getComputedStyle', the 2nd parameter is only for pseudo selectors and it will return all styles, see [docs](https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle?redirectlocale=en-US&redirectslug=DOM%2Fwindow.getComputedStyle) • The function convertToPx did not work for floats, I guess ... E.g. `1.8rem`'s units became '.8rem' and so the switch failed... Corrected both. --- src/ElementQueries.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ElementQueries.js b/src/ElementQueries.js index 1a08208..c98329a 100755 --- a/src/ElementQueries.js +++ b/src/ElementQueries.js @@ -31,7 +31,7 @@ if (!element) { element = document.documentElement; } - var fontSize = getComputedStyle(element, 'fontSize'); + var fontSize = window.getComputedStyle(element, null).fontSize; return parseFloat(fontSize) || 16; } @@ -44,7 +44,8 @@ * @returns {*} */ function convertToPx(element, value) { - var units = value.replace(/[0-9]*/, ''); + var numbers = value.split(/\d/); + var units = numbers[numbers.length-1]; value = parseFloat(value); switch (units) { case "px":