|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + <meta charset="utf-8"> |
| 5 | + <meta http-equiv="X-UA-Compatible" content="IE=edge"> |
| 6 | + <meta name="viewport" content="width=device-width, initial-scale=1"> |
| 7 | + <title>#2639 load() fix</title> |
| 8 | + <link rel="stylesheet" href="../../../demo/demo.css" /> |
| 9 | + <script src="../../../dist/gridstack-all.js"></script> |
| 10 | +</head> |
| 11 | +<body> |
| 12 | + <div class="container-fluid"> |
| 13 | + <h1>#2639 load() fix with mix of missing coordinates.</h1> |
| 14 | + <div> |
| 15 | + <button onClick="addNewWidget()">Add widget using .addWidget()</button> |
| 16 | + <button onClick="loadNewWidget()">Add widget using .load()</button> |
| 17 | + </div> |
| 18 | + <br><br> |
| 19 | + <div class="grid-stack"></div> |
| 20 | + <textarea readonly rows="20" id="text" style="width: 100%;"></textarea> |
| 21 | + </div> |
| 22 | + <script src="events.js"></script> |
| 23 | + <script type="text/javascript"> |
| 24 | + saveGrid = function() { |
| 25 | + items = grid.save(); |
| 26 | + document.querySelector('#text').innerHTML = JSON.stringify(items, ' ', 2) |
| 27 | + } |
| 28 | + |
| 29 | + var count = 0; |
| 30 | + var items = [ |
| 31 | + {x: 0, y: 0, w: 2, h: 2}, |
| 32 | + {x: 2, y: 0, w: 8, h: 2}, |
| 33 | + {x: 0, y: 2, w: 6, h: 2}, |
| 34 | + {x: 6, y: 2, w: 3, h: 2}, |
| 35 | + {x: 9, y: 2, w: 3, h: 2}, |
| 36 | + {x: 0, y: 4, w: 5, h: 3}, |
| 37 | + ].map(w => ({ |
| 38 | + ...w, |
| 39 | + id: String(count), |
| 40 | + content: String(count++) |
| 41 | + })); |
| 42 | + |
| 43 | + var options = { // put in gridstack options here |
| 44 | + float: false, |
| 45 | + cellHeight: 70, |
| 46 | + }; |
| 47 | + var grid = GridStack.init(options).load(items); |
| 48 | + grid.on('change added', saveGrid); |
| 49 | + saveGrid(); |
| 50 | + |
| 51 | + createNode = function (str) { |
| 52 | + return { |
| 53 | + id: String(count), |
| 54 | + w: 3, |
| 55 | + h: 3, |
| 56 | + content: `${count++} ${str}`, |
| 57 | + }; |
| 58 | + } |
| 59 | + |
| 60 | + // Gets placed in the next hortizontal open slot |
| 61 | + addNewWidget = function () { |
| 62 | + grid.addWidget(createNode('added')); |
| 63 | + return false; |
| 64 | + }; |
| 65 | + |
| 66 | + // Gets placed at the bottom of a grid |
| 67 | + loadNewWidget = function () { |
| 68 | + items.push(createNode('loaded')); |
| 69 | + grid.load(items); |
| 70 | + return false; |
| 71 | + } |
| 72 | + </script> |
| 73 | +</body> |
| 74 | +</html> |
0 commit comments