angular-gridster2
Version:
101 lines (100 loc) • 3.51 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("@angular/core");
var GridsterCompact = (function () {
function GridsterCompact(gridster) {
this.gridster = gridster;
}
GridsterCompact.prototype.destroy = function () {
delete this.gridster;
};
GridsterCompact.prototype.checkCompact = function () {
if (this.gridster.$options.compactType !== 'none') {
if (this.gridster.$options.compactType === 'compactUp') {
this.checkCompactUp();
}
else if (this.gridster.$options.compactType === 'compactLeft') {
this.checkCompactLeft();
}
else if (this.gridster.$options.compactType === 'compactUp&Left') {
this.checkCompactUp();
this.checkCompactLeft();
}
else if (this.gridster.$options.compactType === 'compactLeft&Up') {
this.checkCompactLeft();
this.checkCompactUp();
}
}
};
GridsterCompact.prototype.checkCompactUp = function () {
var widgetMovedUp = false, widget, moved;
var l = this.gridster.grid.length;
for (var i = 0; i < l; i++) {
widget = this.gridster.grid[i];
if (widget.$item.compactEnabled === false) {
continue;
}
moved = this.moveUpTillCollision(widget);
if (moved) {
widgetMovedUp = true;
widget.item.y = widget.$item.y;
widget.itemChanged();
}
}
if (widgetMovedUp) {
this.checkCompactUp();
}
return widgetMovedUp;
};
GridsterCompact.prototype.moveUpTillCollision = function (itemComponent) {
itemComponent.$item.y -= 1;
if (this.gridster.checkCollision(itemComponent.$item)) {
itemComponent.$item.y += 1;
return false;
}
else {
this.moveUpTillCollision(itemComponent);
return true;
}
};
GridsterCompact.prototype.checkCompactLeft = function () {
var widgetMovedUp = false, widget, moved;
var l = this.gridster.grid.length;
for (var i = 0; i < l; i++) {
widget = this.gridster.grid[i];
if (widget.$item.compactEnabled === false) {
continue;
}
moved = this.moveLeftTillCollision(widget);
if (moved) {
widgetMovedUp = true;
widget.item.x = widget.$item.x;
widget.itemChanged();
}
}
if (widgetMovedUp) {
this.checkCompactLeft();
}
return widgetMovedUp;
};
GridsterCompact.prototype.moveLeftTillCollision = function (itemComponent) {
itemComponent.$item.x -= 1;
if (this.gridster.checkCollision(itemComponent.$item)) {
itemComponent.$item.x += 1;
return false;
}
else {
this.moveLeftTillCollision(itemComponent);
return true;
}
};
GridsterCompact.decorators = [
{ type: core_1.Injectable },
];
/** @nocollapse */
GridsterCompact.ctorParameters = function () { return [
null,
]; };
return GridsterCompact;
}());
exports.GridsterCompact = GridsterCompact;