FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
react-grid-layout/lib/responsiveUtils.js at master · appgit/react-grid-layout · GitHub
appgit
/
react-grid-layout
Public
forked from
react-grid-layout/react-grid-layout
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
react-grid-layout
/
lib
/
responsiveUtils.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
84 lines (76 loc) · 3.02 KB
Breadcrumbs
react-grid-layout
/
lib
/
responsiveUtils.js
Copy path
File metadata and controls
84 lines (76 loc) · 3.02 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
'use strict'
;
var
utils
=
require
(
'./utils'
)
;
var
responsiveUtils
=
module
.
exports
=
{
/**
* Given a width, find the highest breakpoint that matches is valid for it (width > breakpoint).
*
*
@param
{
Object
} breakpoints Breakpoints object (e.g. {lg: 1200, md: 960, ...})
*
@param
{
Number
} width Screen width.
*
@return
{
String
} Highest breakpoint that is less than width.
*/
getBreakpointFromWidth
(
breakpoints
,
width
)
{
var
sorted
=
responsiveUtils
.
sortBreakpoints
(
breakpoints
)
;
var
matching
=
sorted
[
0
]
;
for
(
var
i
=
1
,
len
=
sorted
.
length
;
i
<
len
;
i
++
)
{
var
breakpointName
=
sorted
[
i
]
;
if
(
width
>
breakpoints
[
breakpointName
]
)
matching
=
breakpointName
;
}
return
matching
;
}
,
/**
* Given a breakpoint, get the # of cols set for it.
*
@param
{
String
} breakpoint Breakpoint name.
*
@param
{
Object
} cols Map of breakpoints to cols.
*
@return
{
Number
} Number of cols.
*/
getColsFromBreakpoint
(
breakpoint
,
cols
)
{
if
(
!
cols
[
breakpoint
]
)
{
throw
new
Error
(
"ResponsiveReactGridLayout: `cols` entry for breakpoint "
+
breakpoint
+
" is missing!"
)
;
}
return
cols
[
breakpoint
]
;
}
,
/**
* Given existing layouts and a new breakpoint, find or generate a new layout.
*
* This finds the layout above the new one and generates from it, if it exists.
*
*
@param
{
Array
} layouts Existing layouts.
*
@param
{
Array
} breakpoints All breakpoints.
*
@param
{
String
} breakpoint New breakpoint.
*
@param
{
String
} breakpoint Last breakpoint (for fallback).
*
@param
{
Number
} cols Column count at new breakpoint.
*
@param
{
Boolean
} verticalCompact Whether or not to compact the layout
* vertically.
*
@return
{
Array
} New layout.
*/
findOrGenerateResponsiveLayout
(
layouts
,
breakpoints
,
breakpoint
,
lastBreakpoint
,
cols
,
verticalCompact
)
{
// If it already exists, just return it.
if
(
layouts
[
breakpoint
]
)
return
layouts
[
breakpoint
]
;
// Find or generate the next layout
var
layout
=
layouts
[
lastBreakpoint
]
;
var
breakpointsSorted
=
responsiveUtils
.
sortBreakpoints
(
breakpoints
)
;
var
breakpointsAbove
=
breakpointsSorted
.
slice
(
breakpointsSorted
.
indexOf
(
breakpoint
)
)
;
for
(
var
i
=
0
,
len
=
breakpointsAbove
.
length
;
i
<
len
;
i
++
)
{
var
b
=
breakpointsAbove
[
i
]
;
if
(
layouts
[
b
]
)
{
layout
=
layouts
[
b
]
;
break
;
}
}
layout
=
JSON
.
parse
(
JSON
.
stringify
(
layout
||
[
]
)
)
;
// clone layout so we don't modify existing items
return
utils
.
compact
(
utils
.
correctBounds
(
layout
,
{
cols
:
cols
}
)
,
verticalCompact
)
;
}
,
/**
* Given breakpoints, return an array of breakpoints sorted by width. This is usually
* e.g. ['xxs', 'xs', 'sm', ...]
*
*
@param
{
Object
} breakpoints Key/value pair of breakpoint names to widths.
*
@return
{
Array
} Sorted breakpoints.
*/
sortBreakpoints
(
breakpoints
)
{
var
keys
=
Object
.
keys
(
breakpoints
)
;
return
keys
.
sort
(
function
(
a
,
b
)
{
return
breakpoints
[
a
]
-
breakpoints
[
b
]
;
}
)
;
}
}
;
Back
|
FazBrowse Home
|
New Git URL