From dcdd162ed0bcecbed1c8286fcf21775569842e15 Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Thu, 1 Sep 2016 13:15:22 +0100 Subject: [PATCH 1/2] #657 Enforce single-click navigation for mobile browsers --- .../src/components/document-list.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ng2-components/ng2-alfresco-documentlist/src/components/document-list.ts b/ng2-components/ng2-alfresco-documentlist/src/components/document-list.ts index 54394d654c..8df0b3076e 100644 --- a/ng2-components/ng2-alfresco-documentlist/src/components/document-list.ts +++ b/ng2-components/ng2-alfresco-documentlist/src/components/document-list.ts @@ -77,7 +77,7 @@ export class DocumentList implements OnInit, AfterViewInit, AfterViewChecked, Af navigate: boolean = true; @Input() - navigationMode: string = 'dblclick'; // click|dblclick + navigationMode: string = DocumentList.DOUBLE_CLICK_NAVIGATION; // click|dblclick @Input() thumbnails: boolean = false; @@ -184,6 +184,11 @@ export class DocumentList implements OnInit, AfterViewInit, AfterViewChecked, Af this.data.thumbnails = this.thumbnails; this.data.maxItems = this.pageSize; this.contextActionHandler.subscribe(val => this.contextActionCallback(val)); + + // Automatically enforce single-click navigation for mobile browsers + if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) { + this.navigationMode = DocumentList.SINGLE_CLICK_NAVIGATION; + } } ngAfterContentInit() { From e3f97a8eef21dd572cbe38d2737b23ed1b5f8a00 Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Thu, 1 Sep 2016 13:51:55 +0100 Subject: [PATCH 2/2] #657 unit tests --- .../src/components/document-list.spec.ts | 36 ++++--------------- .../src/components/document-list.ts | 6 +++- 2 files changed, 11 insertions(+), 31 deletions(-) diff --git a/ng2-components/ng2-alfresco-documentlist/src/components/document-list.spec.ts b/ng2-components/ng2-alfresco-documentlist/src/components/document-list.spec.ts index b4ed50bfa5..9dc72dc090 100644 --- a/ng2-components/ng2-alfresco-documentlist/src/components/document-list.spec.ts +++ b/ng2-components/ng2-alfresco-documentlist/src/components/document-list.spec.ts @@ -492,35 +492,11 @@ describe('DocumentList', () => { expect(documentList.displayFolderContent).not.toHaveBeenCalled(); }); - // TODO: move to data adapter - /* - it('should sort by dates up to ms', () => { - let file1 = new FileNode(); - file1.entry['dateProp'] = new Date(2016, 6, 30, 13, 14, 1); - - let file2 = new FileNode(); - file2.entry['dateProp'] = new Date(2016, 6, 30, 13, 14, 2); - - let page = new PageNode([file1, file2]); - - // desc - documentList.sort(page, new ColumnSortingModel({ - key: 'dateProp', - direction: 'desc' - })); - - expect(page.list.entries[0]).toBe(file2); - expect(page.list.entries[1]).toBe(file1); - - // asc - documentList.sort(page, new ColumnSortingModel({ - key: 'dateProp', - direction: 'asc' - })); - - expect(page.list.entries[0]).toBe(file1); - expect(page.list.entries[1]).toBe(file2); + it('should enforce single-click on mobile browser', () => { + spyOn(documentList, 'isMobile').and.returnValue(true); + documentList.navigationMode = DocumentList.DOUBLE_CLICK_NAVIGATION; + documentList.ngOnInit(); + expect(documentList.isMobile).toHaveBeenCalled(); + expect(documentList.navigationMode).toBe(DocumentList.SINGLE_CLICK_NAVIGATION); }); - */ - }); diff --git a/ng2-components/ng2-alfresco-documentlist/src/components/document-list.ts b/ng2-components/ng2-alfresco-documentlist/src/components/document-list.ts index 8df0b3076e..295e84879d 100644 --- a/ng2-components/ng2-alfresco-documentlist/src/components/document-list.ts +++ b/ng2-components/ng2-alfresco-documentlist/src/components/document-list.ts @@ -186,7 +186,7 @@ export class DocumentList implements OnInit, AfterViewInit, AfterViewChecked, Af this.contextActionHandler.subscribe(val => this.contextActionCallback(val)); // Automatically enforce single-click navigation for mobile browsers - if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) { + if (this.isMobile()) { this.navigationMode = DocumentList.SINGLE_CLICK_NAVIGATION; } } @@ -211,6 +211,10 @@ export class DocumentList implements OnInit, AfterViewInit, AfterViewChecked, Af if (componentHandler) { componentHandler.upgradeAllRegistered(); } + } + + isMobile(): boolean { + return !!/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent); }