locale-notification.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. */
  17. add: function (options) {
  18. var defaults = {
  19. date: false,
  20. message: '',
  21. hasAction: true,
  22. action: 'View',
  23. badge: 0,
  24. id: 0,
  25. sound: '',
  26. background:'',
  27. foreground:''
  28. };
  29. for (var key in defaults) {
  30. if (options[key] !== undefined) {
  31. defaults[key] = options[key];
  32. }
  33. }
  34. if (typeof defaults.date == 'object') {
  35. defaults.date = Math.round(defaults.date.getTime()/1000);
  36. }
  37. cordova.exec(null, null, 'LocalNotification','add', [defaults]);
  38. },
  39. /**
  40. * Entfernt die angegebene Notification.
  41. *
  42. * @param {String} id
  43. */
  44. cancel: function (id) {
  45. cordova.exec(null, null, 'LocalNotification', 'cancel', [id]);
  46. },
  47. /**
  48. * Entfernt alle registrierten Notifications.
  49. */
  50. cancelAll: function () {
  51. cordova.exec(null, null, 'LocalNotification', 'cancelAll', []);
  52. }
  53. };
  54. var plugin = new LocalNotification();
  55. module.exports = plugin;