angular-gridster2
Advanced tools
Comparing version 2.10.4 to 2.10.5
@@ -38,2 +38,6 @@ import { GridsterSwap } from './gridsterSwap.service'; | ||
swap: GridsterSwap; | ||
path: Array<{ | ||
x: number; | ||
y: number; | ||
}>; | ||
static touchEvent(e: any): void; | ||
@@ -40,0 +44,0 @@ constructor(gridsterItem: GridsterItemComponent, gridster: GridsterComponent); |
@@ -17,2 +17,3 @@ "use strict"; | ||
}; | ||
this.path = []; | ||
} | ||
@@ -75,2 +76,3 @@ GridsterDraggable.touchEvent = function (e) { | ||
this.gridster.gridLines.updateGrid(true); | ||
this.path.push({ x: this.gridsterItem.item.x, y: this.gridsterItem.item.y }); | ||
}; | ||
@@ -108,2 +110,3 @@ GridsterDraggable.prototype.dragMove = function (e) { | ||
this.gridster.gridLines.updateGrid(false); | ||
this.path = []; | ||
if (this.gridster.$options.draggable.stop) { | ||
@@ -149,3 +152,17 @@ Promise.resolve(this.gridster.$options.draggable.stop(this.gridsterItem.item, this.gridsterItem, e)) | ||
if (this.positionXBackup !== this.gridsterItem.$item.x || this.positionYBackup !== this.gridsterItem.$item.y) { | ||
this.push.pushItems(); | ||
var lastPosition = this.path[this.path.length - 1]; | ||
var direction = void 0; | ||
if (lastPosition.x < this.gridsterItem.$item.x) { | ||
direction = this.push.fromWest; | ||
} | ||
else if (lastPosition.x > this.gridsterItem.$item.x) { | ||
direction = this.push.fromEast; | ||
} | ||
else if (lastPosition.y < this.gridsterItem.$item.y) { | ||
direction = this.push.fromNorth; | ||
} | ||
else if (lastPosition.y > this.gridsterItem.$item.y) { | ||
direction = this.push.fromSouth; | ||
} | ||
this.push.pushItems(direction); | ||
this.swap.swapItems(); | ||
@@ -157,2 +174,3 @@ if (this.gridster.checkCollision(this.gridsterItem)) { | ||
else { | ||
this.path.push({ x: this.gridsterItem.$item.x, y: this.gridsterItem.$item.y }); | ||
this.gridster.previewStyle(); | ||
@@ -159,0 +177,0 @@ } |
@@ -5,17 +5,23 @@ import { GridsterItemComponent } from './gridsterItem.component'; | ||
private pushedItems; | ||
private pushedItemsPath; | ||
private gridsterItem; | ||
private gridster; | ||
private tryPattern; | ||
fromSouth: string; | ||
fromNorth: string; | ||
fromEast: string; | ||
fromWest: string; | ||
constructor(gridsterItem: GridsterItemComponent, gridster: GridsterComponent); | ||
pushItems(): void; | ||
pushItems(direction: any): void; | ||
restoreItems(): void; | ||
setPushedItems(): void; | ||
private push(gridsterItem, pushedBy); | ||
private trySouth(gridsterItemCollide, gridsterItem, pushedBy); | ||
private tryNorth(gridsterItemCollide, gridsterItem, pushedBy); | ||
private tryEast(gridsterItemCollide, gridsterItem, pushedBy); | ||
private tryWest(gridsterItemCollide, gridsterItem, pushedBy); | ||
private push(gridsterItem, direction, pushedBy); | ||
private trySouth(gridsterItemCollide, gridsterItem, direction, pushedBy); | ||
private tryNorth(gridsterItemCollide, gridsterItem, direction, pushedBy); | ||
private tryEast(gridsterItemCollide, gridsterItem, direction, pushedBy); | ||
private tryWest(gridsterItemCollide, gridsterItem, direction, pushedBy); | ||
private addToPushed(gridsterItem); | ||
private removeFromPushed(gridsterItem); | ||
private removeFromPushed(i); | ||
private checkPushBack(); | ||
private checkPushedItem(pushedItem); | ||
private checkPushedItem(pushedItem, i); | ||
} |
@@ -9,9 +9,20 @@ "use strict"; | ||
this.pushedItems = []; | ||
this.pushedItemsPath = []; | ||
this.gridsterItem = gridsterItem; | ||
this.gridster = gridster; | ||
this.tryPattern = { | ||
fromEast: [this.tryWest, this.trySouth, this.tryNorth], | ||
fromWest: [this.tryEast, this.trySouth, this.tryNorth], | ||
fromNorth: [this.trySouth, this.tryEast, this.tryWest], | ||
fromSouth: [this.tryNorth, this.tryEast, this.tryWest], | ||
}; | ||
this.fromSouth = 'fromSouth'; | ||
this.fromNorth = 'fromNorth'; | ||
this.fromEast = 'fromEast'; | ||
this.fromWest = 'fromWest'; | ||
} | ||
GridsterPush.prototype.pushItems = function () { | ||
GridsterPush.prototype.pushItems = function (direction) { | ||
if (this.gridster.$options.pushItems) { | ||
this.push(this.gridsterItem, direction, this.gridsterItem); | ||
this.checkPushBack(); | ||
this.push(this.gridsterItem, this.gridsterItem); | ||
} | ||
@@ -30,2 +41,3 @@ }; | ||
this.pushedItems = undefined; | ||
this.pushedItemsPath = undefined; | ||
}; | ||
@@ -41,41 +53,18 @@ GridsterPush.prototype.setPushedItems = function () { | ||
this.pushedItems = undefined; | ||
this.pushedItemsPath = undefined; | ||
}; | ||
GridsterPush.prototype.push = function (gridsterItem, pushedBy) { | ||
GridsterPush.prototype.push = function (gridsterItem, direction, pushedBy) { | ||
var gridsterItemCollision = this.gridster.checkCollision(gridsterItem, pushedBy); | ||
if (gridsterItemCollision && gridsterItemCollision !== true) { | ||
if (gridsterItemCollision && gridsterItemCollision !== true && | ||
gridsterItemCollision !== this.gridsterItem) { | ||
var gridsterItemCollide = gridsterItemCollision; | ||
if (gridsterItem.item.y < gridsterItem.$item.y || | ||
(gridsterItem.item.y === gridsterItem.$item.y && gridsterItem.item.rows < gridsterItem.$item.rows)) { | ||
if (this.trySouth(gridsterItemCollide, gridsterItem, pushedBy)) { | ||
return true; | ||
} | ||
else if (this.tryEast(gridsterItemCollide, gridsterItem, pushedBy)) { | ||
return true; | ||
} | ||
if (this.tryPattern[direction][0].call(this, gridsterItemCollide, gridsterItem, direction, pushedBy)) { | ||
return true; | ||
} | ||
else if (gridsterItem.item.y > gridsterItem.$item.y) { | ||
if (this.tryNorth(gridsterItemCollide, gridsterItem, pushedBy)) { | ||
return true; | ||
} | ||
else if (this.tryEast(gridsterItemCollide, gridsterItem, pushedBy)) { | ||
return true; | ||
} | ||
else if (this.tryPattern[direction][1].call(this, gridsterItemCollide, gridsterItem, direction, pushedBy)) { | ||
return true; | ||
} | ||
if (gridsterItem.item.x < gridsterItem.$item.x || | ||
(gridsterItem.item.x === gridsterItem.$item.x && gridsterItem.item.cols < gridsterItem.$item.cols)) { | ||
if (this.tryEast(gridsterItemCollide, gridsterItem, pushedBy)) { | ||
return true; | ||
} | ||
else if (this.trySouth(gridsterItemCollide, gridsterItem, pushedBy)) { | ||
return true; | ||
} | ||
else if (this.tryPattern[direction][2].call(this, gridsterItemCollide, gridsterItem, direction, pushedBy)) { | ||
return true; | ||
} | ||
else if (gridsterItem.item.x > gridsterItem.$item.x) { | ||
if (this.tryWest(gridsterItemCollide, gridsterItem, pushedBy)) { | ||
return true; | ||
} | ||
else if (this.trySouth(gridsterItemCollide, gridsterItem, pushedBy)) { | ||
return true; | ||
} | ||
} | ||
} | ||
@@ -86,7 +75,7 @@ else if (gridsterItemCollision === undefined) { | ||
}; | ||
GridsterPush.prototype.trySouth = function (gridsterItemCollide, gridsterItem, pushedBy) { | ||
GridsterPush.prototype.trySouth = function (gridsterItemCollide, gridsterItem, direction, pushedBy) { | ||
gridsterItemCollide.$item.y += 1; | ||
if (this.push(gridsterItemCollide, gridsterItem)) { | ||
if (this.push(gridsterItemCollide, this.fromNorth, gridsterItem)) { | ||
gridsterItemCollide.setSize(true); | ||
this.push(gridsterItem, pushedBy); | ||
this.push(gridsterItem, direction, pushedBy); | ||
this.addToPushed(gridsterItemCollide); | ||
@@ -99,7 +88,7 @@ return true; | ||
}; | ||
GridsterPush.prototype.tryNorth = function (gridsterItemCollide, gridsterItem, pushedBy) { | ||
GridsterPush.prototype.tryNorth = function (gridsterItemCollide, gridsterItem, direction, pushedBy) { | ||
gridsterItemCollide.$item.y -= 1; | ||
if (this.push(gridsterItemCollide, gridsterItem)) { | ||
if (this.push(gridsterItemCollide, this.fromSouth, gridsterItem)) { | ||
gridsterItemCollide.setSize(true); | ||
this.push(gridsterItem, pushedBy); | ||
this.push(gridsterItem, direction, pushedBy); | ||
this.addToPushed(gridsterItemCollide); | ||
@@ -112,7 +101,7 @@ return true; | ||
}; | ||
GridsterPush.prototype.tryEast = function (gridsterItemCollide, gridsterItem, pushedBy) { | ||
GridsterPush.prototype.tryEast = function (gridsterItemCollide, gridsterItem, direction, pushedBy) { | ||
gridsterItemCollide.$item.x += 1; | ||
if (this.push(gridsterItemCollide, gridsterItem)) { | ||
if (this.push(gridsterItemCollide, this.fromWest, gridsterItem)) { | ||
gridsterItemCollide.setSize(true); | ||
this.push(gridsterItem, pushedBy); | ||
this.push(gridsterItem, direction, pushedBy); | ||
this.addToPushed(gridsterItemCollide); | ||
@@ -125,7 +114,7 @@ return true; | ||
}; | ||
GridsterPush.prototype.tryWest = function (gridsterItemCollide, gridsterItem, pushedBy) { | ||
GridsterPush.prototype.tryWest = function (gridsterItemCollide, gridsterItem, direction, pushedBy) { | ||
gridsterItemCollide.$item.x -= 1; | ||
if (this.push(gridsterItemCollide, gridsterItem)) { | ||
if (this.push(gridsterItemCollide, this.fromEast, gridsterItem)) { | ||
gridsterItemCollide.setSize(true); | ||
this.push(gridsterItem, pushedBy); | ||
this.push(gridsterItem, direction, pushedBy); | ||
this.addToPushed(gridsterItemCollide); | ||
@@ -141,8 +130,13 @@ return true; | ||
this.pushedItems.push(gridsterItem); | ||
this.pushedItemsPath.push([{ x: gridsterItem.item.x, y: gridsterItem.item.y }, { x: gridsterItem.$item.x, y: gridsterItem.$item.y }]); | ||
} | ||
else { | ||
var i = this.pushedItems.indexOf(gridsterItem); | ||
this.pushedItemsPath[i].push({ x: gridsterItem.$item.x, y: gridsterItem.$item.y }); | ||
} | ||
}; | ||
GridsterPush.prototype.removeFromPushed = function (gridsterItem) { | ||
var i = this.pushedItems.indexOf(gridsterItem); | ||
GridsterPush.prototype.removeFromPushed = function (i) { | ||
if (i > -1) { | ||
this.pushedItems.splice(i, 1); | ||
this.pushedItemsPath.splice(i, 1); | ||
} | ||
@@ -153,49 +147,25 @@ }; | ||
for (; i > -1; i--) { | ||
this.checkPushedItem(this.pushedItems[i]); | ||
this.checkPushedItem(this.pushedItems[i], i); | ||
} | ||
}; | ||
GridsterPush.prototype.checkPushedItem = function (pushedItem) { | ||
if (pushedItem.$item.y > pushedItem.item.y) { | ||
pushedItem.$item.y -= 1; | ||
if (this.gridster.findItemWithItem(pushedItem)) { | ||
pushedItem.$item.y += 1; | ||
} | ||
else { | ||
pushedItem.setSize(true); | ||
this.checkPushedItem(pushedItem); | ||
} | ||
GridsterPush.prototype.checkPushedItem = function (pushedItem, i) { | ||
var path = this.pushedItemsPath[i]; | ||
var lastPosition = path[path.length - 2]; | ||
pushedItem.$item.x = lastPosition.x; | ||
pushedItem.$item.y = lastPosition.y; | ||
if (this.gridster.findItemWithItem(pushedItem)) { | ||
lastPosition = path[path.length - 1]; | ||
pushedItem.$item.x = lastPosition.x; | ||
pushedItem.$item.y = lastPosition.y; | ||
} | ||
else if (pushedItem.$item.y < pushedItem.item.y) { | ||
pushedItem.$item.y += 1; | ||
if (this.gridster.findItemWithItem(pushedItem)) { | ||
pushedItem.$item.y -= 1; | ||
else { | ||
pushedItem.setSize(true); | ||
path.pop(); | ||
if (path.length < 2) { | ||
this.removeFromPushed(i); | ||
} | ||
else { | ||
pushedItem.setSize(true); | ||
this.checkPushedItem(pushedItem); | ||
this.checkPushedItem(pushedItem, i); | ||
} | ||
} | ||
if (pushedItem.$item.x > pushedItem.item.x) { | ||
pushedItem.$item.x -= 1; | ||
if (this.gridster.findItemWithItem(pushedItem)) { | ||
pushedItem.$item.x += 1; | ||
} | ||
else { | ||
pushedItem.setSize(true); | ||
this.checkPushedItem(pushedItem); | ||
} | ||
} | ||
else if (pushedItem.$item.x < pushedItem.item.x) { | ||
pushedItem.$item.x += 1; | ||
if (this.gridster.findItemWithItem(pushedItem)) { | ||
pushedItem.$item.x -= 1; | ||
} | ||
else { | ||
pushedItem.setSize(true); | ||
this.checkPushedItem(pushedItem); | ||
} | ||
} | ||
if (pushedItem.$item.x === pushedItem.item.x && pushedItem.$item.y === pushedItem.item.y) { | ||
this.removeFromPushed(pushedItem); | ||
} | ||
}; | ||
@@ -202,0 +172,0 @@ return GridsterPush; |
@@ -162,3 +162,3 @@ "use strict"; | ||
this.gridsterItem.$item.y = this.newPosition; | ||
this.push.pushItems(); | ||
this.push.pushItems(this.push.fromSouth); | ||
if (this.gridster.checkCollision(this.gridsterItem)) { | ||
@@ -192,3 +192,3 @@ this.gridsterItem.$item.y = this.itemBackup[1]; | ||
this.gridsterItem.$item.x = this.newPosition; | ||
this.push.pushItems(); | ||
this.push.pushItems(this.push.fromEast); | ||
if (this.gridster.checkCollision(this.gridsterItem)) { | ||
@@ -219,3 +219,3 @@ this.gridsterItem.$item.x = this.itemBackup[0]; | ||
this.gridsterItem.$item.rows = this.newPosition - this.gridsterItem.$item.y; | ||
this.push.pushItems(); | ||
this.push.pushItems(this.push.fromNorth); | ||
if (this.gridster.checkCollision(this.gridsterItem)) { | ||
@@ -243,3 +243,3 @@ this.gridsterItem.$item.rows = this.itemBackup[3]; | ||
this.gridsterItem.$item.cols = this.newPosition - this.gridsterItem.$item.x; | ||
this.push.pushItems(); | ||
this.push.pushItems(this.push.fromWest); | ||
if (this.gridsterItem.$item.cols < 1 || this.gridster.checkCollision(this.gridsterItem)) { | ||
@@ -246,0 +246,0 @@ this.gridsterItem.$item.cols = this.itemBackup[2]; |
{ | ||
"name": "angular-gridster2", | ||
"version": "2.10.4", | ||
"version": "2.10.5", | ||
"license": "MIT", | ||
@@ -50,3 +50,3 @@ "main": "dist/index.js", | ||
"@angular/animations": "4.1.3", | ||
"@angular/cli": "1.1.0", | ||
"@angular/cli": "1.1.1", | ||
"@angular/common": "4.1.3", | ||
@@ -64,4 +64,4 @@ "@angular/compiler": "4.1.3", | ||
"@angular/router": "4.1.3", | ||
"@types/jasmine": "2.5.48", | ||
"@types/node": "7.0.23", | ||
"@types/jasmine": "2.5.51", | ||
"@types/node": "7.0.29", | ||
"codelyzer": "3.0.1", | ||
@@ -73,3 +73,3 @@ "core-js": "2.4.1", | ||
"hammerjs": "2.0.8", | ||
"jasmine-core": "2.6.2", | ||
"jasmine-core": "2.6.3", | ||
"jasmine-spec-reporter": "4.1.0", | ||
@@ -86,8 +86,8 @@ "karma": "1.7.0", | ||
"ts-helpers": "1.1.2", | ||
"ts-node": "3.0.4", | ||
"ts-node": "3.0.6", | ||
"tslib": "1.7.1", | ||
"tslint": "5.4.1", | ||
"tslint": "5.4.3", | ||
"typescript": "2.3.4", | ||
"zone.js": "0.8.11" | ||
"zone.js": "0.8.12" | ||
} | ||
} |
@@ -204,3 +204,6 @@ angular-gridster2 | ||
### Load dynamic components inside the `gridster-item` | ||
You can load dynamic components in Angular4+ with the help of [`ng-dynamic-component` library](https://www.npmjs.com/package/ng-dynamic-component) | ||
### Interact with content without dragging | ||
@@ -207,0 +210,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
202897
251
1940