Skip to content

Instantly share code, notes, and snippets.

@atk
Forked from 140bytes/LICENSE.txt
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atk/c191d9b2e0c37d032182 to your computer and use it in GitHub Desktop.
Save atk/c191d9b2e0c37d032182 to your computer and use it in GitHub Desktop.
FlexWrap Support Detection

FlexWrap Support Detection

A small snippet (106 characters) to detect if the browser supports the flex-wrap attribute (a lack of support could lead to an inability to render certain layouts)

function a(b){ // b is undefined on inital call, on regex call it will contain the prefix + f/F
return !b ?
'f0OF0MozF0WebkitF0msF'.replace(/[^0]+/g, a) > 0 : // on undefined b, run a regex through the function
// matching attributes will yield 1, unmatching will result in 0; we compare the result '0000' or '0100' to 0
+(b+'lexWrap' in document.body.style) // test if the flexwrap (or its browser-specific notation) is present,
// coerce the result to number: true => 1, false => 0
}
function a(b){return!b?'f0OF0MozF0WebkitF0msF'.replace(/[^0]+/g,a)>0:+(b+'lexWrap'in document.body.style)}
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2015 Alex Lohr (formerly Kloss) alexthkloss@web.de
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
{
"name": "SupportsFlexWrap",
"description": "Detect FlexWrap support",
"keywords": [
"CSS3",
"flexbox",
"flexwrap",
"flex",
"wrap"
]
}
<!DOCTYPE html>
<title>Foo</title>
<div>Expected value: <b>true/false</b></div>
<div>Actual value: <b id="ret"></b></div>
<script>
// write a small example that shows off the API for your example
// and tests it in one fell swoop.
var myFunction = function a(b){return!b?'f0OF0MozF0WebkitF0msF'.replace(/[^0]+/g,a)>0:+(b+'lexWrap'in document.body.style)}
document.getElementById( "ret" ).innerHTML = myFunction()
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment