Lungo.Device.Notification.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /**
  2. * Notifacion API (HTML5 Feature)
  3. * Pending to final SPEC, now it's a Phonegap Wrapper
  4. *
  5. * @namespace LUNGO.Device
  6. * @class Notification
  7. *
  8. * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
  9. */
  10. LUNGO.Device.Notification = (function(lng, undefined) {
  11. /**
  12. * Shows a custom alert or dialog box.
  13. *
  14. * @method alert
  15. *
  16. * @param {string} Dialog message
  17. * @param {Function} Callback to invoke when alert dialog is dismissed.
  18. * @param {string} Dialog title (Optional, Default: "Alert")
  19. * @param {string} Button name (Optional, Default: "OK")
  20. */
  21. var alert = function(message, callback, title, buttonName) {
  22. navigator.notification.alert(message, callback, title, buttonName)
  23. };
  24. /**
  25. * Shows a customizable confirmation dialog box.
  26. *
  27. * @method confirm
  28. *
  29. * @param {string} Dialog message @ToDo
  30. * @param {function} Callback to invoke with index of button pressed (1, 2 or 3).
  31. * @param {string} Dialog title (Optional, Default: "Confirm")
  32. * @param {string} Comma separated string with button labels (Optional, Default: "OK,Cancel")
  33. */
  34. var confirm = function(message, callback, title, buttonLabels) {
  35. navigator.notification.confirm(message, callback, title, buttonLabels)
  36. };
  37. /**
  38. * The device will play a beep sound.
  39. *
  40. * @method beep
  41. *
  42. * @param {number} The number of times to repeat the beep
  43. */
  44. var beep = function(times) {
  45. navigator.notification.beep(times)
  46. };
  47. /**
  48. * Vibrates the device for the specified amount of time.
  49. *
  50. * @method vibrate
  51. *
  52. * @param {number} Milliseconds to vibrate the device. 1000 milliseconds equals 1 second
  53. */
  54. var vibrate = function(milliseconds) {
  55. navigator.notification.vibrate(milliseconds)
  56. };
  57. return {
  58. alert: alert,
  59. confirm: confirm,
  60. beep: beep,
  61. vibrate: vibrate
  62. };
  63. })(LUNGO);