update demo
This commit is contained in:
parent
6b08e76f2c
commit
2876854a7e
17 changed files with 2135 additions and 1155 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
node_modules
|
||||
|
|
@ -12,13 +12,13 @@
|
|||
|
||||
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.2.0/css/font-awesome.min.css"/>
|
||||
<link rel="stylesheet" href="../gridstack.css"/>
|
||||
<link rel="stylesheet" href="../dist/gridstack.css"/>
|
||||
|
||||
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.0/jquery-ui.js"></script>
|
||||
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/3.5.0/lodash.min.js"></script>
|
||||
<script src="../gridstack.js"></script>
|
||||
<script src="../dist/gridstack.js"></script>
|
||||
|
||||
<style type="text/css">
|
||||
.grid-stack {
|
||||
|
|
@ -68,18 +68,19 @@
|
|||
|
||||
this.grid = $('.grid-stack').data('gridstack');
|
||||
|
||||
this.add_new_widget = function () {
|
||||
this.addNewWidget = function () {
|
||||
var node = this.items.pop() || {
|
||||
x: 12 * Math.random(),
|
||||
y: 5 * Math.random(),
|
||||
width: 1 + 3 * Math.random(),
|
||||
height: 1 + 3 * Math.random()
|
||||
};
|
||||
this.grid.add_widget($('<div><div class="grid-stack-item-content" /><div/>'),
|
||||
this.grid.addWidget($('<div><div class="grid-stack-item-content" /><div/>'),
|
||||
node.x, node.y, node.width, node.height);
|
||||
return false;
|
||||
}.bind(this);
|
||||
|
||||
$('#add-new-widget').click(this.add_new_widget);
|
||||
$('#add-new-widget').click(this.addNewWidget);
|
||||
};
|
||||
});
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -12,14 +12,14 @@
|
|||
|
||||
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.2.0/css/font-awesome.min.css"/>
|
||||
<link rel="stylesheet" href="../gridstack.css"/>
|
||||
<link rel="stylesheet" href="../dist/gridstack.css"/>
|
||||
|
||||
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.0/jquery-ui.js"></script>
|
||||
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/3.5.0/lodash.min.js"></script>
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/knockout/3.2.0/knockout-min.js"></script>
|
||||
<script src="../gridstack.js"></script>
|
||||
<script src="../dist/gridstack.js"></script>
|
||||
|
||||
<style type="text/css">
|
||||
.grid-stack {
|
||||
|
|
@ -38,8 +38,7 @@
|
|||
<h1>knockout.js Demo</h1>
|
||||
|
||||
<div>
|
||||
<button data-bind="click: add_new_widget">Add new widget</button>
|
||||
<button data-bind="click: change_cell_height">Change Cell Height</button>
|
||||
<button data-bind="click: addNewWidget">Add new widget</button>
|
||||
</div>
|
||||
|
||||
<br>
|
||||
|
|
@ -65,9 +64,9 @@
|
|||
}
|
||||
|
||||
var item = _.find(items, function (i) { return i.nodeType == 1 });
|
||||
grid.add_widget(item);
|
||||
grid.addWidget(item);
|
||||
ko.utils.domNodeDisposal.addDisposeCallback(item, function () {
|
||||
grid.remove_widget(item);
|
||||
grid.removeWidget(item);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
|
@ -79,7 +78,7 @@
|
|||
[
|
||||
'<div class="grid-stack" data-bind="foreach: {data: widgets, afterRender: afterAddWidget}">',
|
||||
' <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}">',
|
||||
' <div class="grid-stack-item-content"><button data-bind="click: $root.delete_widget">Delete me</button></div>',
|
||||
' <div class="grid-stack-item-content"><button data-bind="click: $root.deleteWidget">Delete me</button></div>',
|
||||
' </div>',
|
||||
'</div> '
|
||||
].join('')
|
||||
|
|
@ -91,7 +90,7 @@
|
|||
|
||||
this.widgets = ko.observableArray(widgets);
|
||||
|
||||
this.add_new_widget = function () {
|
||||
this.addNewWidget = function () {
|
||||
this.widgets.push({
|
||||
x: 0,
|
||||
y: 0,
|
||||
|
|
@ -99,16 +98,13 @@
|
|||
height: Math.floor(1 + 3 * Math.random()),
|
||||
auto_position: true
|
||||
});
|
||||
return false;
|
||||
};
|
||||
|
||||
this.delete_widget = function (item) {
|
||||
this.deleteWidget = function (item) {
|
||||
self.widgets.remove(item);
|
||||
return false;
|
||||
};
|
||||
|
||||
this.change_cell_height = function (item) {
|
||||
var grid = $('.grid-stack').data('gridstack');
|
||||
grid.cell_height(50 + 100 * Math.random());
|
||||
}.bind(this);
|
||||
};
|
||||
|
||||
var widgets = [
|
||||
|
|
|
|||
|
|
@ -12,14 +12,14 @@
|
|||
|
||||
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.2.0/css/font-awesome.min.css"/>
|
||||
<link rel="stylesheet" href="../gridstack.css"/>
|
||||
<link rel="stylesheet" href="../dist/gridstack.css"/>
|
||||
|
||||
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.0/jquery-ui.js"></script>
|
||||
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/3.5.0/lodash.min.js"></script>
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/knockout/3.2.0/knockout-min.js"></script>
|
||||
<script src="../gridstack.js"></script>
|
||||
<script src="../dist/gridstack.js"></script>
|
||||
|
||||
<style type="text/css">
|
||||
.grid-stack {
|
||||
|
|
@ -38,7 +38,7 @@
|
|||
<h1>knockout.js Demo</h1>
|
||||
|
||||
<div>
|
||||
<button data-bind="click: add_new_widget">Add new widget</button>
|
||||
<button data-bind="click: addNewWidget">Add new widget</button>
|
||||
</div>
|
||||
|
||||
<br>
|
||||
|
|
@ -64,9 +64,9 @@
|
|||
}
|
||||
|
||||
var item = _.find(items, function (i) { return i.nodeType == 1 });
|
||||
grid.add_widget(item);
|
||||
grid.addWidget(item);
|
||||
ko.utils.domNodeDisposal.addDisposeCallback(item, function () {
|
||||
grid.remove_widget(item);
|
||||
grid.removeWidget(item);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
|
@ -83,7 +83,7 @@
|
|||
|
||||
this.widgets = ko.observableArray(widgets);
|
||||
|
||||
this.add_new_widget = function () {
|
||||
this.addNewWidget = function () {
|
||||
this.widgets.push({
|
||||
x: 0,
|
||||
y: 0,
|
||||
|
|
@ -91,10 +91,12 @@
|
|||
height: Math.floor(1 + 3 * Math.random()),
|
||||
auto_position: true
|
||||
});
|
||||
return false;
|
||||
};
|
||||
|
||||
this.delete_widget = function (item) {
|
||||
this.deleteWidget = function (item) {
|
||||
self.widgets.remove(item);
|
||||
return false;
|
||||
};
|
||||
};
|
||||
|
||||
|
|
@ -113,7 +115,7 @@
|
|||
<template id="gridstack-template">
|
||||
<div class="grid-stack" data-bind="foreach: {data: widgets, afterRender: afterAddWidget}">
|
||||
<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}">
|
||||
<div class="grid-stack-item-content"><button data-bind="click: $root.delete_widget">Delete me</button></div>
|
||||
<div class="grid-stack-item-content"><button data-bind="click: $root.deleteWidget">Delete me</button></div>
|
||||
</div></div><!-- <---- NO SPACE BETWEEN THESE CLOSING TAGS -->
|
||||
</template>
|
||||
</body>
|
||||
|
|
|
|||
|
|
@ -12,13 +12,13 @@
|
|||
|
||||
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.2.0/css/font-awesome.min.css"/>
|
||||
<link rel="stylesheet" href="../gridstack.css"/>
|
||||
<link rel="stylesheet" href="../dist/gridstack.css"/>
|
||||
|
||||
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.0/jquery-ui.js"></script>
|
||||
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/3.5.0/lodash.min.js"></script>
|
||||
<script src="../gridstack.js"></script>
|
||||
<script src="../dist/gridstack.js"></script>
|
||||
|
||||
<style type="text/css">
|
||||
.grid-stack {
|
||||
|
|
|
|||
121
demo/rtl.html
Normal file
121
demo/rtl.html
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en" dir="rtl">
|
||||
<head>
|
||||
<!--[if lt IE 9]>
|
||||
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
|
||||
<![endif]-->
|
||||
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>RTL demo</title>
|
||||
|
||||
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.2.0/css/font-awesome.min.css"/>
|
||||
<link rel="stylesheet" href="../dist/gridstack.css"/>
|
||||
|
||||
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.0/jquery-ui.js"></script>
|
||||
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/3.5.0/lodash.min.js"></script>
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/knockout/3.2.0/knockout-min.js"></script>
|
||||
<script src="../dist/gridstack.js"></script>
|
||||
|
||||
<style type="text/css">
|
||||
.grid-stack {
|
||||
background: lightgoldenrodyellow;
|
||||
}
|
||||
|
||||
.grid-stack-item-content {
|
||||
color: #2c3e50;
|
||||
background-color: #18bc9c;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container-fluid">
|
||||
<h1>RTL Demo</h1>
|
||||
|
||||
<div>
|
||||
<button data-bind="click: addNewWidget">Add new widget</button>
|
||||
</div>
|
||||
|
||||
<br>
|
||||
|
||||
<div data-bind="component: {name: 'dashboard-grid', params: $data}"></div>
|
||||
</div>
|
||||
|
||||
|
||||
<script type="text/javascript">
|
||||
ko.components.register('dashboard-grid', {
|
||||
viewModel: {
|
||||
createViewModel: function (controller, componentInfo) {
|
||||
var ViewModel = function (controller, componentInfo) {
|
||||
var grid = null;
|
||||
|
||||
this.widgets = controller.widgets;
|
||||
|
||||
this.afterAddWidget = function (items) {
|
||||
if (grid == null) {
|
||||
grid = $(componentInfo.element).find('.grid-stack').gridstack({
|
||||
auto: false
|
||||
}).data('gridstack');
|
||||
}
|
||||
|
||||
var item = _.find(items, function (i) { return i.nodeType == 1 });
|
||||
grid.addWidget(item);
|
||||
ko.utils.domNodeDisposal.addDisposeCallback(item, function () {
|
||||
grid.removeWidget(item);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
return new ViewModel(controller, componentInfo);
|
||||
}
|
||||
},
|
||||
template:
|
||||
[
|
||||
'<div class="grid-stack" data-bind="foreach: {data: widgets, afterRender: afterAddWidget}">',
|
||||
' <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}">',
|
||||
' <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>',
|
||||
' </div>',
|
||||
'</div> '
|
||||
].join('')
|
||||
});
|
||||
|
||||
$(function () {
|
||||
var Controller = function (widgets) {
|
||||
var self = this;
|
||||
|
||||
this.widgets = ko.observableArray(widgets);
|
||||
|
||||
this.addNewWidget = function () {
|
||||
this.widgets.push({
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: Math.floor(1 + 3 * Math.random()),
|
||||
height: Math.floor(1 + 3 * Math.random()),
|
||||
auto_position: true
|
||||
});
|
||||
return false;
|
||||
};
|
||||
|
||||
this.deleteWidget = function (item) {
|
||||
self.widgets.remove(item);
|
||||
return false;
|
||||
};
|
||||
};
|
||||
|
||||
var widgets = [
|
||||
{x: 0, y: 0, width: 2, height: 2, index: 1},
|
||||
{x: 2, y: 0, width: 4, height: 2, index: 2},
|
||||
{x: 6, y: 0, width: 2, height: 4, index: 3},
|
||||
{x: 1, y: 2, width: 4, height: 2, index: 4}
|
||||
];
|
||||
|
||||
var controller = new Controller(widgets);
|
||||
ko.applyBindings(controller);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -12,13 +12,13 @@
|
|||
|
||||
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.2.0/css/font-awesome.min.css"/>
|
||||
<link rel="stylesheet" href="../gridstack.css"/>
|
||||
<link rel="stylesheet" href="../dist/gridstack.css"/>
|
||||
|
||||
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.0/jquery-ui.js"></script>
|
||||
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/3.5.0/lodash.min.js"></script>
|
||||
<script src="../gridstack.js"></script>
|
||||
<script src="../dist/gridstack.js"></script>
|
||||
|
||||
<style type="text/css">
|
||||
.grid-stack {
|
||||
|
|
@ -60,7 +60,7 @@
|
|||
$('.grid-stack').gridstack(options);
|
||||
|
||||
new function () {
|
||||
this.serialized_data = [
|
||||
this.serializedData = [
|
||||
{x: 0, y: 0, width: 2, height: 2},
|
||||
{x: 3, y: 1, width: 1, height: 2},
|
||||
{x: 4, y: 1, width: 1, height: 1},
|
||||
|
|
@ -73,17 +73,18 @@
|
|||
|
||||
this.grid = $('.grid-stack').data('gridstack');
|
||||
|
||||
this.load_grid = function () {
|
||||
this.grid.remove_all();
|
||||
var items = GridStackUI.Utils.sort(this.serialized_data);
|
||||
this.loadGrid = function () {
|
||||
this.grid.removeAll();
|
||||
var items = GridStackUI.Utils.sort(this.serializedData);
|
||||
_.each(items, function (node) {
|
||||
this.grid.add_widget($('<div><div class="grid-stack-item-content" /><div/>'),
|
||||
this.grid.addWidget($('<div><div class="grid-stack-item-content" /><div/>'),
|
||||
node.x, node.y, node.width, node.height);
|
||||
}, this);
|
||||
return false;
|
||||
}.bind(this);
|
||||
|
||||
this.save_grid = function () {
|
||||
this.serialized_data = _.map($('.grid-stack > .grid-stack-item:visible'), function (el) {
|
||||
this.saveGrid = function () {
|
||||
this.serializedData = _.map($('.grid-stack > .grid-stack-item:visible'), function (el) {
|
||||
el = $(el);
|
||||
var node = el.data('_gridstack_node');
|
||||
return {
|
||||
|
|
@ -93,18 +94,20 @@
|
|||
height: node.height
|
||||
};
|
||||
}, this);
|
||||
$('#saved-data').val(JSON.stringify(this.serialized_data, null, ' '));
|
||||
$('#saved-data').val(JSON.stringify(this.serializedData, null, ' '));
|
||||
return false;
|
||||
}.bind(this);
|
||||
|
||||
this.clear_grid = function () {
|
||||
this.grid.remove_all();
|
||||
this.clearGrid = function () {
|
||||
this.grid.removeAll();
|
||||
return false;
|
||||
}.bind(this);
|
||||
|
||||
$('#save-grid').click(this.save_grid);
|
||||
$('#load-grid').click(this.load_grid);
|
||||
$('#clear-grid').click(this.clear_grid);
|
||||
$('#save-grid').click(this.saveGrid);
|
||||
$('#load-grid').click(this.loadGrid);
|
||||
$('#clear-grid').click(this.clearGrid);
|
||||
|
||||
this.load_grid();
|
||||
this.loadGrid();
|
||||
};
|
||||
});
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -12,14 +12,14 @@
|
|||
|
||||
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.2.0/css/font-awesome.min.css"/>
|
||||
<link rel="stylesheet" href="../gridstack.css"/>
|
||||
<link rel="stylesheet" href="../gridstack-extra.css"/>
|
||||
<link rel="stylesheet" href="../dist/gridstack.css"/>
|
||||
<link rel="stylesheet" href="../dist/gridstack-extra.css"/>
|
||||
|
||||
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.0/jquery-ui.js"></script>
|
||||
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/3.5.0/lodash.min.js"></script>
|
||||
<script src="../gridstack.js"></script>
|
||||
<script src="../dist/gridstack.js"></script>
|
||||
|
||||
<style type="text/css">
|
||||
#grid1 {
|
||||
|
|
@ -75,7 +75,7 @@
|
|||
var grid = $(this).data('gridstack');
|
||||
|
||||
_.each(items, function (node) {
|
||||
grid.add_widget($('<div><div class="grid-stack-item-content" /><div/>'),
|
||||
grid.addWidget($('<div><div class="grid-stack-item-content" /><div/>'),
|
||||
node.x, node.y, node.width, node.height);
|
||||
}, this);
|
||||
});
|
||||
|
|
|
|||
636
gridstack-extra.css → dist/gridstack-extra.css
vendored
636
gridstack-extra.css → dist/gridstack-extra.css
vendored
File diff suppressed because it is too large
Load diff
1
dist/gridstack-extra.min.css
vendored
Normal file
1
dist/gridstack-extra.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
193
gridstack.css → dist/gridstack.css
vendored
193
gridstack.css → dist/gridstack.css
vendored
|
|
@ -5,6 +5,15 @@
|
|||
.grid-stack {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.grid-stack.grid-stack-rtl {
|
||||
direction: ltr;
|
||||
}
|
||||
|
||||
.grid-stack.grid-stack-rtl > .grid-stack-item {
|
||||
direction: rtl;
|
||||
}
|
||||
|
||||
.grid-stack .grid-stack-placeholder > .placeholder-content {
|
||||
border: 1px dashed lightgray;
|
||||
margin: 0;
|
||||
|
|
@ -15,12 +24,15 @@
|
|||
bottom: 0;
|
||||
width: auto;
|
||||
z-index: 0 !important;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item {
|
||||
min-width: 8.33333333%;
|
||||
min-width: 8.3333333333%;
|
||||
position: absolute;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item > .grid-stack-item-content {
|
||||
margin: 0;
|
||||
position: absolute;
|
||||
|
|
@ -33,6 +45,7 @@
|
|||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item > .ui-resizable-handle {
|
||||
position: absolute;
|
||||
font-size: 0.1px;
|
||||
|
|
@ -40,43 +53,44 @@
|
|||
-ms-touch-action: none;
|
||||
touch-action: none;
|
||||
}
|
||||
.grid-stack > .grid-stack-item.ui-resizable-disabled > .ui-resizable-handle, .grid-stack > .grid-stack-item.ui-resizable-autohide > .ui-resizable-handle {
|
||||
|
||||
.grid-stack > .grid-stack-item.ui-resizable-disabled > .ui-resizable-handle,
|
||||
.grid-stack > .grid-stack-item.ui-resizable-autohide > .ui-resizable-handle {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item.ui-draggable-dragging, .grid-stack > .grid-stack-item.ui-resizable-resizing {
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item.ui-draggable-dragging > .grid-stack-item-content,
|
||||
.grid-stack > .grid-stack-item.ui-draggable-dragging > .grid-stack-item-content, .grid-stack > .grid-stack-item.ui-resizable-resizing > .grid-stack-item-content,
|
||||
.grid-stack > .grid-stack-item.ui-resizable-resizing > .grid-stack-item-content {
|
||||
box-shadow: 1px 4px 6px rgba(0, 0, 0, 0.2);
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item > .ui-resizable-se,
|
||||
.grid-stack > .grid-stack-item > .ui-resizable-sw {
|
||||
text-align: right;
|
||||
color: gray;
|
||||
padding: 2px 3px 0 0;
|
||||
margin: 0;
|
||||
font: normal normal normal 10px/1 FontAwesome;
|
||||
font-size: inherit;
|
||||
text-rendering: auto;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
.grid-stack > .grid-stack-item > .ui-resizable-se::before,
|
||||
.grid-stack > .grid-stack-item > .ui-resizable-sw::before {
|
||||
content: "\f065";
|
||||
background-image: url(data:image/svg+xml;utf8;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pgo8IS0tIEdlbmVyYXRvcjogQWRvYmUgSWxsdXN0cmF0b3IgMTYuMC4wLCBTVkcgRXhwb3J0IFBsdWctSW4gLiBTVkcgVmVyc2lvbjogNi4wMCBCdWlsZCAwKSAgLS0+CjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+CjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgdmVyc2lvbj0iMS4xIiBpZD0iQ2FwYV8xIiB4PSIwcHgiIHk9IjBweCIgd2lkdGg9IjE2cHgiIGhlaWdodD0iMTZweCIgdmlld0JveD0iMCAwIDUxMS42MjYgNTExLjYyNyIgc3R5bGU9ImVuYWJsZS1iYWNrZ3JvdW5kOm5ldyAwIDAgNTExLjYyNiA1MTEuNjI3OyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+CjxnPgoJPHBhdGggZD0iTTMyOC45MDYsNDAxLjk5NGgtMzYuNTUzVjEwOS42MzZoMzYuNTUzYzQuOTQ4LDAsOS4yMzYtMS44MDksMTIuODQ3LTUuNDI2YzMuNjEzLTMuNjE1LDUuNDIxLTcuODk4LDUuNDIxLTEyLjg0NSAgIGMwLTQuOTQ5LTEuODAxLTkuMjMxLTUuNDI4LTEyLjg1MWwtNzMuMDg3LTczLjA5QzI2NS4wNDQsMS44MDksMjYwLjc2LDAsMjU1LjgxMywwYy00Ljk0OCwwLTkuMjI5LDEuODA5LTEyLjg0Nyw1LjQyNCAgIGwtNzMuMDg4LDczLjA5Yy0zLjYxOCwzLjYxOS01LjQyNCw3LjkwMi01LjQyNCwxMi44NTFjMCw0Ljk0NiwxLjgwNyw5LjIyOSw1LjQyNCwxMi44NDVjMy42MTksMy42MTcsNy45MDEsNS40MjYsMTIuODUsNS40MjYgICBoMzYuNTQ1djI5Mi4zNThoLTM2LjU0MmMtNC45NTIsMC05LjIzNSwxLjgwOC0xMi44NSw1LjQyMWMtMy42MTcsMy42MjEtNS40MjQsNy45MDUtNS40MjQsMTIuODU0ICAgYzAsNC45NDUsMS44MDcsOS4yMjcsNS40MjQsMTIuODQ3bDczLjA4OSw3My4wODhjMy42MTcsMy42MTcsNy44OTgsNS40MjQsMTIuODQ3LDUuNDI0YzQuOTUsMCw5LjIzNC0xLjgwNywxMi44NDktNS40MjQgICBsNzMuMDg3LTczLjA4OGMzLjYxMy0zLjYyLDUuNDIxLTcuOTAxLDUuNDIxLTEyLjg0N2MwLTQuOTQ4LTEuODA4LTkuMjMyLTUuNDIxLTEyLjg1NCAgIEMzMzguMTQyLDQwMy44MDIsMzMzLjg1Nyw0MDEuOTk0LDMyOC45MDYsNDAxLjk5NHoiIGZpbGw9IiM2NjY2NjYiLz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8L3N2Zz4K);
|
||||
background-repeat: no-repeat;
|
||||
background-position: center;
|
||||
-webkit-transform: rotate(45deg);
|
||||
-moz-transform: rotate(45deg);
|
||||
-ms-transform: rotate(45deg);
|
||||
-o-transform: rotate(45deg);
|
||||
transform: rotate(45deg);
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item > .ui-resizable-se {
|
||||
display: inline-block;
|
||||
filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=1);
|
||||
-webkit-transform: rotate(90deg);
|
||||
-moz-transform: rotate(90deg);
|
||||
-ms-transform: rotate(90deg);
|
||||
-o-transform: rotate(90deg);
|
||||
transform: rotate(90deg);
|
||||
-webkit-transform: rotate(-45deg);
|
||||
-moz-transform: rotate(-45deg);
|
||||
-ms-transform: rotate(-45deg);
|
||||
-o-transform: rotate(-45deg);
|
||||
transform: rotate(-45deg);
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item > .ui-resizable-nw {
|
||||
cursor: nw-resize;
|
||||
width: 20px;
|
||||
|
|
@ -84,6 +98,7 @@
|
|||
left: 10px;
|
||||
top: 0;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item > .ui-resizable-n {
|
||||
cursor: n-resize;
|
||||
height: 10px;
|
||||
|
|
@ -91,6 +106,7 @@
|
|||
left: 25px;
|
||||
right: 25px;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item > .ui-resizable-ne {
|
||||
cursor: ne-resize;
|
||||
width: 20px;
|
||||
|
|
@ -98,6 +114,7 @@
|
|||
right: 10px;
|
||||
top: 0;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item > .ui-resizable-e {
|
||||
cursor: e-resize;
|
||||
width: 10px;
|
||||
|
|
@ -105,6 +122,7 @@
|
|||
top: 15px;
|
||||
bottom: 15px;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item > .ui-resizable-se {
|
||||
cursor: se-resize;
|
||||
width: 20px;
|
||||
|
|
@ -112,6 +130,7 @@
|
|||
right: 10px;
|
||||
bottom: 0;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item > .ui-resizable-s {
|
||||
cursor: s-resize;
|
||||
height: 10px;
|
||||
|
|
@ -119,6 +138,7 @@
|
|||
bottom: 0;
|
||||
right: 25px;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item > .ui-resizable-sw {
|
||||
cursor: sw-resize;
|
||||
width: 20px;
|
||||
|
|
@ -126,6 +146,7 @@
|
|||
left: 10px;
|
||||
bottom: 0;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item > .ui-resizable-w {
|
||||
cursor: w-resize;
|
||||
width: 10px;
|
||||
|
|
@ -133,158 +154,211 @@
|
|||
top: 15px;
|
||||
bottom: 15px;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item[data-gs-width='1'] {
|
||||
width: 8.33333333%;
|
||||
width: 8.3333333333%;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item[data-gs-x='1'] {
|
||||
left: 8.33333333%;
|
||||
left: 8.3333333333%;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item[data-gs-min-width='1'] {
|
||||
min-width: 8.33333333%;
|
||||
min-width: 8.3333333333%;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item[data-gs-max-width='1'] {
|
||||
max-width: 8.33333333%;
|
||||
max-width: 8.3333333333%;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item[data-gs-width='2'] {
|
||||
width: 16.66666667%;
|
||||
width: 16.6666666667%;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item[data-gs-x='2'] {
|
||||
left: 16.66666667%;
|
||||
left: 16.6666666667%;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item[data-gs-min-width='2'] {
|
||||
min-width: 16.66666667%;
|
||||
min-width: 16.6666666667%;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item[data-gs-max-width='2'] {
|
||||
max-width: 16.66666667%;
|
||||
max-width: 16.6666666667%;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item[data-gs-width='3'] {
|
||||
width: 25%;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item[data-gs-x='3'] {
|
||||
left: 25%;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item[data-gs-min-width='3'] {
|
||||
min-width: 25%;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item[data-gs-max-width='3'] {
|
||||
max-width: 25%;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item[data-gs-width='4'] {
|
||||
width: 33.33333333%;
|
||||
width: 33.3333333333%;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item[data-gs-x='4'] {
|
||||
left: 33.33333333%;
|
||||
left: 33.3333333333%;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item[data-gs-min-width='4'] {
|
||||
min-width: 33.33333333%;
|
||||
min-width: 33.3333333333%;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item[data-gs-max-width='4'] {
|
||||
max-width: 33.33333333%;
|
||||
max-width: 33.3333333333%;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item[data-gs-width='5'] {
|
||||
width: 41.66666667%;
|
||||
width: 41.6666666667%;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item[data-gs-x='5'] {
|
||||
left: 41.66666667%;
|
||||
left: 41.6666666667%;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item[data-gs-min-width='5'] {
|
||||
min-width: 41.66666667%;
|
||||
min-width: 41.6666666667%;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item[data-gs-max-width='5'] {
|
||||
max-width: 41.66666667%;
|
||||
max-width: 41.6666666667%;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item[data-gs-width='6'] {
|
||||
width: 50%;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item[data-gs-x='6'] {
|
||||
left: 50%;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item[data-gs-min-width='6'] {
|
||||
min-width: 50%;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item[data-gs-max-width='6'] {
|
||||
max-width: 50%;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item[data-gs-width='7'] {
|
||||
width: 58.33333333%;
|
||||
width: 58.3333333333%;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item[data-gs-x='7'] {
|
||||
left: 58.33333333%;
|
||||
left: 58.3333333333%;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item[data-gs-min-width='7'] {
|
||||
min-width: 58.33333333%;
|
||||
min-width: 58.3333333333%;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item[data-gs-max-width='7'] {
|
||||
max-width: 58.33333333%;
|
||||
max-width: 58.3333333333%;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item[data-gs-width='8'] {
|
||||
width: 66.66666667%;
|
||||
width: 66.6666666667%;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item[data-gs-x='8'] {
|
||||
left: 66.66666667%;
|
||||
left: 66.6666666667%;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item[data-gs-min-width='8'] {
|
||||
min-width: 66.66666667%;
|
||||
min-width: 66.6666666667%;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item[data-gs-max-width='8'] {
|
||||
max-width: 66.66666667%;
|
||||
max-width: 66.6666666667%;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item[data-gs-width='9'] {
|
||||
width: 75%;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item[data-gs-x='9'] {
|
||||
left: 75%;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item[data-gs-min-width='9'] {
|
||||
min-width: 75%;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item[data-gs-max-width='9'] {
|
||||
max-width: 75%;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item[data-gs-width='10'] {
|
||||
width: 83.33333333%;
|
||||
width: 83.3333333333%;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item[data-gs-x='10'] {
|
||||
left: 83.33333333%;
|
||||
left: 83.3333333333%;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item[data-gs-min-width='10'] {
|
||||
min-width: 83.33333333%;
|
||||
min-width: 83.3333333333%;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item[data-gs-max-width='10'] {
|
||||
max-width: 83.33333333%;
|
||||
max-width: 83.3333333333%;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item[data-gs-width='11'] {
|
||||
width: 91.66666667%;
|
||||
width: 91.6666666667%;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item[data-gs-x='11'] {
|
||||
left: 91.66666667%;
|
||||
left: 91.6666666667%;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item[data-gs-min-width='11'] {
|
||||
min-width: 91.66666667%;
|
||||
min-width: 91.6666666667%;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item[data-gs-max-width='11'] {
|
||||
max-width: 91.66666667%;
|
||||
max-width: 91.6666666667%;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item[data-gs-width='12'] {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item[data-gs-x='12'] {
|
||||
left: 100%;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item[data-gs-min-width='12'] {
|
||||
min-width: 100%;
|
||||
}
|
||||
|
||||
.grid-stack > .grid-stack-item[data-gs-max-width='12'] {
|
||||
max-width: 100%;
|
||||
}
|
||||
.grid-stack.grid-stack-animate, .grid-stack.grid-stack-animate .grid-stack-item {
|
||||
|
||||
.grid-stack.grid-stack-animate,
|
||||
.grid-stack.grid-stack-animate .grid-stack-item {
|
||||
-webkit-transition: left 0.3s, top 0.3s, height 0.3s, width 0.3s;
|
||||
-moz-transition: left 0.3s, top 0.3s, height 0.3s, width 0.3s;
|
||||
-ms-transition: left 0.3s, top 0.3s, height 0.3s, width 0.3s;
|
||||
-o-transition: left 0.3s, top 0.3s, height 0.3s, width 0.3s;
|
||||
transition: left 0.3s, top 0.3s, height 0.3s, width 0.3s;
|
||||
}
|
||||
.grid-stack.grid-stack-animate .grid-stack-item.ui-draggable-dragging, .grid-stack.grid-stack-animate .grid-stack-item.ui-resizable-resizing, .grid-stack.grid-stack-animate .grid-stack-item.grid-stack-placeholder {
|
||||
|
||||
.grid-stack.grid-stack-animate .grid-stack-item.ui-draggable-dragging,
|
||||
.grid-stack.grid-stack-animate .grid-stack-item.ui-resizable-resizing,
|
||||
.grid-stack.grid-stack-animate .grid-stack-item.grid-stack-placeholder {
|
||||
-webkit-transition: left 0s, top 0s, height 0s, width 0s;
|
||||
-moz-transition: left 0s, top 0s, height 0s, width 0s;
|
||||
-ms-transition: left 0s, top 0s, height 0s, width 0s;
|
||||
|
|
@ -292,14 +366,6 @@
|
|||
transition: left 0s, top 0s, height 0s, width 0s;
|
||||
}
|
||||
|
||||
/** Uncomment this to show bottom-left resize handle **/
|
||||
/*
|
||||
.grid-stack > .grid-stack-item > .ui-resizable-sw {
|
||||
display: inline-block;
|
||||
filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3);
|
||||
@include vendor(transform, rotate(180deg));
|
||||
}
|
||||
*/
|
||||
@media (max-width: 768px) {
|
||||
.grid-stack-item {
|
||||
position: relative !important;
|
||||
|
|
@ -311,7 +377,6 @@
|
|||
.grid-stack-item .ui-resizable-handle {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.grid-stack {
|
||||
height: auto !important;
|
||||
}
|
||||
1332
dist/gridstack.js
vendored
Normal file
1332
dist/gridstack.js
vendored
Normal file
File diff suppressed because it is too large
Load diff
1
dist/gridstack.min.css
vendored
Normal file
1
dist/gridstack.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
16
dist/gridstack.min.js
vendored
Normal file
16
dist/gridstack.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
dist/gridstack.min.map
vendored
Normal file
1
dist/gridstack.min.map
vendored
Normal file
File diff suppressed because one or more lines are too long
870
gridstack.js
870
gridstack.js
|
|
@ -1,870 +0,0 @@
|
|||
// gridstack.js 0.2.3-dev
|
||||
// http://troolee.github.io/gridstack.js/
|
||||
// (c) 2014-2015 Pavel Reznikov
|
||||
// gridstack.js may be freely distributed under the MIT license.
|
||||
|
||||
(function (factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
define(['jquery', 'lodash', 'jquery-ui/core', 'jquery-ui/widget', 'jquery-ui/mouse', 'jquery-ui/draggable', 'jquery-ui/resizable'], factory);
|
||||
}
|
||||
else {
|
||||
factory(jQuery, _);
|
||||
}
|
||||
})(function ($, _) {
|
||||
|
||||
var scope = window;
|
||||
|
||||
var Utils = {
|
||||
is_intercepted: function (a, b) {
|
||||
return !(a.x + a.width <= b.x || b.x + b.width <= a.x || a.y + a.height <= b.y || b.y + b.height <= a.y);
|
||||
},
|
||||
|
||||
sort: function (nodes, dir, width) {
|
||||
width = width || _.chain(nodes).map(function (node) { return node.x + node.width; }).max().value();
|
||||
dir = dir != -1 ? 1 : -1;
|
||||
return _.sortBy(nodes, function (n) { return dir * (n.x + n.y * width); });
|
||||
},
|
||||
|
||||
create_stylesheet: function (id) {
|
||||
var style = document.createElement("style");
|
||||
style.setAttribute("type", "text/css");
|
||||
style.setAttribute("data-gs-id", id);
|
||||
if (style.styleSheet) {
|
||||
style.styleSheet.cssText = "";
|
||||
}
|
||||
else {
|
||||
style.appendChild(document.createTextNode(""));
|
||||
}
|
||||
document.getElementsByTagName('head')[0].appendChild(style);
|
||||
return style.sheet;
|
||||
},
|
||||
|
||||
insert_css_rule: function (sheet, selector, rules, index) {
|
||||
if(typeof sheet.insertRule === 'function') {
|
||||
sheet.insertRule(selector + "{" + rules + "}", index);
|
||||
}
|
||||
else if(typeof sheet.addRule === 'function') {
|
||||
sheet.addRule(selector, rules, index);
|
||||
}
|
||||
},
|
||||
|
||||
toBool: function (v) {
|
||||
if (typeof v == 'boolean')
|
||||
return v;
|
||||
if (typeof v == 'string') {
|
||||
v = v.toLowerCase();
|
||||
return !(v == '' || v == 'no' || v == 'false' || v == '0');
|
||||
}
|
||||
return Boolean(v);
|
||||
}
|
||||
};
|
||||
|
||||
var id_seq = 0;
|
||||
|
||||
var GridStackEngine = function (width, onchange, float, height, items) {
|
||||
this.width = width;
|
||||
this.float = float || false;
|
||||
this.height = height || 0;
|
||||
|
||||
this.nodes = items || [];
|
||||
this.onchange = onchange || function () {};
|
||||
|
||||
this._update_counter = 0;
|
||||
this._float = this.float;
|
||||
};
|
||||
|
||||
GridStackEngine.prototype.batch_update = function () {
|
||||
this._update_counter = 1;
|
||||
this.float = true;
|
||||
};
|
||||
|
||||
GridStackEngine.prototype.commit = function () {
|
||||
this._update_counter = 0;
|
||||
if (this._update_counter == 0) {
|
||||
this.float = this._float;
|
||||
this._pack_nodes();
|
||||
this._notify();
|
||||
}
|
||||
};
|
||||
|
||||
GridStackEngine.prototype._fix_collisions = function (node) {
|
||||
this._sort_nodes(-1);
|
||||
|
||||
var nn = node, has_locked = Boolean(_.find(this.nodes, function (n) { return n.locked }));
|
||||
if (!this.float && !has_locked) {
|
||||
nn = {x: 0, y: node.y, width: this.width, height: node.height};
|
||||
}
|
||||
|
||||
while (true) {
|
||||
var collision_node = _.find(this.nodes, function (n) {
|
||||
return n != node && Utils.is_intercepted(n, nn);
|
||||
}, this);
|
||||
if (typeof collision_node == 'undefined') {
|
||||
return;
|
||||
}
|
||||
this.move_node(collision_node, collision_node.x, node.y + node.height,
|
||||
collision_node.width, collision_node.height, true);
|
||||
}
|
||||
};
|
||||
|
||||
GridStackEngine.prototype.is_area_empty = function (x, y, width, height) {
|
||||
var nn = {x: x || 0, y: y || 0, width: width || 1, height: height || 1};
|
||||
var collision_node = _.find(this.nodes, function (n) {
|
||||
return Utils.is_intercepted(n, nn);
|
||||
}, this);
|
||||
return collision_node == null;
|
||||
};
|
||||
|
||||
GridStackEngine.prototype._sort_nodes = function (dir) {
|
||||
this.nodes = Utils.sort(this.nodes, dir, this.width);
|
||||
};
|
||||
|
||||
GridStackEngine.prototype._pack_nodes = function () {
|
||||
this._sort_nodes();
|
||||
|
||||
if (this.float) {
|
||||
_.each(this.nodes, function (n, i) {
|
||||
if (n._updating || typeof n._orig_y == 'undefined' || n.y == n._orig_y)
|
||||
return;
|
||||
|
||||
var new_y = n.y;
|
||||
while (new_y >= n._orig_y) {
|
||||
var collision_node = _.chain(this.nodes)
|
||||
.find(function (bn) {
|
||||
return n != bn && Utils.is_intercepted({x: n.x, y: new_y, width: n.width, height: n.height}, bn);
|
||||
})
|
||||
.value();
|
||||
|
||||
if (!collision_node) {
|
||||
n._dirty = true;
|
||||
n.y = new_y;
|
||||
}
|
||||
--new_y;
|
||||
}
|
||||
}, this);
|
||||
}
|
||||
else {
|
||||
_.each(this.nodes, function (n, i) {
|
||||
if (n.locked)
|
||||
return;
|
||||
while (n.y > 0) {
|
||||
var new_y = n.y - 1;
|
||||
var can_be_moved = i == 0;
|
||||
|
||||
if (i > 0) {
|
||||
var collision_node = _.chain(this.nodes)
|
||||
.take(i)
|
||||
.find(function (bn) {
|
||||
return Utils.is_intercepted({x: n.x, y: new_y, width: n.width, height: n.height}, bn);
|
||||
})
|
||||
.value();
|
||||
can_be_moved = typeof collision_node == 'undefined';
|
||||
}
|
||||
|
||||
if (!can_be_moved) {
|
||||
break;
|
||||
}
|
||||
n._dirty = n.y != new_y;
|
||||
n.y = new_y;
|
||||
}
|
||||
}, this);
|
||||
}
|
||||
};
|
||||
|
||||
GridStackEngine.prototype._prepare_node = function (node, resizing) {
|
||||
node = _.defaults(node || {}, {width: 1, height: 1, x: 0, y: 0 });
|
||||
|
||||
node.x = parseInt('' + node.x);
|
||||
node.y = parseInt('' + node.y);
|
||||
node.width = parseInt('' + node.width);
|
||||
node.height = parseInt('' + node.height);
|
||||
node.auto_position = node.auto_position || false;
|
||||
node.no_resize = node.no_resize || false;
|
||||
node.no_move = node.no_move || false;
|
||||
|
||||
if (node.width > this.width) {
|
||||
node.width = this.width;
|
||||
}
|
||||
else if (node.width < 1) {
|
||||
node.width = 1;
|
||||
}
|
||||
|
||||
if (node.height < 1) {
|
||||
node.height = 1;
|
||||
}
|
||||
|
||||
if (node.x < 0) {
|
||||
node.x = 0;
|
||||
}
|
||||
|
||||
if (node.x + node.width > this.width) {
|
||||
if (resizing) {
|
||||
node.width = this.width - node.x;
|
||||
}
|
||||
else {
|
||||
node.x = this.width - node.width;
|
||||
}
|
||||
}
|
||||
|
||||
if (node.y < 0) {
|
||||
node.y = 0;
|
||||
}
|
||||
|
||||
return node;
|
||||
};
|
||||
|
||||
GridStackEngine.prototype._notify = function () {
|
||||
if (this._update_counter) {
|
||||
return;
|
||||
}
|
||||
var deleted_nodes = Array.prototype.slice.call(arguments, 1).concat(this.get_dirty_nodes());
|
||||
deleted_nodes = deleted_nodes.concat(this.get_dirty_nodes());
|
||||
this.onchange(deleted_nodes);
|
||||
};
|
||||
|
||||
GridStackEngine.prototype.clean_nodes = function () {
|
||||
_.each(this.nodes, function (n) {n._dirty = false });
|
||||
};
|
||||
|
||||
GridStackEngine.prototype.get_dirty_nodes = function () {
|
||||
return _.filter(this.nodes, function (n) { return n._dirty; });
|
||||
};
|
||||
|
||||
GridStackEngine.prototype.add_node = function(node) {
|
||||
node = this._prepare_node(node);
|
||||
|
||||
if (typeof node.max_width != 'undefined') node.width = Math.min(node.width, node.max_width);
|
||||
if (typeof node.max_height != 'undefined') node.height = Math.min(node.height, node.max_height);
|
||||
if (typeof node.min_width != 'undefined') node.width = Math.max(node.width, node.min_width);
|
||||
if (typeof node.min_height != 'undefined') node.height = Math.max(node.height, node.min_height);
|
||||
|
||||
node._id = ++id_seq;
|
||||
node._dirty = true;
|
||||
|
||||
if (node.auto_position) {
|
||||
this._sort_nodes();
|
||||
|
||||
for (var i = 0; ; ++i) {
|
||||
var x = i % this.width, y = Math.floor(i / this.width);
|
||||
if (x + node.width > this.width) {
|
||||
continue;
|
||||
}
|
||||
if (!_.find(this.nodes, function (n) {
|
||||
return Utils.is_intercepted({x: x, y: y, width: node.width, height: node.height}, n);
|
||||
})) {
|
||||
node.x = x;
|
||||
node.y = y;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.nodes.push(node);
|
||||
|
||||
this._fix_collisions(node);
|
||||
this._pack_nodes();
|
||||
this._notify();
|
||||
return node;
|
||||
};
|
||||
|
||||
GridStackEngine.prototype.remove_node = function (node) {
|
||||
node._id = null;
|
||||
this.nodes = _.without(this.nodes, node);
|
||||
this._pack_nodes();
|
||||
this._notify(node);
|
||||
};
|
||||
|
||||
GridStackEngine.prototype.can_move_node = function (node, x, y, width, height) {
|
||||
var has_locked = Boolean(_.find(this.nodes, function (n) { return n.locked }));
|
||||
|
||||
if (!this.height && !has_locked)
|
||||
return true;
|
||||
|
||||
var cloned_node;
|
||||
var clone = new GridStackEngine(
|
||||
this.width,
|
||||
null,
|
||||
this.float,
|
||||
0,
|
||||
_.map(this.nodes, function (n) { if (n == node) { cloned_node = $.extend({}, n); return cloned_node; } return $.extend({}, n) }));
|
||||
|
||||
clone.move_node(cloned_node, x, y, width, height);
|
||||
|
||||
var res = true;
|
||||
|
||||
if (has_locked)
|
||||
res &= !Boolean(_.find(clone.nodes, function (n) { return n != cloned_node && Boolean(n.locked) && Boolean(n._dirty); }));
|
||||
if (this.height)
|
||||
res &= clone.get_grid_height() <= this.height;
|
||||
|
||||
return res;
|
||||
};
|
||||
|
||||
GridStackEngine.prototype.can_be_placed_with_respect_to_height = function (node) {
|
||||
if (!this.height)
|
||||
return true;
|
||||
|
||||
var clone = new GridStackEngine(
|
||||
this.width,
|
||||
null,
|
||||
this.float,
|
||||
0,
|
||||
_.map(this.nodes, function (n) { return $.extend({}, n) }));
|
||||
clone.add_node(node);
|
||||
return clone.get_grid_height() <= this.height;
|
||||
};
|
||||
|
||||
GridStackEngine.prototype.move_node = function (node, x, y, width, height, no_pack) {
|
||||
if (typeof x != 'number') x = node.x;
|
||||
if (typeof y != 'number') y = node.y;
|
||||
if (typeof width != 'number') width = node.width;
|
||||
if (typeof height != 'number') height = node.height;
|
||||
|
||||
if (typeof node.max_width != 'undefined') width = Math.min(width, node.max_width);
|
||||
if (typeof node.max_height != 'undefined') height = Math.min(height, node.max_height);
|
||||
if (typeof node.min_width != 'undefined') width = Math.max(width, node.min_width);
|
||||
if (typeof node.min_height != 'undefined') height = Math.max(height, node.min_height);
|
||||
|
||||
if (node.x == x && node.y == y && node.width == width && node.height == height) {
|
||||
return node;
|
||||
}
|
||||
|
||||
var resizing = node.width != width;
|
||||
node._dirty = true;
|
||||
|
||||
node.x = x;
|
||||
node.y = y;
|
||||
node.width = width;
|
||||
node.height = height;
|
||||
|
||||
node = this._prepare_node(node, resizing);
|
||||
|
||||
this._fix_collisions(node);
|
||||
if (!no_pack) {
|
||||
this._pack_nodes();
|
||||
this._notify();
|
||||
}
|
||||
return node;
|
||||
};
|
||||
|
||||
GridStackEngine.prototype.get_grid_height = function () {
|
||||
return _.reduce(this.nodes, function (memo, n) { return Math.max(memo, n.y + n.height); }, 0);
|
||||
};
|
||||
|
||||
GridStackEngine.prototype.begin_update = function (node) {
|
||||
_.each(this.nodes, function (n) {
|
||||
n._orig_y = n.y;
|
||||
});
|
||||
node._updating = true;
|
||||
};
|
||||
|
||||
GridStackEngine.prototype.end_update = function () {
|
||||
_.each(this.nodes, function (n) {
|
||||
n._orig_y = n.y;
|
||||
});
|
||||
var n = _.find(this.nodes, function (n) { return n._updating; });
|
||||
if (n) {
|
||||
n._updating = false;
|
||||
}
|
||||
};
|
||||
|
||||
var GridStack = function (el, opts) {
|
||||
var self = this, one_column_mode;
|
||||
|
||||
this.container = $(el);
|
||||
|
||||
opts.item_class = opts.item_class || 'grid-stack-item';
|
||||
var is_nested = this.container.closest('.' + opts.item_class).size() > 0;
|
||||
|
||||
this.opts = _.defaults(opts || {}, {
|
||||
width: parseInt(this.container.attr('data-gs-width')) || 12,
|
||||
height: parseInt(this.container.attr('data-gs-height')) || 0,
|
||||
item_class: 'grid-stack-item',
|
||||
placeholder_class: 'grid-stack-placeholder',
|
||||
handle: '.grid-stack-item-content',
|
||||
cell_height: 60,
|
||||
vertical_margin: 20,
|
||||
auto: true,
|
||||
min_width: 768,
|
||||
float: false,
|
||||
_class: 'grid-stack-' + (Math.random() * 10000).toFixed(0),
|
||||
animate: Boolean(this.container.attr('data-gs-animate')) || false,
|
||||
always_show_resize_handle: opts.always_show_resize_handle || false,
|
||||
resizable: _.defaults(opts.resizable || {}, {
|
||||
autoHide: !(opts.always_show_resize_handle || false),
|
||||
handles: 'se'
|
||||
}),
|
||||
draggable: _.defaults(opts.draggable || {}, {
|
||||
handle: '.grid-stack-item-content',
|
||||
scroll: false,
|
||||
appendTo: 'body'
|
||||
})
|
||||
});
|
||||
this.opts.is_nested = is_nested;
|
||||
|
||||
this.container.addClass(this.opts._class);
|
||||
if (is_nested) {
|
||||
this.container.addClass('grid-stack-nested');
|
||||
}
|
||||
|
||||
this._init_styles();
|
||||
|
||||
this.grid = new GridStackEngine(this.opts.width, function (nodes) {
|
||||
var max_height = 0;
|
||||
_.each(nodes, function (n) {
|
||||
if (n._id == null) {
|
||||
n.el.remove();
|
||||
}
|
||||
else {
|
||||
n.el
|
||||
.attr('data-gs-x', n.x)
|
||||
.attr('data-gs-y', n.y)
|
||||
.attr('data-gs-width', n.width)
|
||||
.attr('data-gs-height', n.height);
|
||||
max_height = Math.max(max_height, n.y + n.height);
|
||||
}
|
||||
});
|
||||
self._update_styles(max_height + 10);
|
||||
}, this.opts.float, this.opts.height);
|
||||
|
||||
if (this.opts.auto) {
|
||||
var elements = [];
|
||||
var _this = this;
|
||||
this.container.children('.' + this.opts.item_class).each(function (index, el) {
|
||||
el = $(el);
|
||||
elements.push({
|
||||
el: el,
|
||||
i: parseInt(el.attr('data-gs-x')) + parseInt(el.attr('data-gs-y')) * _this.opts.width // Use opts.width as weight for Y
|
||||
});
|
||||
});
|
||||
_.chain(elements).sortBy(function (x) { return x.i; }).each(function (i) {
|
||||
self._prepare_element(i.el);
|
||||
}).value();
|
||||
}
|
||||
|
||||
this.set_animation(this.opts.animate);
|
||||
|
||||
this.placeholder = $('<div class="' + this.opts.placeholder_class + ' ' + this.opts.item_class + '"><div class="placeholder-content" /></div>').hide();
|
||||
this.container.height((this.grid.get_grid_height()) * (this.opts.cell_height + this.opts.vertical_margin) - this.opts.vertical_margin);
|
||||
|
||||
var on_resize_handler = function () {
|
||||
if (self._is_one_column_mode()) {
|
||||
if (one_column_mode)
|
||||
return;
|
||||
|
||||
one_column_mode = true;
|
||||
|
||||
self.grid._sort_nodes();
|
||||
_.each(self.grid.nodes, function (node) {
|
||||
self.container.append(node.el);
|
||||
|
||||
if (!node.no_move) {
|
||||
node.el.draggable('disable');
|
||||
}
|
||||
if (!node.no_resize) {
|
||||
node.el.resizable('disable');
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
if (!one_column_mode)
|
||||
return;
|
||||
|
||||
one_column_mode = false;
|
||||
|
||||
_.each(self.grid.nodes, function (node) {
|
||||
if (!node.no_move) {
|
||||
node.el.draggable('enable');
|
||||
}
|
||||
if (!node.no_resize) {
|
||||
node.el.resizable('enable');
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
$(window).resize(on_resize_handler);
|
||||
on_resize_handler();
|
||||
};
|
||||
|
||||
GridStack.prototype._init_styles = function () {
|
||||
if (this._styles_id) {
|
||||
$('[data-gs-id="' + this._styles_id + '"]').remove();
|
||||
}
|
||||
this._styles_id = 'gridstack-style-' + (Math.random() * 100000).toFixed();
|
||||
this._styles = Utils.create_stylesheet(this._styles_id);
|
||||
if (this._styles != null)
|
||||
this._styles._max = 0;
|
||||
};
|
||||
|
||||
GridStack.prototype._update_styles = function (max_height) {
|
||||
if (this._styles == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
var prefix = '.' + this.opts._class + ' .' + this.opts.item_class;
|
||||
|
||||
if (typeof max_height == 'undefined') {
|
||||
max_height = this._styles._max;
|
||||
this._init_styles();
|
||||
this._update_container_height();
|
||||
}
|
||||
|
||||
if (this._styles._max == 0) {
|
||||
Utils.insert_css_rule(this._styles, prefix, 'min-height: ' + (this.opts.cell_height) + 'px;', 0);
|
||||
}
|
||||
|
||||
if (max_height > this._styles._max) {
|
||||
for (var i = this._styles._max; i < max_height; ++i) {
|
||||
Utils.insert_css_rule(this._styles,
|
||||
prefix + '[data-gs-height="' + (i + 1) + '"]',
|
||||
'height: ' + (this.opts.cell_height * (i + 1) + this.opts.vertical_margin * i) + 'px;',
|
||||
i
|
||||
);
|
||||
Utils.insert_css_rule(this._styles,
|
||||
prefix + '[data-gs-min-height="' + (i + 1) + '"]',
|
||||
'min-height: ' + (this.opts.cell_height * (i + 1) + this.opts.vertical_margin * i) + 'px;',
|
||||
i
|
||||
);
|
||||
Utils.insert_css_rule(this._styles,
|
||||
prefix + '[data-gs-max-height="' + (i + 1) + '"]',
|
||||
'max-height: ' + (this.opts.cell_height * (i + 1) + this.opts.vertical_margin * i) + 'px;',
|
||||
i
|
||||
);
|
||||
Utils.insert_css_rule(this._styles,
|
||||
prefix + '[data-gs-y="' + i + '"]',
|
||||
'top: ' + (this.opts.cell_height * i + this.opts.vertical_margin * i) + 'px;',
|
||||
i
|
||||
);
|
||||
}
|
||||
this._styles._max = max_height;
|
||||
}
|
||||
};
|
||||
|
||||
GridStack.prototype._update_container_height = function () {
|
||||
if (this.grid._update_counter) {
|
||||
return;
|
||||
}
|
||||
this.container.height(this.grid.get_grid_height() * (this.opts.cell_height + this.opts.vertical_margin) - this.opts.vertical_margin);
|
||||
};
|
||||
|
||||
GridStack.prototype._is_one_column_mode = function () {
|
||||
return (window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth) <= this.opts.min_width;
|
||||
};
|
||||
|
||||
GridStack.prototype._prepare_element = function (el) {
|
||||
var self = this;
|
||||
el = $(el);
|
||||
|
||||
el.addClass(this.opts.item_class);
|
||||
|
||||
var node = self.grid.add_node({
|
||||
x: el.attr('data-gs-x'),
|
||||
y: el.attr('data-gs-y'),
|
||||
width: el.attr('data-gs-width'),
|
||||
height: el.attr('data-gs-height'),
|
||||
max_width: el.attr('data-gs-max-width'),
|
||||
min_width: el.attr('data-gs-min-width'),
|
||||
max_height: el.attr('data-gs-max-height'),
|
||||
min_height: el.attr('data-gs-min-height'),
|
||||
auto_position: Utils.toBool(el.attr('data-gs-auto-position')),
|
||||
no_resize: Utils.toBool(el.attr('data-gs-no-resize')),
|
||||
no_move: Utils.toBool(el.attr('data-gs-no-move')),
|
||||
locked: Utils.toBool(el.attr('data-gs-locked')),
|
||||
el: el
|
||||
});
|
||||
el.data('_gridstack_node', node);
|
||||
|
||||
var cell_width, cell_height;
|
||||
|
||||
var on_start_moving = function (event, ui) {
|
||||
self.container.append(self.placeholder);
|
||||
var o = $(this);
|
||||
self.grid.clean_nodes();
|
||||
self.grid.begin_update(node);
|
||||
cell_width = Math.ceil(o.outerWidth() / o.attr('data-gs-width'));
|
||||
cell_height = self.opts.cell_height + self.opts.vertical_margin;
|
||||
self.placeholder
|
||||
.attr('data-gs-x', o.attr('data-gs-x'))
|
||||
.attr('data-gs-y', o.attr('data-gs-y'))
|
||||
.attr('data-gs-width', o.attr('data-gs-width'))
|
||||
.attr('data-gs-height', o.attr('data-gs-height'))
|
||||
.show();
|
||||
node.el = self.placeholder;
|
||||
|
||||
el.resizable('option', 'minWidth', cell_width * (node.min_width || 1));
|
||||
el.resizable('option', 'minHeight', self.opts.cell_height * (node.min_height || 1));
|
||||
};
|
||||
|
||||
var on_end_moving = function (event, ui) {
|
||||
self.placeholder.detach();
|
||||
var o = $(this);
|
||||
node.el = o;
|
||||
self.placeholder.hide();
|
||||
o
|
||||
.attr('data-gs-x', node.x)
|
||||
.attr('data-gs-y', node.y)
|
||||
.attr('data-gs-width', node.width)
|
||||
.attr('data-gs-height', node.height)
|
||||
.removeAttr('style');
|
||||
self._update_container_height();
|
||||
self.container.trigger('change', [self.grid.get_dirty_nodes()]);
|
||||
|
||||
self.grid.end_update();
|
||||
};
|
||||
|
||||
el.draggable(_.extend(this.opts.draggable, {
|
||||
start: on_start_moving,
|
||||
stop: on_end_moving,
|
||||
drag: function (event, ui) {
|
||||
var x = Math.round(ui.position.left / cell_width),
|
||||
y = Math.floor((ui.position.top + cell_height/2) / cell_height);
|
||||
if (!self.grid.can_move_node(node, x, y, node.width, node.height)) {
|
||||
return;
|
||||
}
|
||||
self.grid.move_node(node, x, y);
|
||||
self._update_container_height();
|
||||
},
|
||||
containment: this.opts.is_nested ? this.container.parent() : null
|
||||
})).resizable(_.extend(this.opts.resizable, {
|
||||
start: on_start_moving,
|
||||
stop: on_end_moving,
|
||||
resize: function (event, ui) {
|
||||
var x = Math.round(ui.position.left / cell_width),
|
||||
y = Math.floor((ui.position.top + cell_height/2) / cell_height),
|
||||
width = Math.round(ui.size.width / cell_width),
|
||||
height = Math.round(ui.size.height / cell_height);
|
||||
if (!self.grid.can_move_node(node, x, y, width, height)) {
|
||||
return;
|
||||
}
|
||||
self.grid.move_node(node, x, y, width, height);
|
||||
self._update_container_height();
|
||||
}
|
||||
}));
|
||||
|
||||
if (node.no_move || this._is_one_column_mode()) {
|
||||
el.draggable('disable');
|
||||
}
|
||||
|
||||
if (node.no_resize || this._is_one_column_mode()) {
|
||||
el.resizable('disable');
|
||||
}
|
||||
|
||||
el.attr('data-gs-locked', node.locked ? 'yes' : null);
|
||||
};
|
||||
|
||||
GridStack.prototype.set_animation = function (enable) {
|
||||
if (enable) {
|
||||
this.container.addClass('grid-stack-animate');
|
||||
}
|
||||
else {
|
||||
this.container.removeClass('grid-stack-animate');
|
||||
}
|
||||
};
|
||||
|
||||
GridStack.prototype.add_widget = function (el, x, y, width, height, auto_position) {
|
||||
el = $(el);
|
||||
if (typeof x != 'undefined') el.attr('data-gs-x', x);
|
||||
if (typeof y != 'undefined') el.attr('data-gs-y', y);
|
||||
if (typeof width != 'undefined') el.attr('data-gs-width', width);
|
||||
if (typeof height != 'undefined') el.attr('data-gs-height', height);
|
||||
if (typeof auto_position != 'undefined') el.attr('data-gs-auto-position', auto_position ? 'yes' : null);
|
||||
this.container.append(el);
|
||||
this._prepare_element(el);
|
||||
this._update_container_height();
|
||||
|
||||
return el;
|
||||
};
|
||||
|
||||
GridStack.prototype.will_it_fit = function (x, y, width, height, auto_position) {
|
||||
var node = {x: x, y: y, width: width, height: height, auto_position: auto_position};
|
||||
return this.grid.can_be_placed_with_respect_to_height(node);
|
||||
};
|
||||
|
||||
GridStack.prototype.remove_widget = function (el, detach_node) {
|
||||
detach_node = typeof detach_node === 'undefined' ? true : detach_node;
|
||||
el = $(el);
|
||||
var node = el.data('_gridstack_node');
|
||||
this.grid.remove_node(node);
|
||||
el.removeData('_gridstack_node');
|
||||
this._update_container_height();
|
||||
if (detach_node)
|
||||
el.remove();
|
||||
};
|
||||
|
||||
GridStack.prototype.remove_all = function (detach_node) {
|
||||
_.each(this.grid.nodes, function (node) {
|
||||
this.remove_widget(node.el, detach_node);
|
||||
}, this);
|
||||
this.grid.nodes = [];
|
||||
this._update_container_height();
|
||||
};
|
||||
|
||||
GridStack.prototype.resizable = function (el, val) {
|
||||
el = $(el);
|
||||
el.each(function (index, el) {
|
||||
el = $(el);
|
||||
var node = el.data('_gridstack_node');
|
||||
if (typeof node == 'undefined' || node == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
node.no_resize = !(val || false);
|
||||
if (node.no_resize) {
|
||||
el.resizable('disable');
|
||||
}
|
||||
else {
|
||||
el.resizable('enable');
|
||||
}
|
||||
});
|
||||
return this;
|
||||
};
|
||||
|
||||
GridStack.prototype.movable = function (el, val) {
|
||||
el = $(el);
|
||||
el.each(function (index, el) {
|
||||
el = $(el);
|
||||
var node = el.data('_gridstack_node');
|
||||
if (typeof node == 'undefined' || node == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
node.no_move = !(val || false);
|
||||
if (node.no_move) {
|
||||
el.draggable('disable');
|
||||
}
|
||||
else {
|
||||
el.draggable('enable');
|
||||
}
|
||||
});
|
||||
return this;
|
||||
};
|
||||
|
||||
GridStack.prototype.disable = function () {
|
||||
this.movable(this.container.children('.' + this.opts.item_class), false);
|
||||
this.resizable(this.container.children('.' + this.opts.item_class), false);
|
||||
};
|
||||
|
||||
GridStack.prototype.enable = function () {
|
||||
this.movable(this.container.children('.' + this.opts.item_class), true);
|
||||
this.resizable(this.container.children('.' + this.opts.item_class), true);
|
||||
};
|
||||
|
||||
GridStack.prototype.locked = function (el, val) {
|
||||
el = $(el);
|
||||
el.each(function (index, el) {
|
||||
el = $(el);
|
||||
var node = el.data('_gridstack_node');
|
||||
if (typeof node == 'undefined' || node == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
node.locked = (val || false);
|
||||
el.attr('data-gs-locked', node.locked ? 'yes' : null);
|
||||
});
|
||||
return this;
|
||||
};
|
||||
|
||||
GridStack.prototype._update_element = function (el, callback) {
|
||||
el = $(el).first();
|
||||
var node = el.data('_gridstack_node');
|
||||
if (typeof node == 'undefined' || node == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
var self = this;
|
||||
|
||||
self.grid.clean_nodes();
|
||||
self.grid.begin_update(node);
|
||||
|
||||
callback.call(this, el, node);
|
||||
|
||||
self._update_container_height();
|
||||
self.container.trigger('change', [self.grid.get_dirty_nodes()]);
|
||||
|
||||
self.grid.end_update();
|
||||
};
|
||||
|
||||
GridStack.prototype.resize = function (el, width, height) {
|
||||
this._update_element(el, function (el, node) {
|
||||
width = (width != null && typeof width != 'undefined') ? width : node.width;
|
||||
height = (height != null && typeof height != 'undefined') ? height : node.height;
|
||||
|
||||
this.grid.move_node(node, node.x, node.y, width, height);
|
||||
});
|
||||
};
|
||||
|
||||
GridStack.prototype.move = function (el, x, y) {
|
||||
this._update_element(el, function (el, node) {
|
||||
x = (x != null && typeof x != 'undefined') ? x : node.x;
|
||||
y = (y != null && typeof y != 'undefined') ? y : node.y;
|
||||
|
||||
this.grid.move_node(node, x, y, node.width, node.height);
|
||||
});
|
||||
};
|
||||
|
||||
GridStack.prototype.update = function (el, x, y, width, height) {
|
||||
this._update_element(el, function (el, node) {
|
||||
x = (x != null && typeof x != 'undefined') ? x : node.x;
|
||||
y = (y != null && typeof y != 'undefined') ? y : node.y;
|
||||
width = (width != null && typeof width != 'undefined') ? width : node.width;
|
||||
height = (height != null && typeof height != 'undefined') ? height : node.height;
|
||||
|
||||
this.grid.move_node(node, x, y, width, height);
|
||||
});
|
||||
};
|
||||
|
||||
GridStack.prototype.cell_height = function (val) {
|
||||
if (typeof val == 'undefined') {
|
||||
return this.opts.cell_height;
|
||||
}
|
||||
val = parseInt(val);
|
||||
if (val == this.opts.cell_height)
|
||||
return;
|
||||
this.opts.cell_height = val || this.opts.cell_height;
|
||||
this._update_styles();
|
||||
};
|
||||
|
||||
GridStack.prototype.cell_width = function () {
|
||||
var o = this.container.children('.' + this.opts.item_class).first();
|
||||
return Math.ceil(o.outerWidth() / o.attr('data-gs-width'));
|
||||
};
|
||||
|
||||
GridStack.prototype.get_cell_from_pixel = function(position) {
|
||||
var containerPos = this.container.position();
|
||||
var relativeLeft = position.left - containerPos.left;
|
||||
var relativeTop = position.top - containerPos.top;
|
||||
|
||||
var column_width = Math.floor(this.container.width() / this.opts.width);
|
||||
var row_height = this.opts.cell_height + this.opts.vertical_margin;
|
||||
|
||||
return {x: Math.floor(relativeLeft / column_width), y: Math.floor(relativeTop / row_height)};
|
||||
};
|
||||
|
||||
GridStack.prototype.batch_update = function () {
|
||||
this.grid.batch_update();
|
||||
};
|
||||
|
||||
GridStack.prototype.commit = function () {
|
||||
this.grid.commit();
|
||||
this._update_container_height()
|
||||
};
|
||||
|
||||
GridStack.prototype.is_area_empty = function (x, y, width, height) {
|
||||
return this.grid.is_area_empty(x, y, width, height);
|
||||
};
|
||||
|
||||
scope.GridStackUI = GridStack;
|
||||
|
||||
scope.GridStackUI.Utils = Utils;
|
||||
|
||||
$.fn.gridstack = function (opts) {
|
||||
return this.each(function () {
|
||||
if (!$(this).data('gridstack')) {
|
||||
$(this).data('gridstack', new GridStack(this, opts));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
return scope.GridStackUI;
|
||||
});
|
||||
18
index.html
18
index.html
|
|
@ -33,7 +33,7 @@
|
|||
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
|
||||
<![endif]-->
|
||||
|
||||
<link href="gridstack.css" rel="stylesheet">
|
||||
<link href="dist/gridstack.css" rel="stylesheet">
|
||||
<link href="gridstack-demo.css" rel="stylesheet">
|
||||
</head>
|
||||
|
||||
|
|
@ -133,16 +133,16 @@
|
|||
</div>
|
||||
|
||||
<h3>Basic Usage</h3>
|
||||
|
||||
|
||||
<pre><code class="html">
|
||||
<div class="grid-stack">
|
||||
<div class="grid-stack-item"
|
||||
data-gs-x="0" data-gs-y="0"
|
||||
<div class="grid-stack-item"
|
||||
data-gs-x="0" data-gs-y="0"
|
||||
data-gs-width="4" data-gs-height="2">
|
||||
<div class="grid-stack-item-content"></div>
|
||||
</div>
|
||||
<div class="grid-stack-item"
|
||||
data-gs-x="4" data-gs-y="0"
|
||||
<div class="grid-stack-item"
|
||||
data-gs-x="4" data-gs-y="0"
|
||||
data-gs-width="4" data-gs-height="4">
|
||||
<div class="grid-stack-item-content"></div>
|
||||
</div>
|
||||
|
|
@ -200,13 +200,13 @@ $(function () {
|
|||
<!-- Custom Theme JavaScript -->
|
||||
<script src="freelancer/js/freelancer.js"></script>
|
||||
|
||||
<script src="gridstack.js"></script>
|
||||
<script src="dist/gridstack.js"></script>
|
||||
<script type="text/javascript">
|
||||
hljs.initHighlightingOnLoad();
|
||||
$(function () {
|
||||
$('.grid-stack').gridstack({
|
||||
width: 12,
|
||||
always_show_resize_handle: /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent),
|
||||
alwaysShowResizeHandle: /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent),
|
||||
resizable: {
|
||||
handles: 'e, se, s, sw, w'
|
||||
}
|
||||
|
|
@ -226,5 +226,3 @@ $(function () {
|
|||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue