-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
locked.html
61 lines (55 loc) · 1.73 KB
/
locked.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
<!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>Locked demo</title>
<link rel="stylesheet" href="demo.css"/>
<script src="../dist/gridstack-all.js"></script>
</style>
</head>
<body>
<div class="container-fluid">
<h1>Locked demo</h1>
<div>
<a class="btn btn-primary" onClick="addNewWidget()" href="#">Add Widget</a>
<a class="btn btn-primary" onclick="toggleFloat()" id="float" href="#">float: true</a>
</div>
<br><br>
<div class="grid-stack"></div>
</div>
<script type="text/javascript">
let grid = GridStack.init({float: true});
grid.on('added removed change', function(e, items) {
let str = '';
items.forEach(function(item) { str += ' (x,y)=' + item.x + ',' + item.y; });
console.log(e.type + ' ' + items.length + ' items:' + str );
});
let items = [
{x: 0, y: 1, w: 12, locked: 'yes', noMove: true, noResize: true, text: 'locked, noResize, noMove'},
{x: 1, y: 0, w: 2, h: 3},
{x: 4, y: 2},
{x: 3, y: 1, h: 2},
{x: 0, y: 6, w: 2, h: 2}
];
let count = 0;
addNewWidget = function() {
let n = items[count] || {
x: Math.round(12 * Math.random()),
y: Math.round(5 * Math.random()),
w: Math.round(1 + 3 * Math.random()),
h: Math.round(1 + 3 * Math.random())
};
n.content = n.text ? n.text : String(count);
grid.addWidget(n);
count++
};
toggleFloat = function() {
grid.float(! grid.float());
document.querySelector('#float').innerHTML = 'float: ' + grid.float();
};
addNewWidget();
</script>
</body>
</html>