From: Chris Thronebury Date: Sun, 26 Jun 2016 15:20:53 +0000 (-0400) Subject: Add check if key exists in map X-Git-Tag: v6.2.4-rc1~57^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F8972%2Fhead;p=thirdparty%2Ffoundation%2Ffoundation-sites.git Add check if key exists in map --- diff --git a/scss/util/_breakpoint.scss b/scss/util/_breakpoint.scss index ddcf80aa0..3e5a89827 100644 --- a/scss/util/_breakpoint.scss +++ b/scss/util/_breakpoint.scss @@ -175,21 +175,26 @@ $breakpoint-classes: (small medium large) !default; /// /// @returns {Mixed} The value for the key after `$key`, if `$key` was found. If `$key` was not found, or `$key` was the last value in the map, returns `null`. @function -zf-map-next($map, $key) { - // Store the values of the map as a list, so we can access them with nth + + // Store the keys of the map as a list $values: map-keys($map); - // Get the index of the key within the map and add 1 to it for the next breakpoint in the map - $i: index($values, $key) + 1; + $i: 0; + + // If the Key Exists, Get the index of the key within the map and add 1 to it for the next breakpoint in the map + @if (map-has-key($map, $key)) { + $i: index($values, $key) + 1; + } // If the key doesn't exist, or it's the last key in the map, return null - @if $i > length($map) { + @if ($i > length($map) or $i == 0) { @return null; } // Otherwise, return the value @else { @return map-get($map, nth($values, $i)); - } + } /// Get a value for a breakpoint from a responsive config map. If the config map has the key `$value`, the exact breakpoint value is returned. If the config map does *not* have the breakpoint, the value matching the next lowest breakpoint in the config map is returned.