Skip to content

Commit 6e56e37

Browse files
author
Shlomi Assaf (shlassaf)
committed
fix: demo fixes
1 parent 8b1258c commit 6e56e37

File tree

10 files changed

+81
-27
lines changed

10 files changed

+81
-27
lines changed

src/demo/app/app.component.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@ import { AppState } from './app.service';
88
<div fxLayout="column" fxFill>
99
<div fxFlex="nogrow">
1010
<md-toolbar color="primary">
11-
<span>{{ name }}</span>
11+
<a md-button [routerLink]=" ['./home'] ">{{ name }}</a>
1212
<span class="fill"></span>
13-
<button md-button [routerLink]=" ['./home'] ">
14-
Home
15-
</button>
1613
<button md-button [routerLink]=" ['./game'] ">
1714
Game
1815
</button>

src/demo/app/game/game.component.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<ng-template #playerGui let-ctx>
22
<div>
3-
<md-button-toggle-group [(ngModel)]="ctx.rawtype" (change)="onPlayerTypeChange($event.value, ctx)">
3+
<md-button-toggle-group [(ngModel)]="ctx.rawtype"
4+
[vertical]="!board.isPortrait"
5+
(change)="onPlayerTypeChange($event.value, ctx)">
46
<md-button-toggle color="primary" value="HUMAN">
57
<md-icon>face</md-icon>
68
</md-button-toggle>
@@ -51,7 +53,7 @@
5153
<div fxFlex style="overflow-y: hidden; position: relative">
5254
<div class="absolute-max">
5355
<div class="board-container">
54-
<chess-board class="svg-chess-board" #board (onBoardResize)="onBoardResize($event)">
56+
<chess-board #board (onBoardResize)="onBoardResize($event)" minLandscapeMargin="80">
5557
<div fxFlexFill fxLayout="column" fxLayoutAlign="start end" class="board-content-left">
5658
<ng-container *ngTemplateOutlet="playerGui; context: {'$implicit': black}"></ng-container>
5759
</div>
@@ -69,5 +71,6 @@
6971
</div>
7072
<div style="min-height: 25px;">
7173
<p *ngIf="!workerSupported" style="text-align: center; margin-top: 0">Your broswer does not support web workers, expect UI lags while computer thinks</p>
74+
<p *ngIf="isFF" style="text-align: center; margin-top: 0">Not playing well with FireFox, please switch</p>
7275
</div>
7376
</div>

src/demo/app/game/game.component.scss

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,39 @@
1+
12
.game-toolbar {
2-
margin: 10px 0;
3+
margin: 10px;
4+
transition: all 250ms linear;
35
}
46

57
.game-toolbar > * {
68
margin: 5px;
79
}
810

9-
.ai-select-container {
10-
padding-top: 22px;
11-
}
1211

1312
.board-content-left, .board-content-right {
1413
padding: 0 15px;
1514
}
1615

16+
.ai-select-container {
17+
margin: 35px 0 15px 0;
18+
width: 80px;
19+
}
20+
21+
@media (min-width: 480px) {
22+
.game-toolbar {
23+
margin-top: -25px;
24+
25+
.mat-mini-fab[disabled] {
26+
background-color: rgb(214, 220 , 220);
27+
}
28+
}
29+
}
30+
1731
@media (orientation: landscape) {
1832
.board-container {
1933
height: 100%;
2034
max-height: 100%;
2135
}
22-
.svg-chess-board {
36+
chess-board {
2337
margin: auto;
2438
height: 100%;
2539
}
@@ -31,7 +45,7 @@
3145
height: 100%;
3246
max-width: 100%;
3347
}
34-
.svg-chess-board {
48+
chess-board {
3549
width: 100%;
3650
height: 100%;
3751
}

src/demo/app/game/game.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ export class GameComponent implements AfterViewInit, OnDestroy {
5555

5656
boardRect: BoardSizeChangeEvent = { height: 0, width: 0, clientHeight: 0, clientWidth: 0, xOffset: 0, yOffset: 0};
5757

58+
isFF = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
59+
5860
constructor(private dialog: MdDialog) {}
5961

6062
ngAfterViewInit() {

src/demo/assets/manifest.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "App",
3+
"display": "fullscreen",
34
"icons": [
45
{
56
"src": "/assets/icon/android-icon-36x36.png",

src/demo/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
<head>
44
<meta charset="utf-8">
55
<meta http-equiv="x-ua-compatible" content="ie=edge">
6-
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
7+
78
<title><%= htmlWebpackPlugin.options.title %></title>
89
<meta name="description" content="<%= htmlWebpackPlugin.options.title %>">
910
<!-- base url -->

src/demo/styles/styles.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ button.active:hover{
3333
flex: 1;
3434
}
3535

36+
// workaround, see https://github.com/angular/material2/pull/6684
37+
game .ai-select-container {
38+
.mat-select-trigger {
39+
min-width: inherit;
40+
}
41+
}
42+
3643
main {
3744
display: flex;
3845
flex-direction: column;

src/ngx-chess/plugins/dom-svg-board/src/svg-chess-board/svg-chess-board.component.ts

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
EventEmitter,
88
ViewChild,
99
ViewChildren,
10+
Input,
1011
Output,
1112
Optional,
1213
QueryList,
@@ -90,13 +91,16 @@ export class SVGChessBoard extends ChessBoard implements AfterViewInit, AfterCon
9091
/** @internal */
9192
lastSizeEvent: BoardSizeChangeEvent;
9293

94+
@Input() minLandscapeMargin: number;
95+
9396
get isPortrait(): boolean {
9497
return this._isPortrait;
9598
}
9699

97100
private isDisabled: boolean;
98101
private rxWaste: Subscription[] = [];
99102
private onWindowResize: any;
103+
private onDocumentTouchMove: (event: TouchEvent) => any;
100104
private _isPortrait: boolean;
101105

102106
@ViewChild('board') private boardElRef: ElementRef;
@@ -114,11 +118,28 @@ export class SVGChessBoard extends ChessBoard implements AfterViewInit, AfterCon
114118
Object.defineProperty(this, 'viewBox', {value: `0 0 ${this.width} ${this.height}`});
115119
this.blockSize = this.height / engine.rowCount;
116120

121+
if (document) {
122+
// prevent scrolling when interacting with board.
123+
this.onDocumentTouchMove = (event: TouchEvent): any => {
124+
if ( (event.target as any).ownerSVGElement === this.boardElRef.nativeElement) {
125+
event.preventDefault();
126+
}
127+
return;
128+
};
129+
document.addEventListener('touchmove', this.onDocumentTouchMove, <any>{ passive: false } );
130+
}
131+
117132
if (window) {
118133
this.onWindowResize = (event$: any) => {
119134
const oldIsPortrait = this._isPortrait;
120-
this._isPortrait = window.innerHeight > window.innerWidth;
121135
this.updateLastSizeEvent();
136+
this._isPortrait = window.innerHeight > window.innerWidth;
137+
138+
// this._isPortrait = this.lastSizeEvent.yOffset > 0;
139+
// if (!this._isPortrait && this.minLandscapeMargin && this.minLandscapeMargin > 0 && this.minLandscapeMargin > this.lastSizeEvent.xOffset) {
140+
// this._isPortrait = false;
141+
// }
142+
122143
this.onBoardResize.emit(this.lastSizeEvent);
123144

124145
// on mobile, moving to landscape from portrait require another calc/redraw
@@ -189,6 +210,9 @@ export class SVGChessBoard extends ChessBoard implements AfterViewInit, AfterCon
189210

190211
ngOnDestroy() {
191212
this.clearSubscriptions();
213+
if (this.onDocumentTouchMove) {
214+
document.removeEventListener("touchmove", this.onDocumentTouchMove);
215+
}
192216
if (this.onWindowResize) {
193217
window.removeEventListener("resize", this.onWindowResize);
194218
}
@@ -253,11 +277,11 @@ export class SVGChessBoard extends ChessBoard implements AfterViewInit, AfterCon
253277
private registerDragAndDrop() {
254278
let svgElement: SVGSVGElement = this.boardElRef.nativeElement;
255279

256-
let mousedown = Observable.fromEvent(svgElement, 'mousedown');
257-
let touchstart = Observable.fromEvent(svgElement, 'touchstart');
280+
let mousedown = Observable.fromEvent(svgElement, 'mousedown', { passive: false });
281+
let touchstart = Observable.fromEvent(svgElement, 'touchstart', { passive: false });
258282

259-
let mousemove = Observable.fromEvent(svgElement, 'mousemove');
260-
let touchmove = Observable.fromEvent(svgElement, 'touchmove');
283+
let mousemove = Observable.fromEvent(svgElement, 'mousemove', { passive: false });
284+
let touchmove = Observable.fromEvent(svgElement, 'touchmove', { passive: false });
261285
// TODO: maybe catch mouseup on root component, get root via appRef boot event.
262286
let mouseup = Observable.fromEvent(document, 'mouseup'); // catch drops everywhere
263287
let touchend = Observable.fromEvent(document, 'touchend'); // catch drops everywhere
@@ -308,6 +332,7 @@ export class SVGChessBoard extends ChessBoard implements AfterViewInit, AfterCon
308332
});
309333

310334
let touchdrag = touchstart.mergeMap((md: TouchEvent) => {
335+
this.updateLastSizeEvent();
311336
if (this.isDisabled) return []; // only track when piece is clicked, nothing else.
312337
if (md.touches.length < 1) return [];
313338

@@ -331,7 +356,6 @@ export class SVGChessBoard extends ChessBoard implements AfterViewInit, AfterCon
331356
// only drag when it's the piece turn.
332357
if (this.dragPiece.piece.color !== this.engine.turn()) return [];
333358

334-
335359
// since SVG is responsive 1 mouse px != 1 svg px
336360
// we get SVG px and we need a conversion ratio, from SVG to mouse px:
337361
const viewPortRatioX = this.ratioX,
@@ -481,6 +505,7 @@ export class SVGChessBoard extends ChessBoard implements AfterViewInit, AfterCon
481505
});
482506
}
483507
else {
508+
this.dragPiece.reset(150);
484509
this.endDragAndDrop();
485510
}
486511
}

src/ngx-chess/plugins/dom-svg-board/src/svg-chess-board/svg-chess-board.styles.scss

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,34 @@
1-
:host {
2-
display: block;
1+
.no-user-select {
32
-webkit-user-select: none;
43
-moz-user-select: none;
54
-ms-user-select: none;
65
user-select: none;
76
}
87

9-
.xyz {
8+
:host {
9+
@extend .no-user-select;
10+
display: block;
11+
}
12+
13+
.svg-chess-board {
1014
position: relative;
1115
display: block;
12-
-webkit-user-select: none;
13-
-moz-user-select: none;
14-
-ms-user-select: none;
15-
user-select: none;
1616
overflow-y: hidden;
1717
margin: auto;
1818
height: 100%;
19+
width: 100%;
1920
}
2021

2122
.chess-board {
2223
max-height: 100%;
2324
max-width: 100%;
25+
-webkit-tap-highlight-color: rgba(0,0,0,0);
2426
}
2527

2628
@media (orientation: portrait) {
2729
.chess-board {
2830
height: 100%;
31+
width: 100%;
2932
}
3033
}
3134

src/ngx-chess/plugins/dom-svg-board/src/svg-chess-board/svg-chess-board.template.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
<div class="xyz svg-chess-board">
1+
<div class="svg-chess-board no-user-select">
22
<svg [attr.viewBox]="viewBox"
33
class="chess-board"
4+
[class.portrait]="isPortrait"
45
preserveAspectRatio="xMidYMid meet" #board>
56

67
<!-- Drop shadow for a piece -->

0 commit comments

Comments
 (0)