You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

68 lines
1.5 KiB

  1. // Copyright 2013 Web Notes Technologies Pvt Ltd
  2. // License: MIT. See license.txt
  3. // page container
  4. wn.provide('wn.pages');
  5. wn.provide('wn.views');
  6. wn.views.Container = Class.extend({
  7. init: function() {
  8. this.container = $('#body_div').addClass("container").get(0);
  9. this.page = null; // current page
  10. this.pagewidth = $('#body_div').width();
  11. this.pagemargin = 50;
  12. },
  13. add_page: function(label, onshow, onhide) {
  14. var page = $('<div class="content row"></div>')
  15. .attr('id', "page-" + label)
  16. .toggle(false)
  17. .appendTo(this.container).get(0);
  18. if(onshow)
  19. $(page).bind('show', onshow);
  20. if(onshow)
  21. $(page).bind('hide', onhide);
  22. page.label = label;
  23. wn.pages[label] = page;
  24. return page;
  25. },
  26. change_to: function(label) {
  27. if(this.page && this.page.label == label) {
  28. // don't trigger double events
  29. $(this.page).trigger('show');
  30. return;
  31. }
  32. var me = this;
  33. if(label.tagName) {
  34. // if sent the div, get the table
  35. var page = label;
  36. } else {
  37. var page = wn.pages[label];
  38. }
  39. if(!page) {
  40. console.log(wn._('Page not found')+ ': ' + label);
  41. return;
  42. }
  43. // hide current
  44. if(this.page && this.page != page) {
  45. $(this.page).toggle(false);
  46. $(this.page).trigger('hide');
  47. }
  48. // show new
  49. if(!this.page || this.page != page) {
  50. this.page = page;
  51. //$(this.page).fadeIn();
  52. $(this.page).toggle(true);
  53. }
  54. $(document).trigger("page-change");
  55. this.page._route = window.location.hash;
  56. $(this.page).trigger('show');
  57. scroll(0,0);
  58. return this.page;
  59. }
  60. });