templatemaemo.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. ;(function() {
  2. Nokia.TemplateMaemo = Nokia.Template.extend({
  3. footerIconicMenu: null,
  4. initialize: function(options) {
  5. var instance = this;
  6. var defaults = {
  7. showFirstView: true
  8. };
  9. instance.options = jQuery.extend(defaults, options);
  10. instance._super.apply(instance, [instance.options]);
  11. instance.viewManager = options.viewManager;
  12. // Animated Menu
  13. instance.createAnimatedMenu();
  14. // Content
  15. instance.setContent(
  16. Nokia.dom.parseHTML('<div class="nokia-template-content"></div>')
  17. );
  18. Nokia.dom.append(instance.getContainer(), instance.getContent());
  19. if (instance.options.menu) {
  20. instance.setFooter(
  21. Nokia.dom.parseHTML('<div class="nokia-template-menu"></div>')
  22. );
  23. instance.options.menu.element = Nokia.dom.parseHTML('<div></div>');
  24. instance.iconicMenu = new Nokia.IconicMenu(
  25. instance.options.menu
  26. );
  27. Nokia.dom.append(instance.getFooter(), instance.iconicMenu.getWrapper());
  28. Nokia.dom.append(instance.getMenuWrapper(), instance.getFooter());
  29. } else {
  30. instance.getContent().addClass('nokia-template-content-no-footer');
  31. }
  32. // Append views to the template content
  33. instance.views = instance.viewManager.getViews();
  34. jQuery.each(instance.views, function(i, view) {
  35. view.setTemplate(instance);
  36. view._renderUI(instance.getContent());
  37. });
  38. instance.viewManager.hideAll();
  39. // Show first view
  40. if (instance.options.showFirstView) {
  41. instance.viewManager.show(instance.views[0]);
  42. }
  43. },
  44. createAnimatedMenu: function() {
  45. var instance = this;
  46. instance.menuWrapper = Nokia.dom.parseHTML('<div class="nokia-template-menu-wrapper"></div>');
  47. instance.menuTrigger = Nokia.dom.parseHTML('<a href="javascript:void(0);" class="nokia-template-menu-trigger"></a>');
  48. Nokia.dom.append(instance.getContainer(), instance.menuWrapper);
  49. Nokia.dom.append(instance.getContainer(), instance.menuTrigger);
  50. instance.menuTrigger.click(function() {
  51. instance.showMenu();
  52. });
  53. var allowed = [
  54. '.nokia-template-menu-wrapper',
  55. '.nokia-template-menu-content',
  56. '.nokia-template-menu-trigger'
  57. ].join(', ');
  58. jQuery(document.body).bind('click.menutemplatemaemo', function(event) {
  59. if (!jQuery(event.target).is(allowed)) {
  60. instance.hideMenu();
  61. }
  62. });
  63. },
  64. showMenu: function() {
  65. var instance = this;
  66. instance.menuWrapper.animate({
  67. opacity: 1,
  68. top: '1px',
  69. right: '5px',
  70. height: '418px',
  71. width: '104px'
  72. });
  73. instance.menuTrigger.fadeOut();
  74. },
  75. hideMenu: function() {
  76. var instance = this;
  77. instance.menuWrapper.animate({
  78. opacity: 0,
  79. top: '342px',
  80. right: '16px',
  81. height: '72px',
  82. width: '72px'
  83. });
  84. instance.menuTrigger.fadeIn();
  85. },
  86. getMenuWrapper: function() {
  87. var instance = this;
  88. return instance.menuWrapper;
  89. },
  90. getViewManager: function() {
  91. var instance = this;
  92. return instance.viewManager;
  93. },
  94. getIconicMenu: function() {
  95. var instance = this;
  96. return instance.footerIconicMenu;
  97. }
  98. });
  99. })();