Skip to content

Instantly share code, notes, and snippets.

@mhartington
Created September 17, 2015 12:29
Show Gist options
  • Save mhartington/edab9c2d790741ab0b2c to your computer and use it in GitHub Desktop.
Save mhartington/edab9c2d790741ab0b2c to your computer and use it in GitHub Desktop.
angular.module('sfViewCtrlDirective', [])
.directive('open', OpenDirective);
function OpenDirective() {
return {
restrict: 'A',
link: function($scope, $element, $attr) {
console.log('device is ready');
$element.on('click', function() {
SafariViewController.isAvailable(function(available) {
if (available) {
SafariViewController.show({
'url': $attr.open,
'enterReaderModeIfAvailable': false
},
function(msg) {
console.log("All good");
},
function(msg) {
alert("There appears to have been an error");
})
} else {
// potentially powered by InAppBrowser because that clobbers window.open
window.open($attr.open, '_blank', 'location=yes');
}
})
});
};
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment