|
5 | 5 | <meta http-equiv="X-UA-Compatible" content="IE=edge"> |
6 | 6 | <meta name="viewport" content="width=device-width, initial-scale=1"> |
7 | 7 | <title>Right-To-Left (RTL) demo</title> |
8 | | - |
9 | | - <link rel="stylesheet" href="demo.css"/> |
10 | 8 | <style type="text/css"> |
| 9 | + /* don't include demo.css as that has some forced text aligment */ |
| 10 | + @import "../dist/gridstack.css"; |
| 11 | + .grid-stack { |
| 12 | + background: #FAFAD2; |
| 13 | + } |
11 | 14 | .grid-stack-item-content { |
12 | | - text-align: right; /* override demo.css */ |
| 15 | + background-color: #18bc9c; |
13 | 16 | } |
14 | 17 | </style> |
15 | | - |
16 | | - <script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.5.0/knockout-min.js"></script> |
17 | 18 | <script src="../dist/gridstack-all.js"></script> |
18 | 19 | </head> |
19 | 20 | <body> |
20 | | - <div class="container-fluid"> |
21 | | - <h1>RTL Demo</h1> |
22 | | - <div> |
23 | | - <a class="btn btn-primary" data-bind="click: addNewWidget">Add Widget</a> |
24 | | - </div> |
25 | | - <br> |
26 | | - <div data-bind="component: {name: 'dashboard-grid', params: $data}"></div> |
| 21 | + <h1>RTL Demo</h1> |
| 22 | + <div> |
| 23 | + <button onClick="addWidget()">Add Widget</button> |
27 | 24 | </div> |
| 25 | + <br> |
| 26 | + <div class="grid-stack"></div> |
28 | 27 |
|
29 | 28 | <script type="text/javascript"> |
30 | | - ko.components.register('dashboard-grid', { |
31 | | - viewModel: { |
32 | | - createViewModel: function (controller, componentInfo) { |
33 | | - let ViewModel = function (controller, componentInfo) { |
34 | | - let grid = null; |
35 | | - |
36 | | - this.widgets = controller.widgets; |
37 | | - |
38 | | - this.afterAddWidget = function (items) { |
39 | | - if (!grid) { |
40 | | - grid = GridStack.init({auto: false}); |
41 | | - } |
42 | | - |
43 | | - let item = items.find(function (i) { return i.nodeType == 1 }); |
44 | | - grid.addWidget(item); |
45 | | - ko.utils.domNodeDisposal.addDisposeCallback(item, function () { |
46 | | - grid.removeWidget(item); |
47 | | - }); |
48 | | - }; |
49 | | - }; |
50 | | - |
51 | | - return new ViewModel(controller, componentInfo); |
52 | | - } |
53 | | - }, |
54 | | - template: |
55 | | - [ |
56 | | - '<div class="grid-stack" data-bind="foreach: {data: widgets, afterRender: afterAddWidget}">', |
57 | | - ' <div class="grid-stack-item" data-bind="attr: {\'gs-x\': $data.x, \'gs-y\': $data.y, \'gs-w\': $data.w, \'gs-h\': $data.h, \'gs-auto-position\': $data.auto_position}">', |
58 | | - ' <div class="grid-stack-item-content"><center><button data-bind="click: $root.deleteWidget">Delete me</button><br><h5 data-bind="text: index" /></center><br><p>lorem ipsum</p></div>', |
59 | | - ' </div>', |
60 | | - '</div> ' |
61 | | - ].join('') |
62 | | - }); |
63 | | - |
64 | | - let Controller = function (widgets) { |
65 | | - let self = this; |
66 | | - |
67 | | - this.widgets = ko.observableArray(widgets); |
68 | | - |
69 | | - this.addNewWidget = function () { |
70 | | - this.widgets.push({ |
71 | | - x: 0, |
72 | | - y: 0, |
73 | | - w: Math.floor(1 + 3 * Math.random()), |
74 | | - h: Math.floor(1 + 3 * Math.random()), |
75 | | - auto_position: true, |
76 | | - index: 'auto' |
77 | | - }); |
78 | | - return false; |
79 | | - }; |
80 | | - |
81 | | - this.deleteWidget = function (item) { |
82 | | - self.widgets.remove(item); |
83 | | - return false; |
| 29 | + let items = [ |
| 30 | + {x: 0, y: 0, w: 2, h: 1}, |
| 31 | + {x: 2, y: 0, w: 4, h: 1}, |
| 32 | + {x: 6, y: 0, w: 2, h: 2}, |
| 33 | + ]; |
| 34 | + items.forEach((item, i) => item.content = 'item ' + i); |
| 35 | + let grid = GridStack.init({rtl: true, children: items}); |
| 36 | + |
| 37 | + function addWidget() { |
| 38 | + let w = { |
| 39 | + w: Math.round(1 + 3 * Math.random()), |
| 40 | + h: Math.round(1 + 3 * Math.random()), |
| 41 | + content: 'new item', |
84 | 42 | }; |
| 43 | + grid.addWidget(w); |
85 | 44 | }; |
86 | 45 |
|
87 | | - let widgets = [ |
88 | | - {x: 0, y: 0, w: 2, h: 2, index: 1}, |
89 | | - {x: 2, y: 0, w: 4, h: 2, index: 2}, |
90 | | - {x: 6, y: 0, w: 2, h: 4, index: 3}, |
91 | | - {x: 1, y: 2, w: 4, h: 2, index: 4} |
92 | | - ]; |
93 | | - |
94 | | - let controller = new Controller(widgets); |
95 | | - ko.applyBindings(controller); |
96 | 46 | </script> |
97 | 47 | </body> |
98 | 48 | </html> |
0 commit comments