Skip to content
This repository has been archived by the owner on Mar 5, 2024. It is now read-only.

Commit

Permalink
Remove debug logs. Convert to using absolute positioning instead of t…
Browse files Browse the repository at this point in the history
…ransform #241. Add try/catch to findHandle method #225. Add triggerResize method #239
  • Loading branch information
BTMorton committed Jun 25, 2017
1 parent e8fb109 commit 46dfc7e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
9 changes: 4 additions & 5 deletions src/directives/NgGrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,10 @@ export class NgGrid implements OnInit, DoCheck, OnDestroy {
this._cascadeGrid(null, null);
}

public triggerResize(): void {
this.resizeEventHandler(null);
}

public resizeEventHandler(e: any): void {
this._calculateColWidth();
this._calculateRowHeight();
Expand Down Expand Up @@ -1060,10 +1064,6 @@ export class NgGrid implements OnInit, DoCheck, OnDestroy {
if (this._itemGrid[pos.row + j] == null) this._itemGrid[pos.row + j] = {};

for (let i: number = 0; i < dims.x; i++) {
if (this._itemGrid[pos.row + j][pos.col + i] != null) {
console.error("ITEM COLLISION", this._hasGridCollision(pos, dims));
}

this._itemGrid[pos.row + j][pos.col + i] = item;
}
}
Expand All @@ -1084,7 +1084,6 @@ export class NgGrid implements OnInit, DoCheck, OnDestroy {
const withinCol = <any>x < (item.col + item.sizex) && <any>x >= item.col;

if (this._items.indexOf(this._itemGrid[y][x]) < 0 || !withinRow || !withinCol) {
console.error("LEFTOVER ITEM");
delete this._itemGrid[y][x];
}
}
Expand Down
36 changes: 22 additions & 14 deletions src/directives/NgGridItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,15 @@ export class NgGridItem implements OnInit, OnDestroy {
}

public findHandle(handleSelector: string, startElement: HTMLElement): boolean {
let targetElem: any = startElement;
try {
let targetElem: any = startElement;

while (targetElem && targetElem != this._ngEl.nativeElement) {
if (this.elementMatches(targetElem, handleSelector)) return true;
while (targetElem && targetElem != this._ngEl.nativeElement) {
if (this.elementMatches(targetElem, handleSelector)) return true;

targetElem = targetElem.parentElement;
}
targetElem = targetElem.parentElement;
}
} catch (err) {}

return false;
}
Expand Down Expand Up @@ -374,13 +376,16 @@ export class NgGridItem implements OnInit, OnDestroy {
case 'up':
case 'left':
default:
this._renderer.setElementStyle(this._ngEl.nativeElement, 'transform', 'translate(' + x + 'px, ' + y + 'px)');
this._renderer.setElementStyle(this._ngEl.nativeElement, 'left', x + 'px');
this._renderer.setElementStyle(this._ngEl.nativeElement, 'top', y + 'px');
break;
case 'right':
this._renderer.setElementStyle(this._ngEl.nativeElement, 'transform', 'translate(' + -x + 'px, ' + y + 'px)');
this._renderer.setElementStyle(this._ngEl.nativeElement, 'right', x + 'px');
this._renderer.setElementStyle(this._ngEl.nativeElement, 'top', y + 'px');
break;
case 'down':
this._renderer.setElementStyle(this._ngEl.nativeElement, 'transform', 'translate(' + x + 'px, ' + -y + 'px)');
this._renderer.setElementStyle(this._ngEl.nativeElement, 'left', x + 'px');
this._renderer.setElementStyle(this._ngEl.nativeElement, 'bottom', y + 'px');
break;
}

Expand All @@ -394,20 +399,20 @@ export class NgGridItem implements OnInit, OnDestroy {
case 'up':
case 'left':
default:
this._renderer.setElementStyle(this._ngEl.nativeElement, 'left', '0px');
this._renderer.setElementStyle(this._ngEl.nativeElement, 'top', '0px');
this._renderer.setElementStyle(this._ngEl.nativeElement, 'left', this._elemLeft + 'px');
this._renderer.setElementStyle(this._ngEl.nativeElement, 'top', this._elemTop + 'px');
this._renderer.setElementStyle(this._ngEl.nativeElement, 'right', null);
this._renderer.setElementStyle(this._ngEl.nativeElement, 'bottom', null);
break;
case 'right':
this._renderer.setElementStyle(this._ngEl.nativeElement, 'right', '0px');
this._renderer.setElementStyle(this._ngEl.nativeElement, 'top', '0px');
this._renderer.setElementStyle(this._ngEl.nativeElement, 'right', this._elemLeft + 'px');
this._renderer.setElementStyle(this._ngEl.nativeElement, 'top', this._elemTop + 'px');
this._renderer.setElementStyle(this._ngEl.nativeElement, 'left', null);
this._renderer.setElementStyle(this._ngEl.nativeElement, 'bottom', null);
break;
case 'down':
this._renderer.setElementStyle(this._ngEl.nativeElement, 'left', '0px');
this._renderer.setElementStyle(this._ngEl.nativeElement, 'bottom', '0px');
this._renderer.setElementStyle(this._ngEl.nativeElement, 'left', this._elemLeft + 'px');
this._renderer.setElementStyle(this._ngEl.nativeElement, 'bottom', this._elemTop + 'px');
this._renderer.setElementStyle(this._ngEl.nativeElement, 'right', null);
this._renderer.setElementStyle(this._ngEl.nativeElement, 'top', null);
break;
Expand Down Expand Up @@ -460,12 +465,15 @@ export class NgGridItem implements OnInit, OnDestroy {

// Private methods
private elementMatches(element: any, selector: string): boolean {
if (!element) return false;
if (element.matches) return element.matches(selector);
if (element.oMatchesSelector) return element.oMatchesSelector(selector);
if (element.msMatchesSelector) return element.msMatchesSelector(selector);
if (element.mozMatchesSelector) return element.mozMatchesSelector(selector);
if (element.webkitMatchesSelector) return element.webkitMatchesSelector(selector);

if (!element.document || !element.ownerDocument) return false;

const matches: any = (element.document || element.ownerDocument).querySelectorAll(selector);
let i: number = matches.length;
while (--i >= 0 && matches.item(i) !== element) { }
Expand Down

0 comments on commit 46dfc7e

Please sign in to comment.