forked from gridstack/gridstack.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsizeToContent.html
90 lines (88 loc) · 3.49 KB
/
sizeToContent.html
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
85
86
87
88
89
90
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>sizeToContent demo</title>
<link rel="stylesheet" href="demo.css"/>
<link rel="stylesheet" href="../dist/gridstack-extra.css"/>
<script src="../dist/gridstack-all.js"></script>
<style type="text/css">
.grid-stack-item-content {
text-align: unset;
}
</style>
</head>
<body>
<div class="container">
<h1>Cell sizeToContent options demo</h1>
<p>new 9.x feature that size the items to fit their content height as to not have scroll bars
(unless `sizeToContent:false` in C: case). Defaulting to different initial size (see code) to show grow/shrink behavior.</p>
<div>
column:
<a onClick="column(8)" class="btn btn-primary" href="#">8</a>
<a onClick="column(12)" class="btn btn-primary" href="#">12</a>
cellHeight:
<a onClick="cellHeight(25)" class="btn btn-primary" href="#">25</a>
<a onClick="cellHeight(50)" class="btn btn-primary" href="#">50</a>
<a onClick="cellHeight(75)" class="btn btn-primary" href="#">75</a>
Widget:
<a onClick="addWidget()" class="btn btn-primary" href="#">Add</a>
<a onClick="makeWidget()" class="btn btn-primary" href="#">Make</a>
</div>
<br>
<div class="grid-stack"></div>
</div>
<script type="text/javascript">
let opts = {
margin: 5,
cellHeight: 50,
sizeToContent: true, // default to make them all fit
resizable: { handles: 'all'} // do all sides for testing
// cellHeightThrottle: 100, // ms before sizeToContent happens
}
let grid = GridStack.init(opts);
let text ='some very large content that will normally not fit in the window.'
text = text + text;
let items = [
{x:0, y:0, w:2, content: `<div>A no h: ${text}</div>`},
{x:2, y:0, w:1, h:2, content: '<div>B: shrink h=2</div>'}, // make taller than needed upfront
{x:3, y:0, w:2, sizeToContent: false, content: `<div>C: WILL SCROLL. ${text}</div>`}, // prevent this from fitting testing
{x:0, y:1, w:3, content: `<div>D no h: ${text} ${text}</div>`},
{x:3, y:1, w:2, sizeToContent:3, content: `<div>E sizeToContent=3 <button onClick="more()">more</button><button onClick="less()">less</button><div id="dynContent">${text} ${text} ${text}</div></div>`} ];
grid.load(items);
function column(n) {
grid.column(n, 'none');
}
function cellHeight(n) {
grid.cellHeight(n);
}
function addWidget() {
grid.addWidget({content: `<div>New: ${text}</div>`});
}
function makeWidget() {
let doc = document.implementation.createHTMLDocument();
doc.body.innerHTML = `<div class="item"><div class="grid-stack-item-content"><div>New Make: ${text}</div></div></div>`;
let el = doc.body.children[0];
grid.el.appendChild(el);
grid.makeWidget(el);
}
function more() {
let cont = document.getElementById('dynContent');
if (!cont) return;
cont.innerHTML += cont.innerHTML;
let el = cont.parentElement.parentElement.parentElement;
grid.resizeToContent(el)
}
function less() {
let cont = document.getElementById('dynContent');
if (!cont) return;
let content = cont.innerHTML;
cont.innerHTML = content.substring(0, content.length/2);
let el = cont.parentElement.parentElement.parentElement;
grid.resizeToContent(el);
}
</script>
</body>
</html>