]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
refactor: move MediaQuery query name resolution to "_getQueryName()"
authorNicolas Coden <nicolas@ncoden.fr>
Sat, 11 Aug 2018 20:42:56 +0000 (22:42 +0200)
committerDaniel Ruf <mac1@daniel-ruf.de>
Sun, 17 Nov 2019 15:49:40 +0000 (16:49 +0100)
js/foundation.util.mediaQuery.js

index cd3f5888b8c261c70eda1423e082667166f3564e..66af3bbc3fd8531116885efd0e01df4b365d7353 100644 (file)
@@ -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);
   },
 
   /**