Skip to content

Commit e09b0c9

Browse files
committed
rtl demo
1 parent 4b13d40 commit e09b0c9

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed

demo/rtl.html

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
<!DOCTYPE html>
2+
<html lang="en" dir="rtl">
3+
<head>
4+
<!--[if lt IE 9]>
5+
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
6+
<![endif]-->
7+
8+
<meta charset="utf-8">
9+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
10+
<meta name="viewport" content="width=device-width, initial-scale=1">
11+
<title>RTL demo</title>
12+
13+
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
14+
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.2.0/css/font-awesome.min.css"/>
15+
<link rel="stylesheet" href="../dist/gridstack.css"/>
16+
17+
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
18+
<script src="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.0/jquery-ui.js"></script>
19+
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
20+
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/3.5.0/lodash.min.js"></script>
21+
<script src="//cdnjs.cloudflare.com/ajax/libs/knockout/3.2.0/knockout-min.js"></script>
22+
<script src="../dist/gridstack.js"></script>
23+
24+
<style type="text/css">
25+
.grid-stack {
26+
background: lightgoldenrodyellow;
27+
}
28+
29+
.grid-stack-item-content {
30+
color: #2c3e50;
31+
background-color: #18bc9c;
32+
}
33+
</style>
34+
</head>
35+
<body>
36+
<div class="container-fluid">
37+
<h1>RTL Demo</h1>
38+
39+
<div>
40+
<button data-bind="click: addNewWidget">Add new widget</button>
41+
</div>
42+
43+
<br>
44+
45+
<div data-bind="component: {name: 'dashboard-grid', params: $data}"></div>
46+
</div>
47+
48+
49+
<script type="text/javascript">
50+
ko.components.register('dashboard-grid', {
51+
viewModel: {
52+
createViewModel: function (controller, componentInfo) {
53+
var ViewModel = function (controller, componentInfo) {
54+
var grid = null;
55+
56+
this.widgets = controller.widgets;
57+
58+
this.afterAddWidget = function (items) {
59+
if (grid == null) {
60+
grid = $(componentInfo.element).find('.grid-stack').gridstack({
61+
auto: false
62+
}).data('gridstack');
63+
}
64+
65+
var item = _.find(items, function (i) { return i.nodeType == 1 });
66+
grid.addWidget(item);
67+
ko.utils.domNodeDisposal.addDisposeCallback(item, function () {
68+
grid.removeWidget(item);
69+
});
70+
};
71+
};
72+
73+
return new ViewModel(controller, componentInfo);
74+
}
75+
},
76+
template:
77+
[
78+
'<div class="grid-stack" data-bind="foreach: {data: widgets, afterRender: afterAddWidget}">',
79+
' <div class="grid-stack-item" data-bind="attr: {\'data-gs-x\': $data.x, \'data-gs-y\': $data.y, \'data-gs-width\': $data.width, \'data-gs-height\': $data.height, \'data-gs-auto-position\': $data.auto_position}">',
80+
' <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>',
81+
' </div>',
82+
'</div> '
83+
].join('')
84+
});
85+
86+
$(function () {
87+
var Controller = function (widgets) {
88+
var self = this;
89+
90+
this.widgets = ko.observableArray(widgets);
91+
92+
this.addNewWidget = function () {
93+
this.widgets.push({
94+
x: 0,
95+
y: 0,
96+
width: Math.floor(1 + 3 * Math.random()),
97+
height: Math.floor(1 + 3 * Math.random()),
98+
auto_position: true
99+
});
100+
return false;
101+
};
102+
103+
this.deleteWidget = function (item) {
104+
self.widgets.remove(item);
105+
return false;
106+
};
107+
};
108+
109+
var widgets = [
110+
{x: 0, y: 0, width: 2, height: 2, index: 1},
111+
{x: 2, y: 0, width: 4, height: 2, index: 2},
112+
{x: 6, y: 0, width: 2, height: 4, index: 3},
113+
{x: 1, y: 2, width: 4, height: 2, index: 4}
114+
];
115+
116+
var controller = new Controller(widgets);
117+
ko.applyBindings(controller);
118+
});
119+
</script>
120+
</body>
121+
</html>

0 commit comments

Comments
 (0)