Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2876854

Browse files
committed
update demo
1 parent 6b08e76 commit 2876854

17 files changed

+2135
-1155
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

demo/float.html

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212

1313
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
1414
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.2.0/css/font-awesome.min.css"/>
15-
<link rel="stylesheet" href="../gridstack.css"/>
15+
<link rel="stylesheet" href="../dist/gridstack.css"/>
1616

1717
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
1818
<script src="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.0/jquery-ui.js"></script>
1919
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
2020
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/3.5.0/lodash.min.js"></script>
21-
<script src="../gridstack.js"></script>
21+
<script src="../dist/gridstack.js"></script>
2222

2323
<style type="text/css">
2424
.grid-stack {
@@ -68,18 +68,19 @@ <h1>Float grid demo</h1>
6868

6969
this.grid = $('.grid-stack').data('gridstack');
7070

71-
this.add_new_widget = function () {
71+
this.addNewWidget = function () {
7272
var node = this.items.pop() || {
7373
x: 12 * Math.random(),
7474
y: 5 * Math.random(),
7575
width: 1 + 3 * Math.random(),
7676
height: 1 + 3 * Math.random()
7777
};
78-
this.grid.add_widget($('<div><div class="grid-stack-item-content" /><div/>'),
78+
this.grid.addWidget($('<div><div class="grid-stack-item-content" /><div/>'),
7979
node.x, node.y, node.width, node.height);
80+
return false;
8081
}.bind(this);
8182

82-
$('#add-new-widget').click(this.add_new_widget);
83+
$('#add-new-widget').click(this.addNewWidget);
8384
};
8485
});
8586
</script>

demo/knockout.html

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212

1313
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
1414
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.2.0/css/font-awesome.min.css"/>
15-
<link rel="stylesheet" href="../gridstack.css"/>
15+
<link rel="stylesheet" href="../dist/gridstack.css"/>
1616

1717
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
1818
<script src="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.0/jquery-ui.js"></script>
1919
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
2020
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/3.5.0/lodash.min.js"></script>
2121
<script src="//cdnjs.cloudflare.com/ajax/libs/knockout/3.2.0/knockout-min.js"></script>
22-
<script src="../gridstack.js"></script>
22+
<script src="../dist/gridstack.js"></script>
2323

2424
<style type="text/css">
2525
.grid-stack {
@@ -38,8 +38,7 @@
3838
<h1>knockout.js Demo</h1>
3939

4040
<div>
41-
<button data-bind="click: add_new_widget">Add new widget</button>
42-
<button data-bind="click: change_cell_height">Change Cell Height</button>
41+
<button data-bind="click: addNewWidget">Add new widget</button>
4342
</div>
4443

4544
<br>
@@ -65,9 +64,9 @@ <h1>knockout.js Demo</h1>
6564
}
6665

6766
var item = _.find(items, function (i) { return i.nodeType == 1 });
68-
grid.add_widget(item);
67+
grid.addWidget(item);
6968
ko.utils.domNodeDisposal.addDisposeCallback(item, function () {
70-
grid.remove_widget(item);
69+
grid.removeWidget(item);
7170
});
7271
};
7372
};
@@ -79,7 +78,7 @@ <h1>knockout.js Demo</h1>
7978
[
8079
'<div class="grid-stack" data-bind="foreach: {data: widgets, afterRender: afterAddWidget}">',
8180
' <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}">',
82-
' <div class="grid-stack-item-content"><button data-bind="click: $root.delete_widget">Delete me</button></div>',
81+
' <div class="grid-stack-item-content"><button data-bind="click: $root.deleteWidget">Delete me</button></div>',
8382
' </div>',
8483
'</div> '
8584
].join('')
@@ -91,24 +90,21 @@ <h1>knockout.js Demo</h1>
9190

9291
this.widgets = ko.observableArray(widgets);
9392

94-
this.add_new_widget = function () {
93+
this.addNewWidget = function () {
9594
this.widgets.push({
9695
x: 0,
9796
y: 0,
9897
width: Math.floor(1 + 3 * Math.random()),
9998
height: Math.floor(1 + 3 * Math.random()),
10099
auto_position: true
101100
});
101+
return false;
102102
};
103103

104-
this.delete_widget = function (item) {
104+
this.deleteWidget = function (item) {
105105
self.widgets.remove(item);
106+
return false;
106107
};
107-
108-
this.change_cell_height = function (item) {
109-
var grid = $('.grid-stack').data('gridstack');
110-
grid.cell_height(50 + 100 * Math.random());
111-
}.bind(this);
112108
};
113109

114110
var widgets = [

demo/knockout2.html

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212

1313
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
1414
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.2.0/css/font-awesome.min.css"/>
15-
<link rel="stylesheet" href="../gridstack.css"/>
15+
<link rel="stylesheet" href="../dist/gridstack.css"/>
1616

1717
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
1818
<script src="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.0/jquery-ui.js"></script>
1919
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
2020
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/3.5.0/lodash.min.js"></script>
2121
<script src="//cdnjs.cloudflare.com/ajax/libs/knockout/3.2.0/knockout-min.js"></script>
22-
<script src="../gridstack.js"></script>
22+
<script src="../dist/gridstack.js"></script>
2323

2424
<style type="text/css">
2525
.grid-stack {
@@ -38,7 +38,7 @@
3838
<h1>knockout.js Demo</h1>
3939

4040
<div>
41-
<button data-bind="click: add_new_widget">Add new widget</button>
41+
<button data-bind="click: addNewWidget">Add new widget</button>
4242
</div>
4343

4444
<br>
@@ -64,9 +64,9 @@ <h1>knockout.js Demo</h1>
6464
}
6565

6666
var item = _.find(items, function (i) { return i.nodeType == 1 });
67-
grid.add_widget(item);
67+
grid.addWidget(item);
6868
ko.utils.domNodeDisposal.addDisposeCallback(item, function () {
69-
grid.remove_widget(item);
69+
grid.removeWidget(item);
7070
});
7171
};
7272
};
@@ -83,18 +83,20 @@ <h1>knockout.js Demo</h1>
8383

8484
this.widgets = ko.observableArray(widgets);
8585

86-
this.add_new_widget = function () {
86+
this.addNewWidget = function () {
8787
this.widgets.push({
8888
x: 0,
8989
y: 0,
9090
width: Math.floor(1 + 3 * Math.random()),
9191
height: Math.floor(1 + 3 * Math.random()),
9292
auto_position: true
9393
});
94+
return false;
9495
};
9596

96-
this.delete_widget = function (item) {
97+
this.deleteWidget = function (item) {
9798
self.widgets.remove(item);
99+
return false;
98100
};
99101
};
100102

@@ -113,7 +115,7 @@ <h1>knockout.js Demo</h1>
113115
<template id="gridstack-template">
114116
<div class="grid-stack" data-bind="foreach: {data: widgets, afterRender: afterAddWidget}">
115117
<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}">
116-
<div class="grid-stack-item-content"><button data-bind="click: $root.delete_widget">Delete me</button></div>
118+
<div class="grid-stack-item-content"><button data-bind="click: $root.deleteWidget">Delete me</button></div>
117119
</div></div><!-- <---- NO SPACE BETWEEN THESE CLOSING TAGS -->
118120
</template>
119121
</body>

demo/nested.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212

1313
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
1414
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.2.0/css/font-awesome.min.css"/>
15-
<link rel="stylesheet" href="../gridstack.css"/>
15+
<link rel="stylesheet" href="../dist/gridstack.css"/>
1616

1717
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
1818
<script src="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.0/jquery-ui.js"></script>
1919
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
2020
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/3.5.0/lodash.min.js"></script>
21-
<script src="../gridstack.js"></script>
21+
<script src="../dist/gridstack.js"></script>
2222

2323
<style type="text/css">
2424
.grid-stack {

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)