local-notification.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. sound: '', // nur iOS
  26. background: '',
  27. foreground: ''
  28. };
  29. var callbackFn = function (cmd) {
  30. eval(cmd);
  31. };
  32. for (var key in defaults) {
  33. if (options[key] !== undefined) {
  34. defaults[key] = options[key];
  35. }
  36. }
  37. if (defaults.id) {
  38. defaults.id = defaults.id.toString();
  39. }
  40. if (typeof defaults.date == 'object') {
  41. defaults.date = Math.round(defaults.date.getTime()/1000);
  42. }
  43. cordova.exec(callbackFn, null, 'LocalNotification', 'add', [defaults]);
  44. return defaults.id;
  45. },
  46. /**
  47. * Entfernt die angegebene Notification.
  48. *
  49. * @param {String} id
  50. */
  51. cancel: function (id) {
  52. cordova.exec(null, null, 'LocalNotification', 'cancel', [id.toString()]);
  53. },
  54. /**
  55. * Entfernt alle registrierten Notifications.
  56. */
  57. cancelAll: function () {
  58. cordova.exec(null, null, 'LocalNotification', 'cancelAll', []);
  59. }
  60. };
  61. var plugin = new LocalNotification();
  62. module.exports = plugin;