Lungo.Environment.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /**
  2. * Set environment (Desktop or Mobile) automatically, depending on the
  3. * environment the subscribed events wil be different.
  4. *
  5. * @namespace LUNGO
  6. * @class Environment
  7. *
  8. * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
  9. * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
  10. */
  11. LUNGO.Environment = (function(lng, undefined) {
  12. var MOBILE_ENVIRONMENT = 'mobile';
  13. var DESKTOP_ENVIRONMENT = 'desktop';
  14. var _environment = DESKTOP_ENVIRONMENT;
  15. /**
  16. * Analizing if it's run in Mobile Phone and changing the type of event to subscribe.
  17. *
  18. * @method start
  19. */
  20. var start = function() {
  21. if (lng.Core.isMobile()) {
  22. _environment = MOBILE_ENVIRONMENT;
  23. _saveStatsInLungoJS();
  24. }
  25. };
  26. /**
  27. * Gets the current environment for LungoJS
  28. *
  29. * @method current
  30. *
  31. * @return {String} Current environment enumerator
  32. */
  33. var current = function() {
  34. return _environment;
  35. };
  36. /**
  37. * Returns whether the development environment is in desktop mode
  38. *
  39. * @method isDesktop
  40. *
  41. * @return {Boolean} True if is in DESKTOP_ENVIRONMENT
  42. */
  43. var isDesktop = function() {
  44. return (_environment === DESKTOP_ENVIRONMENT) ? true : false;
  45. };
  46. /**
  47. * Save in LungoJS.com the use of the service for further ranking
  48. *
  49. * @method _saveStatsInLungoJS
  50. */
  51. var _saveStatsInLungoJS = function() {
  52. lng.Service.post( 'http://www.lungojs.com/stats/', {
  53. name: lng.App.get('name'),
  54. version: lng.App.get('version'),
  55. icon: lng.App.get('icon')
  56. });
  57. };
  58. return {
  59. start: start,
  60. current: current,
  61. isDesktop: isDesktop
  62. };
  63. })(LUNGO);