Skip to content

Commit 4ca740f

Browse files
committed
Merge pull request #419 from crazyserver/MOBILE-1459
MOBILE-1459: Only capture links from entered text when mm-browser is …
2 parents 453059d + 774d371 commit 4ca740f

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

www/core/directives/browser.js

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

www/core/directives/formattext.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ angular.module('mm.core')
212212
// Important: We need to look for links first because in 'img' we add new links without mm-browser.
213213
angular.forEach(dom.find('a'), function(anchor) {
214214
anchor.setAttribute('mm-browser', '');
215+
anchor.setAttribute('capture-link', true);
215216
addExternalContent(anchor, component, componentId, siteId);
216217
});
217218

0 commit comments

Comments
 (0)