From: Nicolas Coden Date: Sat, 11 Aug 2018 20:42:56 +0000 (+0200) Subject: refactor: move MediaQuery query name resolution to "_getQueryName()" X-Git-Tag: v6.6.0~1^2~2^2~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=52ff8865385304b16f730dc3a0b02bd8e711d88f;p=thirdparty%2Ffoundation%2Ffoundation-sites.git refactor: move MediaQuery query name resolution to "_getQueryName()" --- diff --git a/js/foundation.util.mediaQuery.js b/js/foundation.util.mediaQuery.js index cd3f5888b..66af3bbc3 100644 --- a/js/foundation.util.mediaQuery.js +++ b/js/foundation.util.mediaQuery.js @@ -205,6 +205,24 @@ var MediaQuery = { return null; }, + /** + * Returns the name of the breakpoint related to the given value. + * @function + * @private + * @param {String|Object} value - Breakpoint name or query object. + * @returns {String} Name of the breakpoint. + */ + _getQueryName(value) { + if (typeof value === 'string') + return value; + if (typeof value === 'object') + return value.name; + throw new TypeError(` + invalid value passed to MediaQuery._getQueryName(). + Expected a breakpoint name (String) or a query object, got "${value}" + `); + }, + /** * Gets the current breakpoint name by testing every breakpoint and returning the last one to match (the biggest one). * @function @@ -222,11 +240,7 @@ var MediaQuery = { } } - if (typeof matched === 'object') { - return matched.name; - } else { - return matched; - } + return matched && this._getQueryName(matched); }, /**