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

Commit 1d9137f

Browse files
committed
Fix Firefox support
1 parent 519aa51 commit 1d9137f

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

src/NgGrid.ts

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import {Component, View, Directive, ElementRef, Renderer, EventEmitter, DynamicC
66
host: {
77
'(^mousedown)': '_onMouseDown($event)',
88
'(^mousemove)': '_onMouseMove($event)',
9-
// '(^document:mousemove)': '_onMouseMove($event)',
109
'(^mouseup)': '_onMouseUp($event)',
1110
'(^touchstart)': '_onMouseDown($event)',
1211
'(^touchmove)': '_onMouseMove($event)',
1312
'(^touchend)': '_onMouseUp($event)',
14-
'(window:resize)': '_onResize($event)'
13+
'(window:resize)': '_onResize($event)',
14+
'(document:^mousemove)': '_onMouseMove($event)',
15+
'(document:^mouseup)': '_onMouseUp($event)'
1516
},
1617
lifecycle: [LifecycleEvent.onCheck],
1718
events: ['dragStart', 'drag', 'dragStop', 'resizeStart', 'resize', 'resizeStop']
@@ -203,11 +204,10 @@ export class NgGrid {
203204
}
204205

205206
this._cascadeGrid();
206-
207207
}
208208

209209
if (this._autoResize && this._maxCols > 0) {
210-
var maxWidth: number = this._ngEl.nativeElement.parentElement.getBoundingClientRect().width;
210+
var maxWidth: number = this._ngEl.nativeElement.getBoundingClientRect().width;
211211

212212
var colWidth: number = Math.floor(maxWidth / this._maxCols);
213213
colWidth -= (this.marginLeft + this.marginRight);
@@ -287,7 +287,7 @@ export class NgGrid {
287287
// Private methods
288288
private _onResize(e: any): void {
289289
if (this._autoResize && this._maxCols > 0) {
290-
var maxWidth = this._ngEl.nativeElement.parentElement.getBoundingClientRect().width;
290+
var maxWidth = this._ngEl.nativeElement.getBoundingClientRect().width;
291291

292292
var colWidth = Math.floor(maxWidth / this._maxCols);
293293
colWidth -= (this.marginLeft + this.marginRight);
@@ -819,7 +819,7 @@ export class NgGrid {
819819
}
820820

821821
private _getMousePosition(e: any): {left: number, top: number} {
822-
if (e instanceof TouchEvent) {
822+
if (((<any>window).TouchEvent && e instanceof TouchEvent) || (e.touches || e.changedTouches)) {
823823
e = e.touches.length > 0 ? e.touches[0] : e.changedTouches[0];
824824
}
825825

@@ -838,9 +838,8 @@ export class NgGrid {
838838
}
839839

840840
private _getAbsoluteMousePosition(e: any): {left: number, top: number} {
841-
if (e.originalEvent && e.originalEvent.touches) {
842-
var oe = e.originalEvent;
843-
e = oe.touches.length ? oe.touches[0] : oe.changedTouches[0];
841+
if (((<any>window).TouchEvent && e instanceof TouchEvent) || (e.touches || e.changedTouches)) {
842+
e = e.touches.length > 0 ? e.touches[0] : e.changedTouches[0];
844843
}
845844

846845
return {
@@ -865,7 +864,9 @@ export class NgGrid {
865864

866865
private _createPlaceholder(pos: {col: number, row:number}, dims: {x: number, y: number}) {
867866
var me = this;
867+
console.log(pos, dims);
868868
this._loader.loadNextToLocation((<Type>NgGridPlaceholder), this._items[0].getElement()).then(componentRef => {
869+
console.log(componentRef);
869870
me._placeholderRef = componentRef;
870871
var placeholder = componentRef.instance;
871872
// me._placeholder.setGrid(me);
@@ -948,20 +949,18 @@ export class NgGridItem {
948949
public canDrag(e: any): boolean {
949950
if (this._dragHandle) {
950951
var foundHandle: boolean;
951-
var paths: Array<any> = e.path;
952-
paths.pop(); // Get rid of #document
952+
var parent = e.target.parentElement;
953953

954-
var last: any = null;
954+
var last: any = e.target;
955955

956-
for (var x in paths) {
957-
if (last !== null) {
958-
if (paths[x].querySelector(this._dragHandle) == last) {
959-
foundHandle = true;
960-
break;
961-
}
956+
while (parent) {
957+
if (parent.querySelector(this._dragHandle) == last) {
958+
foundHandle = true;
959+
break;
962960
}
963961

964-
last = paths[x];
962+
last = parent;
963+
parent = parent.parentElement;
965964
}
966965

967966
return foundHandle;

src/app.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Component, View, bootstrap, CORE_DIRECTIVES, NgStyle, FORM_DIRECTIVES, Self, Query, QueryList } from 'angular2/angular2';
1+
import {Component, View, bootstrap, CORE_DIRECTIVES, NgStyle, FORM_DIRECTIVES, Self, Query, QueryList, ViewEncapsulation } from 'angular2/angular2';
22
import {NgGrid, NgGridItem} from "NgGrid";
33
// import {NgTest} from "./NgTest";
44
// Annotation section
@@ -8,7 +8,8 @@ import {NgGrid, NgGridItem} from "NgGrid";
88
@View({
99
templateUrl: 'app.html',
1010
styleUrls: ['app.css', 'NgGrid.css'],
11-
directives: [CORE_DIRECTIVES, NgStyle, NgGrid, NgGridItem, FORM_DIRECTIVES]
11+
directives: [CORE_DIRECTIVES, NgStyle, NgGrid, NgGridItem, FORM_DIRECTIVES],
12+
encapsulation: ViewEncapsulation.NONE
1213
})
1314
// Component controller
1415
class MyAppComponent {

0 commit comments

Comments
 (0)