local-notification.js 1.7 KB

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