-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
77 additions
and
9 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
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,12 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { LinkService } from './link.service'; | ||
|
||
describe('LinkService', () => { | ||
beforeEach(() => TestBed.configureTestingModule({})); | ||
|
||
it('should be created', () => { | ||
const service: LinkService = TestBed.get(LinkService); | ||
expect(service).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,52 @@ | ||
import { Injectable, ElementRef } from '@angular/core'; | ||
import { InAppBrowser } from '@ionic-native/in-app-browser/ngx'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class LinkService { | ||
|
||
constructor(private iab: InAppBrowser) { } | ||
|
||
|
||
/** | ||
* Enable hyperlinks that are embedded within a HTML string | ||
*/ | ||
public _enableDynamicHyperlinks(element: ElementRef): void { | ||
// Provide a minor delay to allow the HTML to be rendered and 'found' | ||
// within the view template | ||
setTimeout(() => { | ||
// Query the DOM to find ALL occurrences of the <a> hyperlink tag | ||
const urls: any = element.nativeElement.querySelectorAll('a'); | ||
|
||
// Iterate through these | ||
urls.forEach((url) => { | ||
// Listen for a click event on each hyperlink found | ||
url.addEventListener('click', (event) => { | ||
// Retrieve the href value from the selected hyperlink | ||
event.preventDefault(); | ||
const link = event.target.href; | ||
|
||
// Log values to the console and open the link within the InAppBrowser plugin | ||
console.log('Name is: ' + event.target.innerText); | ||
console.log('Link is: ' + link); | ||
this.launchInAppBrowser(link); | ||
}, false); | ||
}); | ||
}, 2000); | ||
} | ||
|
||
|
||
|
||
/** | ||
* Creates/launches an Ionic Native InAppBrowser window to display hyperlink locations within | ||
* @param string link The URL to visit within the InAppBrowser window | ||
*/ | ||
public launchInAppBrowser(link: string): void { | ||
const opts = 'location=yes,clearcache=yes,hidespinner=no,beforeload=yes'; | ||
this.iab.create(link, '_system', opts); | ||
} | ||
|
||
|
||
|
||
} |