Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

88 строки
2.2 KiB

  1. // route urls to their virtual pages
  2. // re-route map (for rename)
  3. wn.re_route = {};
  4. wn.route_titles = {};
  5. wn.view_factory = {};
  6. wn.view_factories = [];
  7. wn.route = function() {
  8. if(wn.re_route[window.location.hash]) {
  9. // after saving a doc, for example,
  10. // "New DocType 1" and the renamed "TestDocType", both exist in history
  11. // now if we try to go back,
  12. // it doesn't allow us to go back to the one prior to "New DocType 1"
  13. // Hence if this check is true, instead of changing location hash,
  14. // we just do a back to go to the doc previous to the "New DocType 1"
  15. var re_route_val = wn.get_route_str(wn.re_route[window.location.hash]);
  16. var cur_route_val = wn.get_route_str(wn._cur_route);
  17. if (decodeURIComponent(re_route_val) === decodeURIComponent(cur_route_val)) {
  18. window.history.back();
  19. return;
  20. } else {
  21. window.location.hash = wn.re_route[window.location.hash];
  22. }
  23. }
  24. wn._cur_route = window.location.hash;
  25. route = wn.get_route();
  26. if(route[0] && wn.views[route[0] + "Factory"]) {
  27. // has a view generator, generate!
  28. if(!wn.view_factory[route[0]])
  29. wn.view_factory[route[0]] = new wn.views[route[0] + "Factory"]();
  30. wn.view_factory[route[0]].show();
  31. } else {
  32. // show page
  33. wn.views.pageview.show(route[0]);
  34. }
  35. if(wn.route_titles[window.location.hash]) {
  36. document.title = wn.route_titles[window.location.hash];
  37. }
  38. }
  39. wn.get_route = function(route) {
  40. // for app
  41. return wn.get_route_str(route).split('/')
  42. }
  43. wn.get_route_str = function(route) {
  44. if(!route)
  45. route = window.location.hash;
  46. if(route.substr(0,1)=='#') route = route.substr(1);
  47. if(route.substr(0,1)=='!') route = route.substr(1);
  48. route = $.map(route.split('/'),
  49. function(r) { return decodeURIComponent(r); }).join('/');
  50. return route;
  51. }
  52. wn.set_route = function() {
  53. route = $.map(arguments, function(a) { return a ? encodeURIComponent(a) : null; }).join('/');
  54. window.location.hash = route;
  55. // Set favicon (app.js)
  56. wn.app.set_favicon();
  57. }
  58. wn._cur_route = null;
  59. $(window).bind('hashchange', function() {
  60. // save the title
  61. wn.route_titles[wn._cur_route] = document.title;
  62. if(window.location.hash==wn._cur_route)
  63. return;
  64. // hide open dialog
  65. if(cur_dialog && cur_dialog.hide_on_page_refresh)
  66. cur_dialog.hide();
  67. wn.route();
  68. });