Last active
August 29, 2015 13:56
-
-
Save ozexpert/9259545 to your computer and use it in GitHub Desktop.
AngularJS / Cordova Notification Service for device & web (Cordova Ver 3.3.0)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
YourModule.factory('Notification', function($rootScope){ | |
return { | |
alert: function(message, callback){ | |
if(navigator.notification !== undefined){ | |
navigator.notification.alert(message, | |
function(){ | |
$rootScope.$apply(callback()); | |
}); | |
} else { | |
alert(message); | |
callback(); | |
} | |
}, | |
confirm: function(message, callback){ | |
if(navigator.notification !== undefined){ | |
var callbackWrapper = function(buttonIndex){ | |
if(buttonIndex == 1){ | |
callback(); | |
} | |
}; | |
navigator.notification.confirm(message, | |
function(buttonIndex){ | |
$rootScope.$apply(callbackWrapper(buttonIndex)); | |
}); | |
} else { | |
var trueOrFalse = confirm(message); | |
if(trueOrFalse){ | |
callback(); | |
} | |
} | |
}, | |
prompt: function(message, title, callback){ | |
//navigator.notification.prompt(message, promptCallback, [title], [buttonLabels], [defaultText]) | |
if(navigator.notification !== undefined){ | |
var callbackWrapper = function(results){ | |
if(results.buttonIndex == 1){ | |
callback(results.input1); | |
} | |
}; | |
navigator.notification.prompt(message, | |
function (results) { | |
$rootScope.$apply(callbackWrapper(results)); | |
}, title); | |
} else { | |
var sessionTitle = prompt(message); | |
callback(sessionTitle); | |
} | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment