Advertisement
Guest User

main.js

a guest
Apr 23rd, 2013
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. window.HomeView = Backbone.View.extend({
  2.  
  3.     template:_.template($('#home').html()),
  4.  
  5.     render:function (eventName) {
  6.         $(this.el).html(this.template());
  7.         return this;
  8.     }
  9. });
  10.  
  11. window.Page1View = Backbone.View.extend({
  12.  
  13.     template:_.template($('#page1').html()),
  14.  
  15.     render:function (eventName) {
  16.         $(this.el).html(this.template());
  17.         return this;
  18.     }
  19. });
  20.  
  21. window.Page2View = Backbone.View.extend({
  22.  
  23.     template:_.template($('#page2').html()),
  24.  
  25.     render:function (eventName) {
  26.         $(this.el).html(this.template());
  27.         return this;
  28.     }
  29. });
  30.  
  31. var AppRouter = Backbone.Router.extend({
  32.  
  33.     routes:{
  34.         "":"home",
  35.         "page1":"page1",
  36.         "page2":"page2"
  37.     },
  38.  
  39.     initialize:function () {
  40.         // Handle back button throughout the application
  41.         $('.back').live('click', function(event) {
  42.             window.history.back();
  43.             return false;
  44.         });
  45.         this.firstPage = true;
  46.     },
  47.  
  48.     home:function () {
  49.         console.log('#home');
  50.         this.changePage(new HomeView());
  51.     },
  52.  
  53.     page1:function () {
  54.         console.log('#page1');
  55.         this.changePage(new Page1View());
  56.     },
  57.  
  58.     page2:function () {
  59.         console.log('#page2');
  60.         this.changePage(new Page2View());
  61.     },
  62.  
  63.     changePage:function (page) {
  64.         console.log($(page.el));
  65.         $(page.el).attr('data-role', 'page');
  66.         page.render();
  67.         $('#app-content').append($(page.el));
  68.         var transition = $.mobile.defaultPageTransition;
  69.         // We don't want to slide the first page
  70.         if (this.firstPage) {
  71.             transition = 'none';
  72.             this.firstPage = false;
  73.         }
  74.         $.mobile.changePage($(page.el), {changeHash:false, transition: transition});
  75.     }
  76.  
  77. });
  78.  
  79. $(document).ready(function () {
  80.     console.log('document ready');
  81.     app = new AppRouter();
  82.     Backbone.history.start();
  83. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement