MOBILE-2515 link: Don't open links in right pane of split view

main
Dani Palou 2018-07-31 15:02:44 +02:00
parent e6c5607463
commit ff07f4bba8
2 changed files with 13 additions and 4 deletions

View File

@ -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();

View File

@ -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);
}