1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | function classNames() {
|
8 | var classes = '';
|
9 | var arg;
|
10 |
|
11 | for (var i = 0; i < arguments.length; i++) {
|
12 | arg = arguments[i];
|
13 | if (!arg) {
|
14 | continue;
|
15 | }
|
16 |
|
17 | if ('string' === typeof arg || 'number' === typeof arg) {
|
18 | classes += ' ' + arg;
|
19 | } else if (Object.prototype.toString.call(arg) === '[object Array]') {
|
20 | classes += ' ' + classNames.apply(null, arg);
|
21 | } else if ('object' === typeof arg) {
|
22 | for (var key in arg) {
|
23 | if (!arg.hasOwnProperty(key) || !arg[key]) {
|
24 | continue;
|
25 | }
|
26 | classes += ' ' + key;
|
27 | }
|
28 | }
|
29 | }
|
30 | return classes.substr(1);
|
31 | }
|
32 |
|
33 |
|
34 | if (typeof module !== 'undefined' && module.exports) {
|
35 | module.exports = classNames;
|
36 | }
|
37 |
|
38 |
|
39 | if (typeof define !== 'undefined' && define.amd) {
|
40 | define('classnames', [], function() {
|
41 | return classNames;
|
42 | });
|
43 | }
|