Screen.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Screen class takes care of everything
  3. * related to screen size and mode
  4. */
  5. var Screen = Class.create({
  6. initialize: function() {
  7. this.MINI_VIEW_THRESHOLD = 150; // Sets the screen height threshold value for miniview
  8. this.container = $("container");
  9. },
  10. // Returns screen size in pixels
  11. getSize: function() {
  12. return {
  13. width: window.innerWidth,
  14. height: window.innerHeight
  15. };
  16. },
  17. // Recognizes the landscape mode
  18. isLandscape: function() {
  19. var size = this.getSize();
  20. return ( size.width > size.height );
  21. },
  22. // This is not needed in Qype S60 WRT widget,
  23. // but is so common that we left it as an example of
  24. // how to extend the functionality
  25. isMiniViewMode: function() {
  26. return ((this.getSize()).height < this.MINI_VIEW_THRESHOLD);
  27. },
  28. /*
  29. * Resize function simply adds the screen mode class
  30. * into DOM tree: thus you can create landscape and
  31. * portrait speficic CSS formatting without any
  32. * code involved
  33. * (As an example, take a look on image used in PlaceView.js)
  34. *
  35. * In case you are willing to have more complex
  36. * landscape/portrait adaptation, this is the place
  37. * to add them
  38. */
  39. resize: function() {
  40. util.log("{Screen.prototype.resize} start");
  41. if(this.isLandscape()) {
  42. this.container.addClassName("landscape");
  43. this.container.removeClassName("portrait");
  44. }
  45. else {
  46. this.container.removeClassName("landscape");
  47. this.container.addClassName("portrait");
  48. }
  49. }
  50. });