generated from PackagrIO/goweb-template
-
-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ensure that all external links (other than Source OAuth/SmartOnFire) …
…open in an external window.
- Loading branch information
Showing
14 changed files
with
108 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
frontend/src/app/components/glossary-lookup/glossary-lookup.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { NgModule } from '@angular/core'; | ||
|
||
|
||
// Directives | ||
import {ExternalLinkDirective} from './external-link.directive'; | ||
|
||
@NgModule({ | ||
declarations: [ | ||
ExternalLinkDirective, | ||
], | ||
imports: [ | ||
|
||
], | ||
exports: [ | ||
ExternalLinkDirective, | ||
] | ||
}) | ||
export class DirectivesModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { ExternalLinkDirective } from './external-link.directive'; | ||
|
||
describe('ExternalLinkDirective', () => { | ||
it('should create an instance', () => { | ||
const directive = new ExternalLinkDirective(); | ||
expect(directive).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import {Directive, HostBinding, HostListener, Input} from '@angular/core'; | ||
import {environment} from '../../environments/environment'; | ||
|
||
// In desktop mode external links can allow the user to navigate away from the app, without any means to return. | ||
// We can prevent this by forcing all external links to open in a new tab | ||
// | ||
// references: | ||
// https://www.educative.io/answers/how-to-open-a-link-in-a-new-tab-with-html-and-javascript | ||
// https://stackoverflow.com/questions/42775017/angular-2-redirect-to-an-external-url-and-open-in-a-new-tab | ||
// https://coryrylan.com/blog/managing-external-links-safely-in-angular | ||
// https://stackoverflow.com/questions/58862558/angular-directive-cannot-attach-event-listener-to-element | ||
// https://github.com/wailsapp/wails/issues/2691 | ||
@Directive({ | ||
selector: '[externalLink]' | ||
}) | ||
export class ExternalLinkDirective { | ||
// @HostBinding('attr.rel') relAttr = ''; | ||
// @HostBinding('attr.target') targetAttr = ''; | ||
// @HostBinding('attr.href') hrefAttr = ''; | ||
// @Input() href: string; | ||
|
||
// ngOnChanges() { | ||
// this.hrefAttr = this.href; | ||
// | ||
// if (this.isLinkExternal()) { | ||
// this.relAttr = 'noopener'; | ||
// this.targetAttr = '_blank'; | ||
// } | ||
// console.log("Checking if link is external", this.href) | ||
// } | ||
// | ||
// private isLinkExternal() { | ||
// return !this.href.includes(location.hostname); | ||
// } | ||
|
||
@HostListener("click", ["$event"]) | ||
onClick(event: MouseEvent) { | ||
event.preventDefault(); | ||
|
||
let url: string = (<any>event.currentTarget).getAttribute("href"); | ||
|
||
//check if wails exists and is defined | ||
|
||
if(typeof wails !== "undefined" && environment.environment_desktop){ | ||
wails.CallByName("pkg.AppService.BrowserOpenURL", url) | ||
} else{ | ||
window.open(url, "_blank"); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters