Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 27 additions & 12 deletions www/core/directives/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}
}
});
}
Expand Down
1 change: 1 addition & 0 deletions www/core/directives/formattext.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down