MOBILE-2515 link: Don't open links in right pane of split view
parent
e6c5607463
commit
ff07f4bba8
|
@ -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();
|
||||||
|
@ -328,7 +329,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();
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue