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.

154 line
5.7KB

  1. /**
  2. * Copyright 2013 IBM Corp.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. **/
  16. RED.sidebar = (function() {
  17. //$('#sidebar').tabs();
  18. var sidebar_tabs = RED.tabs.create({
  19. id:"sidebar-tabs",
  20. onchange:function(tab) {
  21. $("#sidebar-content").children().hide();
  22. $("#"+tab.id).show();
  23. },
  24. onremove: function(tab) {
  25. $("#"+tab.id).remove();
  26. }
  27. });
  28. function addTab(title,content,closeable) {
  29. $("#sidebar-content").append(content);
  30. $(content).hide();
  31. sidebar_tabs.addTab({id:"tab-"+title,label:title,closeable:closeable});
  32. //content.style.position = "absolute";
  33. //$('#sidebar').tabs("refresh");
  34. }
  35. $('#btn-sidebar').click(function() {toggleSidebar();});
  36. RED.keyboard.add(/* SPACE */ 32,{ctrl:true},function(){toggleSidebar();d3.event.preventDefault();});
  37. var sidebarSeparator = {};
  38. $("#sidebar-separator").draggable({
  39. axis: "x",
  40. start:function(event,ui) {
  41. sidebarSeparator.closing = false;
  42. sidebarSeparator.opening = false;
  43. var winWidth = $(window).width();
  44. sidebarSeparator.start = ui.position.left;
  45. sidebarSeparator.chartWidth = $("#workspace").width();
  46. sidebarSeparator.chartRight = winWidth-$("#workspace").width()-$("#workspace").offset().left-2;
  47. if (!btnSidebar.hasClass("active")) {
  48. sidebarSeparator.opening = true;
  49. var newChartRight = 15;
  50. $("#sidebar").addClass("closing");
  51. $("#workspace").css("right",newChartRight);
  52. $("#chart-zoom-controls").css("right",newChartRight+20);
  53. $("#sidebar").width(0);
  54. toggleSidebar();
  55. RED.view.resize();
  56. }
  57. sidebarSeparator.width = $("#sidebar").width();
  58. },
  59. drag: function(event,ui) {
  60. var d = ui.position.left-sidebarSeparator.start;
  61. var newSidebarWidth = sidebarSeparator.width-d;
  62. if (sidebarSeparator.opening) {
  63. newSidebarWidth -= 13;
  64. }
  65. if (newSidebarWidth > 150) {
  66. if (sidebarSeparator.chartWidth+d < 200) {
  67. ui.position.left = 200+sidebarSeparator.start-sidebarSeparator.chartWidth;
  68. d = ui.position.left-sidebarSeparator.start;
  69. newSidebarWidth = sidebarSeparator.width-d;
  70. }
  71. }
  72. if (newSidebarWidth < 150) {
  73. if (!sidebarSeparator.closing) {
  74. $("#sidebar").addClass("closing");
  75. sidebarSeparator.closing = true;
  76. }
  77. if (!sidebarSeparator.opening) {
  78. newSidebarWidth = 150;
  79. ui.position.left = sidebarSeparator.width-(150 - sidebarSeparator.start);
  80. d = ui.position.left-sidebarSeparator.start;
  81. }
  82. } else if (newSidebarWidth > 150 && (sidebarSeparator.closing || sidebarSeparator.opening)) {
  83. sidebarSeparator.closing = false;
  84. $("#sidebar").removeClass("closing");
  85. }
  86. var newChartRight = sidebarSeparator.chartRight-d;
  87. $("#workspace").css("right",newChartRight);
  88. $("#chart-zoom-controls").css("right",newChartRight+20);
  89. $("#sidebar").width(newSidebarWidth);
  90. sidebar_tabs.resize();
  91. RED.view.resize();
  92. },
  93. stop:function(event,ui) {
  94. RED.view.resize();
  95. if (sidebarSeparator.closing) {
  96. $("#sidebar").removeClass("closing");
  97. toggleSidebar();
  98. if ($("#sidebar").width() < 180) {
  99. $("#sidebar").width(180);
  100. $("#workspace").css("right",208);
  101. $("#chart-zoom-controls").css("right",228);
  102. }
  103. }
  104. $("#sidebar-separator").css("left","auto");
  105. $("#sidebar-separator").css("right",($("#sidebar").width()+13)+"px");
  106. }
  107. });
  108. var btnSidebar = $("#btn-sidebar");
  109. function toggleSidebar() {
  110. //if ($('#sidebar').tabs( "option", "active" ) === false) {
  111. // $('#sidebar').tabs( "option", "active",0);
  112. //}
  113. btnSidebar.toggleClass("active");
  114. if (!btnSidebar.hasClass("active")) {
  115. $("#main-container").addClass("sidebar-closed");
  116. } else {
  117. $("#main-container").removeClass("sidebar-closed");
  118. }
  119. }
  120. toggleSidebar();
  121. function showSidebar(id) {
  122. if (!$("#btn-sidebar").hasClass("active")) {
  123. toggleSidebar();
  124. }
  125. sidebar_tabs.activateTab("tab-"+id);
  126. }
  127. function containsTab(id) {
  128. return sidebar_tabs.contains("tab-"+id);
  129. }
  130. return {
  131. addTab: addTab,
  132. show: showSidebar,
  133. containsTab: containsTab
  134. }
  135. })();