From 774d3712f50c2ae0804f15d6f60485ef9e94356f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Thu, 10 Mar 2016 09:31:58 +0100 Subject: [PATCH] MOBILE-1459: Only capture links from entered text when mm-browser is present --- www/core/directives/browser.js | 39 +++++++++++++++++++++---------- www/core/directives/formattext.js | 1 + 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/www/core/directives/browser.js b/www/core/directives/browser.js index 131f9bcf295..16a52d8a146 100644 --- a/www/core/directives/browser.js +++ b/www/core/directives/browser.js @@ -20,9 +20,28 @@ angular.module('mm.core') * @module mm.core * @ngdoc directive * @name mmBrowser + * + * @param {Boolean} [captureLink=false] If the link needs to be captured by the app. */ .directive('mmBrowser', function($mmUtil, $mmContentLinksHelper) { + /** + * Convenience function to open file or url in the browser. + * + * @param {String} href HREF to be opened + */ + function openInBrowser(href) { + if (href.indexOf('cdvfile://') === 0 || href.indexOf('file://') === 0) { + // We have a local file. + $mmUtil.openFile(href).catch(function(error) { + $mmUtil.showErrorModal(error); + }); + } else { + // It's an external link, we will open with browser. + $mmUtil.openInBrowser(href); + } + } + return { restrict: 'A', priority: 100, @@ -33,19 +52,15 @@ angular.module('mm.core') event.preventDefault(); event.stopPropagation(); - $mmContentLinksHelper.handleLink(href).then(function(treated) { - if (!treated) { - if (href.indexOf('cdvfile://') === 0 || href.indexOf('file://') === 0) { - // We have a local file. - $mmUtil.openFile(href).catch(function(error) { - $mmUtil.showErrorModal(error); - }); - } else { - // It's an external link, we will open with browser. - $mmUtil.openInBrowser(href); + if (attrs.captureLink && attrs.captureLink !== 'false') { + $mmContentLinksHelper.handleLink(href).then(function(treated) { + if (!treated) { + openInBrowser(href); } - } - }); + }); + } else { + openInBrowser(href); + } } }); } diff --git a/www/core/directives/formattext.js b/www/core/directives/formattext.js index cb410cb2c11..df24204c3ad 100644 --- a/www/core/directives/formattext.js +++ b/www/core/directives/formattext.js @@ -212,6 +212,7 @@ angular.module('mm.core') // Important: We need to look for links first because in 'img' we add new links without mm-browser. angular.forEach(dom.find('a'), function(anchor) { anchor.setAttribute('mm-browser', ''); + anchor.setAttribute('capture-link', true); addExternalContent(anchor, component, componentId, siteId); });