routes.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* exported initializeRoutes */
  2. function initializeRoutes()
  3. {
  4. router('/login', routes.login);
  5. router('/sd', routes.sd);
  6. router('*', routes.login);
  7. }
  8. //add a 'firstLoad' setup function into the route's middleware chain
  9. var routes =
  10. {
  11. login: function()
  12. {
  13. showPage('login');
  14. },
  15. sd: function()
  16. {
  17. showPage('sd');
  18. }
  19. };
  20. function showPage(page)
  21. {
  22. console.log('show page', page);
  23. var $page_old = $('.screen.active');
  24. var $page_new = $('#screen-' + page);
  25. //do nothing if we are already on the page
  26. if($page_old.is($page_new))
  27. return;
  28. $('body').attr('class', 'screen-' + page);
  29. //put new page on top of old
  30. $page_new.insertAfter('.screen.active');
  31. //slide it to the right while crossfading
  32. $page_old
  33. .one('animationend', function(event) //jshint ignore:line, unused
  34. {
  35. $(this).hide();
  36. }) //TODO: add detect webkitanimationend or animationend
  37. .removeClass('active');
  38. //slide from left while crossfading
  39. $page_new
  40. .show()
  41. .off('animationend')
  42. .addClass('active')
  43. .focus(); //this needs to be used in conjunction with a "tabindex" field on the html object to maintain keyboard focus
  44. }