Skip to content

Commit 72a40f2

Browse files
committed
init
0 parents  commit 72a40f2

File tree

5 files changed

+197
-0
lines changed

5 files changed

+197
-0
lines changed

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
The MIT License (MIT)
3+
4+
Copyright (c) 2014 Jonathan Ong [email protected]
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
THE SOFTWARE.

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
# Flex
3+
4+
Detect flex support.
5+
Note that it uses the same exact keys Modernizr,
6+
but that's subject to change.

build/index.js

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/**
2+
* Require the module at `name`.
3+
*
4+
* @param {String} name
5+
* @return {Object} exports
6+
* @api public
7+
*/
8+
9+
function require(name) {
10+
var module = require.modules[name];
11+
if (!module) throw new Error('failed to require "' + name + '"');
12+
13+
var definition = module.definition;
14+
if (definition) {
15+
definition.call(this, module.exports = {}, module);
16+
delete module.definition;
17+
}
18+
19+
return module.exports;
20+
}
21+
22+
/**
23+
* Registered modules.
24+
*/
25+
26+
require.modules = {};
27+
28+
/**
29+
* Register module at `name` with callback `definition`.
30+
*
31+
* @param {String} name
32+
* @param {Function} definition
33+
* @api private
34+
*/
35+
36+
require.register = function (name, definition) {
37+
require.modules[name] = {
38+
definition: definition
39+
};
40+
};
41+
42+
require.register("./index.js", function (exports, module) {
43+
44+
// http://caniuse.com/flexbox
45+
46+
var html = document.documentElement
47+
48+
var prefixes = [
49+
'-webkit-',
50+
'-moz-',
51+
'-ms-',
52+
'-o-',
53+
''
54+
]
55+
56+
var supported
57+
58+
cssflex()
59+
60+
module.exports = cssflex
61+
62+
function cssflex() {
63+
if (supported) return supported
64+
65+
supported = {}
66+
67+
// tests
68+
test('flex-basis: 1px;', 'flexbox')
69+
test('box-direction: reverse;', 'flexboxlegacy')
70+
test('flex-align: end;', 'flexboxtweener')
71+
test('flex-wrap: wrap;', 'flexwrap')
72+
73+
// aliases
74+
supported.flex = supported.flexbox
75+
supported.legacy = supported.flexboxlegacy
76+
supported.tweener = supported.flexboxtweener
77+
supported.wrap = supported.flexwrap
78+
79+
return supported
80+
}
81+
82+
function test(prop, name) {
83+
var el = document.createElement('div')
84+
el.style.cssText = prefix(prop)
85+
supported[name] = !!el.style.length
86+
html.className += ' ' + (supported[name] ? '' : 'no-') + name
87+
}
88+
89+
function prefix(str) {
90+
var out = ''
91+
for (var i = 0; i < prefixes.length; i++) {
92+
out += prefixes[i] + str
93+
}
94+
return out
95+
}
96+
97+
})
98+
99+
require("./index.js");

index.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
2+
// http://caniuse.com/flexbox
3+
4+
var html = document.documentElement
5+
6+
var prefixes = [
7+
'-webkit-',
8+
'-moz-',
9+
'-ms-',
10+
'-o-',
11+
''
12+
]
13+
14+
var supported
15+
16+
cssflex()
17+
18+
export default cssflex
19+
20+
function cssflex() {
21+
if (supported) return supported
22+
23+
supported = {}
24+
25+
// tests
26+
test('flex-basis: 1px;', 'flexbox')
27+
test('box-direction: reverse;', 'flexboxlegacy')
28+
test('flex-align: end;', 'flexboxtweener')
29+
test('flex-wrap: wrap;', 'flexwrap')
30+
31+
// aliases
32+
supported.flex = supported.flexbox
33+
supported.legacy = supported.flexboxlegacy
34+
supported.tweener = supported.flexboxtweener
35+
supported.wrap = supported.flexwrap
36+
37+
return supported
38+
}
39+
40+
function test(prop, name) {
41+
var el = document.createElement('div')
42+
el.style.cssText = prefix(prop)
43+
supported[name] = !!el.style.length
44+
html.className += ' ' + (supported[name] ? '' : 'no-') + name
45+
}
46+
47+
function prefix(str) {
48+
var out = ''
49+
for (var i = 0; i < prefixes.length; i++) {
50+
out += prefixes[i] + str
51+
}
52+
return out
53+
}

test.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>CSS Flex</title>
5+
</head>
6+
<body>
7+
<script src="build/index.js"></script>
8+
<script>
9+
var support = require('./index.js')()
10+
Object.keys(support).forEach(function (name) {
11+
var p = document.createElement('p')
12+
p.textContent = name + ': ' + (support[name] ? 'yes' : 'no')
13+
document.body.appendChild(p)
14+
})
15+
</script>
16+
</body>
17+
</html>

0 commit comments

Comments
 (0)