Merge pull request #1454 from dpalou/MOBILE-2515

MOBILE-2515 link: Don't open links in right pane of split view
main
Juan Leyva 2018-08-21 17:38:04 +01:00 committed by GitHub
commit e7606286ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 { CoreLinkDirective } from '../directives/link';
import { CoreExternalContentDirective } from '../directives/external-content'; import { CoreExternalContentDirective } from '../directives/external-content';
import { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper'; 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 * 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 utils: CoreUtilsProvider, private urlUtils: CoreUrlUtilsProvider, private loggerProvider: CoreLoggerProvider,
private filepoolProvider: CoreFilepoolProvider, private appProvider: CoreAppProvider, private filepoolProvider: CoreFilepoolProvider, private appProvider: CoreAppProvider,
private contentLinksHelper: CoreContentLinksHelperProvider, @Optional() private navCtrl: NavController, 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 = element.nativeElement;
this.element.classList.add('opacity-hide'); // Hide contents until they're treated. this.element.classList.add('opacity-hide'); // Hide contents until they're treated.
this.afterRender = new EventEmitter(); this.afterRender = new EventEmitter();
@ -330,7 +331,7 @@ export class CoreFormatTextDirective implements OnChanges {
anchors.forEach((anchor) => { anchors.forEach((anchor) => {
// Angular 2 doesn't let adding directives dynamically. Create the CoreLinkDirective manually. // 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, 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.capture = true;
linkDir.ngOnInit(); linkDir.ngOnInit();

View File

@ -20,6 +20,7 @@ import { CoreUrlUtilsProvider } from '@providers/utils/url';
import { CoreUtilsProvider } from '@providers/utils/utils'; import { CoreUtilsProvider } from '@providers/utils/utils';
import { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper'; import { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper';
import { CoreConfigConstants } from '../configconstants'; import { CoreConfigConstants } from '../configconstants';
import { CoreSplitViewComponent } from '@components/split-view/split-view';
/** /**
* Directive to open a link in external browser. * 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, constructor(element: ElementRef, private domUtils: CoreDomUtilsProvider, private utils: CoreUtilsProvider,
private sitesProvider: CoreSitesProvider, private urlUtils: CoreUrlUtilsProvider, private sitesProvider: CoreSitesProvider, private urlUtils: CoreUrlUtilsProvider,
private contentLinksHelper: CoreContentLinksHelperProvider, @Optional() private navCtrl: NavController, 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 directive can be added dynamically. In that case, the first param is the anchor HTMLElement.
this.element = element.nativeElement || element; this.element = element.nativeElement || element;
} }
@ -51,6 +52,13 @@ export class CoreLinkDirective implements OnInit {
ngOnInit(): void { ngOnInit(): void {
this.inApp = this.utils.isTrueOrOne(this.inApp); 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) => { this.element.addEventListener('click', (event) => {
// If the event prevented default action, do nothing. // If the event prevented default action, do nothing.
if (!event.defaultPrevented) { if (!event.defaultPrevented) {
@ -60,7 +68,7 @@ export class CoreLinkDirective implements OnInit {
event.stopPropagation(); event.stopPropagation();
if (this.utils.isTrueOrOne(this.capture)) { 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) { if (!treated) {
this.navigate(href); this.navigate(href);
} }