@@ -20,9 +20,28 @@ angular.module('mm.core')
2020 * @module mm.core
2121 * @ngdoc directive
2222 * @name mmBrowser
23+ *
24+ * @param {Boolean } [captureLink=false] If the link needs to be captured by the app.
2325 */
2426. directive ( 'mmBrowser' , function ( $mmUtil , $mmContentLinksHelper ) {
2527
28+ /**
29+ * Convenience function to open file or url in the browser.
30+ *
31+ * @param {String } href HREF to be opened
32+ */
33+ function openInBrowser ( href ) {
34+ if ( href . indexOf ( 'cdvfile://' ) === 0 || href . indexOf ( 'file://' ) === 0 ) {
35+ // We have a local file.
36+ $mmUtil . openFile ( href ) . catch ( function ( error ) {
37+ $mmUtil . showErrorModal ( error ) ;
38+ } ) ;
39+ } else {
40+ // It's an external link, we will open with browser.
41+ $mmUtil . openInBrowser ( href ) ;
42+ }
43+ }
44+
2645 return {
2746 restrict : 'A' ,
2847 priority : 100 ,
@@ -33,19 +52,15 @@ angular.module('mm.core')
3352 event . preventDefault ( ) ;
3453 event . stopPropagation ( ) ;
3554
36- $mmContentLinksHelper . handleLink ( href ) . then ( function ( treated ) {
37- if ( ! treated ) {
38- if ( href . indexOf ( 'cdvfile://' ) === 0 || href . indexOf ( 'file://' ) === 0 ) {
39- // We have a local file.
40- $mmUtil . openFile ( href ) . catch ( function ( error ) {
41- $mmUtil . showErrorModal ( error ) ;
42- } ) ;
43- } else {
44- // It's an external link, we will open with browser.
45- $mmUtil . openInBrowser ( href ) ;
55+ if ( attrs . captureLink && attrs . captureLink !== 'false' ) {
56+ $mmContentLinksHelper . handleLink ( href ) . then ( function ( treated ) {
57+ if ( ! treated ) {
58+ openInBrowser ( href ) ;
4659 }
47- }
48- } ) ;
60+ } ) ;
61+ } else {
62+ openInBrowser ( href ) ;
63+ }
4964 }
5065 } ) ;
5166 }
0 commit comments