vis.js is a dynamic, browser-based visualization library
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.

83 lines
3.0 KiB

9 years ago
  1. /**
  2. * Created by Alex on 4/21/2015.
  3. */
  4. /**
  5. * it works like this:
  6. *
  7. * the toggle row has the onclick with the table id, the parent name and this. The function will look through all trs with matching parent and check the class
  8. * if hidden, it shows them, else it hides them.
  9. *
  10. * The caret is also flipped and the toggle class is changed.
  11. *
  12. *
  13. <tr class='toggle collapsible' onclick="toggleTable('physicsTable','barnesHut', this);"><td><span parent="barnesHut" class="right-caret"></span> barnesHut</td></tr>
  14. <tr parent="barnesHut" class="hidden"><td>barnesHut.gravitationalConstant</td></tr>
  15. <tr parent="barnesHut" class="hidden"><td>barnesHut.centralGravity</td></tr>
  16. <tr parent="barnesHut" class="hidden"><td>barnesHut.springLength</td></tr>
  17. <tr parent="barnesHut" class="hidden"><td>barnesHut.springConstant</td></tr>
  18. <tr parent="barnesHut" class="hidden"><td>barnesHut.damping</td></tr>
  19. *
  20. *
  21. * @param tableId
  22. * @param parent
  23. * @param clickedRow
  24. */
  25. function toggleTable(tableId, parent, clickedRow) {
  26. var table = document.getElementById(tableId);
  27. var wasOpen = false;
  28. for (var i = 0, row; row = table.rows[i]; i++) {
  29. if (row.getAttribute('parent') === parent) {
  30. if (row.className === 'hidden') {
  31. row.className = 'visible';
  32. }
  33. else {
  34. row.className = 'hidden';
  35. wasOpen = true;
  36. }
  37. }
  38. }
  39. var spans;
  40. if (wasOpen === true) {
  41. spans = document.getElementsByClassName('caret');
  42. clickedRow.className = 'toggle collapsible';
  43. }
  44. else {
  45. spans = document.getElementsByClassName('right-caret')
  46. clickedRow.className = 'toggle';
  47. }
  48. for (var i = 0; i < spans.length; i++) {
  49. if (spans[i].getAttribute('parent') === parent) {
  50. spans[i].className = wasOpen === true ? 'right-caret' : 'caret';
  51. }
  52. }
  53. }
  54. function toggleTab(showTabId, showPreId, hideTabId, hidePreId) {
  55. if (hideTabId !== undefined) {
  56. document.getElementById(hideTabId).className = '';
  57. document.getElementById(hidePreId).className = document.getElementById(hidePreId).className.replace(' hidden','');
  58. document.getElementById(hidePreId).className += ' hidden';
  59. }
  60. document.getElementById('hiddenTab').className = '';
  61. document.getElementById(showTabId).className = 'active';
  62. document.getElementById(showPreId).className = document.getElementById(showPreId).className.replace(' hidden','');
  63. }
  64. function hideOptions(hideTabId1, hidePreId1, hideTabId2, hidePreId2) {
  65. document.getElementById('hiddenTab').className = 'active';
  66. document.getElementById(hideTabId1).className = '';
  67. document.getElementById(hidePreId1).className = document.getElementById(hidePreId1).className.replace(' hidden','');
  68. document.getElementById(hidePreId1).className += ' hidden';
  69. if (hideTabId2 !== undefined) {
  70. document.getElementById(hideTabId2).className = '';
  71. document.getElementById(hidePreId2).className = document.getElementById(hidePreId2).className.replace(' hidden','');
  72. document.getElementById(hidePreId2).className += ' hidden';
  73. }
  74. }