main-frame.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. var homePages = {};
  2. var themeswitcherDialog;
  3. // tabs
  4. var $tabs = null;
  5. var tabCounter = 1;
  6. var lastMenuUrl = '';
  7. var openedTabs = new Map();
  8. $(function() {
  9. // 布局
  10. $('body').layout({
  11. north: {
  12. size: 47
  13. }
  14. });
  15. $('.ui-layout-resizer').addClass('ui-state-default');
  16. // 设置菜单样式
  17. $('#css3menu > li:last').addClass('toplast');
  18. // 初始化中间内容区域
  19. initMainContent();
  20. // 处理角色以及切换
  21. dealRoles();
  22. // 退出系统
  23. $('#loginOut').click(function(){
  24. if (confirm('系统提示,您确定要退出本次登录吗?')) {
  25. location.href = ctx + '/user/logout';
  26. }
  27. });
  28. });
  29. /**
  30. * 初始化中间内容区域
  31. */
  32. function initMainContent() {
  33. var tabPanelHeight = $('#centerPane').height() - 35;
  34. $tabs = $('#tabs').tabs({
  35. tabTemplate: "<li><a class='tabs-title' href='#{href}'>#{label}</a><span class='ui-icon ui-icon-close' title='关闭标签页'></span></li>",
  36. add: function( event, ui ) {
  37. $('#tabs-menu-' + tabCounter).css({height: tabPanelHeight + 'px', width: '100%'});
  38. $( ui.panel ).append( "<iframe id='iframe" + tabCounter + "' name='iframe" + tabCounter + "' scrolling='auto' frameborder='0' class='module-iframe' style='width:100%;height:100%;'></iframe>" );
  39. $('#tabs').tabs('select', $('.tabs-title').length - 1);
  40. $('#iframe' + tabCounter).attr('src', lastMenuUrl);
  41. tabCounter++;
  42. }
  43. }).find( ".ui-tabs-nav" ).sortable({ axis: "x" });
  44. $('#tab-index').height(tabPanelHeight);
  45. // close icon: removing the tab on click
  46. // note: closable tabs gonna be an option in the future - see http://dev.jqueryui.com/ticket/3924
  47. $( "#tabs span.ui-icon-close" ).live( "click", function() {
  48. var index = $( " #tabs li" ).index( $( this ).parent() );
  49. $('#tabs').tabs( "remove", index );
  50. openedTabs.remove($(this).parent().find('a').text());
  51. });
  52. }
  53. /**
  54. * 处理角色以及切换
  55. */
  56. function dealRoles() {
  57. openedTabs.put("首页", 0);
  58. $('#css3menu a').click(function() {
  59. if ($(this).attr('rel') == '#') {
  60. return false;
  61. } else if (!$(this).attr('rel')) {
  62. return true;
  63. }
  64. $('.active').removeClass('active');
  65. $(this).addClass('active');
  66. $(this).parents('li').find('a:eq(0)').addClass('active');
  67. // 多个标签页
  68. var moduleName = $(this).hasClass('use-title') ? $(this).attr('title') : $(this).text();
  69. if (openedTabs.get(moduleName) == null) {
  70. lastMenuUrl = ctx + "/" + $(this).attr('rel');
  71. openedTabs.put($(this).text(), tabCounter);
  72. $('#tabs').tabs( "add", "#tabs-menu-" + tabCounter, moduleName );
  73. } else {
  74. $('#tabs').tabs('select', openedTabs.get(moduleName));
  75. lastMenuUrl = ctx + "/" + $(this).attr('rel');
  76. $('#iframe' + openedTabs.get(moduleName)).attr('src', lastMenuUrl);
  77. }
  78. var menuNames = "";
  79. var alink = $(this).parent().parent().parent().find('a:first');
  80. while (true) {
  81. if (alink.text() != '') {
  82. var hasSameLink = false;
  83. $('#css3menu a').each(function() {
  84. if ($(this).text() == $(alink).text()) {
  85. hasSameLink = true;
  86. return true;
  87. }
  88. });
  89. if (!hasSameLink) {
  90. break;
  91. }
  92. if (menuNames != '') {
  93. menuNames = "->" + menuNames;
  94. }
  95. menuNames = $(alink).text() + menuNames;
  96. alink = $(alink).parent().parent().parent().find('a:first');
  97. } else {
  98. break;
  99. }
  100. }
  101. var p = $('.ui-tabs-nav').position();
  102. $('#menu-road').css({left: 100, top: 80});
  103. });
  104. }
  105. /**
  106. * 使用菜单中的rel添加一个标签页
  107. * @param {Object} menuLink
  108. */
  109. function addTab(menuLink) {
  110. // 多个标签页
  111. var $menuItem = $('#css3menu a[rel="' + menuLink + '"]');
  112. var moduleName = $menuItem.hasClass('use-title') ? $($menuItem).attr('title') : $($menuItem).text();
  113. if (openedTabs.get(moduleName) == null) {
  114. lastMenuUrl = ctx + "/" + $($menuItem).attr('rel');
  115. openedTabs.put($($menuItem).text(), tabCounter);
  116. $('#tabs').tabs( "add", "#tabs-menu-" + tabCounter, moduleName );
  117. } else {
  118. $('#tabs').tabs('select', openedTabs.get(moduleName));
  119. }
  120. }