locked widgets
This commit is contained in:
parent
3c870a8949
commit
80f3b33210
|
@ -207,7 +207,9 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
GridStackEngine.prototype.can_move_node = function (node, x, y, width, height) {
|
GridStackEngine.prototype.can_move_node = function (node, x, y, width, height) {
|
||||||
if (!this.height)
|
var has_locked = Boolean(_.find(this.nodes, function (n) { return n.locked }));
|
||||||
|
|
||||||
|
if (!this.height && !has_locked)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
var cloned_node;
|
var cloned_node;
|
||||||
|
@ -220,7 +222,14 @@
|
||||||
|
|
||||||
clone.move_node(cloned_node, x, y, width, height);
|
clone.move_node(cloned_node, x, y, width, height);
|
||||||
|
|
||||||
return clone.get_grid_height() <= this.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) {
|
GridStackEngine.prototype.can_be_placed_with_respect_to_height = function (node) {
|
||||||
|
@ -415,6 +424,7 @@
|
||||||
auto_position: el.attr('data-gs-auto-position'),
|
auto_position: el.attr('data-gs-auto-position'),
|
||||||
no_resize: el.attr('data-gs-no-resize'),
|
no_resize: el.attr('data-gs-no-resize'),
|
||||||
no_move: el.attr('data-gs-no-move'),
|
no_move: el.attr('data-gs-no-move'),
|
||||||
|
locked: el.attr('data-gs-locked'),
|
||||||
el: el
|
el: el
|
||||||
});
|
});
|
||||||
el.data('_gridstack_node', node);
|
el.data('_gridstack_node', node);
|
||||||
|
@ -469,7 +479,7 @@
|
||||||
drag: function (event, ui) {
|
drag: function (event, ui) {
|
||||||
var x = Math.round(ui.position.left / cell_width),
|
var x = Math.round(ui.position.left / cell_width),
|
||||||
y = Math.floor((ui.position.top + cell_height/2) / cell_height);
|
y = Math.floor((ui.position.top + cell_height/2) / cell_height);
|
||||||
if (self.opts.height && !self.grid.can_move_node(node, x, y, node.width, node.height)) {
|
if (!self.grid.can_move_node(node, x, y, node.width, node.height)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
self.grid.move_node(node, x, y);
|
self.grid.move_node(node, x, y);
|
||||||
|
@ -486,7 +496,7 @@
|
||||||
resize: function (event, ui) {
|
resize: function (event, ui) {
|
||||||
var width = Math.round(ui.size.width / cell_width),
|
var width = Math.round(ui.size.width / cell_width),
|
||||||
height = Math.round(ui.size.height / cell_height);
|
height = Math.round(ui.size.height / cell_height);
|
||||||
if (self.opts.height && !self.grid.can_move_node(node, node.x, node.y, width, height)) {
|
if (!self.grid.can_move_node(node, node.x, node.y, width, height)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
self.grid.move_node(node, node.x, node.y, width, height);
|
self.grid.move_node(node, node.x, node.y, width, height);
|
||||||
|
@ -501,6 +511,8 @@
|
||||||
if (node.no_resize || this._is_one_column_mode()) {
|
if (node.no_resize || this._is_one_column_mode()) {
|
||||||
el.resizable('disable');
|
el.resizable('disable');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
el.attr('data-gs-locked', node.locked ? 'yes' : null);
|
||||||
};
|
};
|
||||||
|
|
||||||
GridStack.prototype.set_animation = function (enable) {
|
GridStack.prototype.set_animation = function (enable) {
|
||||||
|
@ -585,6 +597,21 @@
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
node.locked = (val || false);
|
||||||
|
el.attr('data-gs-locked', node.locked ? 'yes' : null);
|
||||||
|
});
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
GridStack.prototype._update_element = function (el, callback) {
|
GridStack.prototype._update_element = function (el, callback) {
|
||||||
el = $(el).first();
|
el = $(el).first();
|
||||||
var node = el.data('_gridstack_node');
|
var node = el.data('_gridstack_node');
|
||||||
|
|
Loading…
Reference in a new issue