local-notification.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /**
  2. * locale-notification.js
  3. * Cordova LocalNotification Plugin
  4. *
  5. * Created by Sebastian Katzer (github.com/katzer) on 10/08/2013.
  6. * Copyright 2013 Sebastian Katzer. All rights reserved.
  7. * GPL v2 licensed
  8. */
  9. var LocalNotification = function () {
  10. };
  11. LocalNotification.prototype = {
  12. /**
  13. * Fügt einen neuen Eintrag zur Registry hinzu.
  14. *
  15. * @param {Object} options
  16. * @return {Number} Die ID der Notification
  17. */
  18. add: function (options) {
  19. var defaults = {
  20. date: false,
  21. message: '',
  22. title: '',
  23. badge: 0,
  24. id: 0,
  25. icon: 'icon', // nur Android
  26. sound: '', // nur iOS
  27. background: '',
  28. foreground: ''
  29. };
  30. var callbackFn = function (cmd) {
  31. eval(cmd);
  32. };
  33. for (var key in defaults) {
  34. if (options[key] !== undefined) {
  35. defaults[key] = options[key];
  36. }
  37. }
  38. if (defaults.id) {
  39. defaults.id = defaults.id.toString();
  40. }
  41. if (typeof defaults.date == 'object') {
  42. defaults.date = Math.round(defaults.date.getTime()/1000);
  43. }
  44. cordova.exec(callbackFn, null, 'LocalNotification', 'add', [defaults]);
  45. return defaults.id;
  46. },
  47. /**
  48. * Entfernt die angegebene Notification.
  49. *
  50. * @param {String} id
  51. */
  52. cancel: function (id) {
  53. cordova.exec(null, null, 'LocalNotification', 'cancel', [id.toString()]);
  54. },
  55. /**
  56. * Entfernt alle registrierten Notifications.
  57. */
  58. cancelAll: function () {
  59. cordova.exec(null, null, 'LocalNotification', 'cancelAll', []);
  60. }
  61. };
  62. var plugin = new LocalNotification();
  63. module.exports = plugin;