]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
Added proposed public is() method for use in plugins
authorauginator <amsevilla3@gmail.com>
Thu, 7 Jul 2016 15:33:30 +0000 (11:33 -0400)
committerauginator <amsevilla3@gmail.com>
Thu, 7 Jul 2016 15:33:30 +0000 (11:33 -0400)
Accepts either ‘[breakpoint] only’ or ‘[breakpoint]’ - in the former
case, it will see if the breakpoint matches exactly, and in the latter,
it falls back to atLeast(). I was thinking this would be a good way for
plugins to target a specific breakpoint, rather than being limited to
atLeast.

js/foundation.util.mediaQuery.js

index baa1f0b8721c69adca213ed737a0271aae7396cc..298bd56acebd638ecb6285f8f30eeab5e6f65261 100644 (file)
@@ -60,6 +60,22 @@ var MediaQuery = {
     return false;
   },
 
+  /**
+   * Checks if the screen matches to a breakpoint. 
+   * @function
+   * @param {String} size - Name of the breakpoint to check, either 'small only' or 'small'. Omitting 'only' falls back to using atLeast() method.
+   * @returns {Boolean} `true` if the breakpoint matches, `false` if it does not.
+   */
+  is(size) {
+    size = size.trim().split(' ');
+    if(size.length > 0 && size[1] === 'only') {
+      if(size[0] === this._getCurrentSize()) return true;
+    } else {
+      return this.atLeast(size[0]);
+    }
+    return false;
+  },
+
   /**
    * Gets the media query of a breakpoint.
    * @function