From ff07f4bba8c21ff03bb1e1da4a58ae7c2035d457 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Tue, 31 Jul 2018 15:02:44 +0200 Subject: [PATCH] MOBILE-2515 link: Don't open links in right pane of split view --- src/directives/format-text.ts | 5 +++-- src/directives/link.ts | 12 ++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/directives/format-text.ts b/src/directives/format-text.ts index acaed8032..d4b975aea 100644 --- a/src/directives/format-text.ts +++ b/src/directives/format-text.ts @@ -27,6 +27,7 @@ import { CoreSite } from '@classes/site'; import { CoreLinkDirective } from '../directives/link'; import { CoreExternalContentDirective } from '../directives/external-content'; import { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper'; +import { CoreSplitViewComponent } from '@components/split-view/split-view'; /** * Directive to format text rendered. It renders the HTML and treats all links and media, using CoreLinkDirective @@ -64,7 +65,7 @@ export class CoreFormatTextDirective implements OnChanges { private utils: CoreUtilsProvider, private urlUtils: CoreUrlUtilsProvider, private loggerProvider: CoreLoggerProvider, private filepoolProvider: CoreFilepoolProvider, private appProvider: CoreAppProvider, private contentLinksHelper: CoreContentLinksHelperProvider, @Optional() private navCtrl: NavController, - @Optional() private content: Content) { + @Optional() private content: Content, @Optional() private svComponent: CoreSplitViewComponent) { this.element = element.nativeElement; this.element.classList.add('opacity-hide'); // Hide contents until they're treated. this.afterRender = new EventEmitter(); @@ -328,7 +329,7 @@ export class CoreFormatTextDirective implements OnChanges { anchors.forEach((anchor) => { // Angular 2 doesn't let adding directives dynamically. Create the CoreLinkDirective manually. const linkDir = new CoreLinkDirective(anchor, this.domUtils, this.utils, this.sitesProvider, this.urlUtils, - this.contentLinksHelper, this.navCtrl, this.content); + this.contentLinksHelper, this.navCtrl, this.content, this.svComponent); linkDir.capture = true; linkDir.ngOnInit(); diff --git a/src/directives/link.ts b/src/directives/link.ts index 1b5700efb..5746fbf51 100644 --- a/src/directives/link.ts +++ b/src/directives/link.ts @@ -20,6 +20,7 @@ import { CoreUrlUtilsProvider } from '@providers/utils/url'; import { CoreUtilsProvider } from '@providers/utils/utils'; import { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper'; import { CoreConfigConstants } from '../configconstants'; +import { CoreSplitViewComponent } from '@components/split-view/split-view'; /** * Directive to open a link in external browser. @@ -40,7 +41,7 @@ export class CoreLinkDirective implements OnInit { constructor(element: ElementRef, private domUtils: CoreDomUtilsProvider, private utils: CoreUtilsProvider, private sitesProvider: CoreSitesProvider, private urlUtils: CoreUrlUtilsProvider, private contentLinksHelper: CoreContentLinksHelperProvider, @Optional() private navCtrl: NavController, - @Optional() private content: Content) { + @Optional() private content: Content, @Optional() private svComponent: CoreSplitViewComponent) { // This directive can be added dynamically. In that case, the first param is the anchor HTMLElement. this.element = element.nativeElement || element; } @@ -51,6 +52,13 @@ export class CoreLinkDirective implements OnInit { ngOnInit(): void { this.inApp = this.utils.isTrueOrOne(this.inApp); + let navCtrl = this.navCtrl; + + if (this.svComponent && (!this.navCtrl || this.navCtrl === this.svComponent.getDetailsNav())) { + // The link is in the right side of a split view. Always open them with the left side NavController. + navCtrl = this.svComponent.getMasterNav(); + } + this.element.addEventListener('click', (event) => { // If the event prevented default action, do nothing. if (!event.defaultPrevented) { @@ -60,7 +68,7 @@ export class CoreLinkDirective implements OnInit { event.stopPropagation(); if (this.utils.isTrueOrOne(this.capture)) { - this.contentLinksHelper.handleLink(href, undefined, this.navCtrl).then((treated) => { + this.contentLinksHelper.handleLink(href, undefined, navCtrl).then((treated) => { if (!treated) { this.navigate(href); }