]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
feat: add "MediaQuery.only()"
authorNicolas Coden <nicolas@ncoden.fr>
Sat, 11 Aug 2018 22:05:38 +0000 (00:05 +0200)
committerDaniel Ruf <mac1@daniel-ruf.de>
Sun, 17 Nov 2019 15:49:45 +0000 (16:49 +0100)
Add method:
* `MediaQuery.only(size)`
  Checks if the screen is within the given breakpoint.
  If smaller than the breakpoint of wider than its upper limit, returns false.

js/foundation.util.mediaQuery.js

index 9a9931c1f2c586e07eb7fcfecbbee2fe2c075ffb..ef31362c62a7b7ed0bf7fa5da2ea42f8684714c4 100644 (file)
@@ -142,6 +142,17 @@ var MediaQuery = {
     return false;
   },
 
+  /**
+   * Checks if the screen is within the given breakpoint.
+   * If smaller than the breakpoint of wider than its upper limit, returns false.
+   * @function
+   * @param {String} size - Name of the breakpoint to check.
+   * @returns {Boolean} `true` if the breakpoint matches, `false` otherwise.
+   */
+  only(size) {
+    return size === this._getCurrentSize();
+  },
+
   /**
    * Checks if the screen is within a breakpoint or smaller.
    * @function
@@ -174,7 +185,7 @@ var MediaQuery = {
 
     // Only the breakpont
     if (bpModifier === 'only') {
-      return bpSize === this._getCurrentSize();
+      return this.only(bpSize);
     }
     // Up to the breakpoint (included)
     if (bpModifier === 'down') {