InspectorShared.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import Check from "../Core/Check.js";
  2. import defined from "../Core/defined.js";
  3. /**
  4. * A static class with helper functions used by the CesiumInspector and Cesium3DTilesInspector
  5. * @private
  6. */
  7. var InspectorShared = {};
  8. /**
  9. * Creates a checkbox component
  10. * @param {String} labelText The text to display in the checkbox label
  11. * @param {String} checkedBinding The name of the variable used for checked binding
  12. * @param {String} [enableBinding] The name of the variable used for enable binding
  13. * @return {Element}
  14. */
  15. InspectorShared.createCheckbox = function (
  16. labelText,
  17. checkedBinding,
  18. enableBinding
  19. ) {
  20. //>>includeStart('debug', pragmas.debug);
  21. Check.typeOf.string("labelText", labelText);
  22. Check.typeOf.string("checkedBinding", checkedBinding);
  23. //>>includeEnd('debug');
  24. var checkboxContainer = document.createElement("div");
  25. var checkboxLabel = document.createElement("label");
  26. var checkboxInput = document.createElement("input");
  27. checkboxInput.type = "checkbox";
  28. var binding = "checked: " + checkedBinding;
  29. if (defined(enableBinding)) {
  30. binding += ", enable: " + enableBinding;
  31. }
  32. checkboxInput.setAttribute("data-bind", binding);
  33. checkboxLabel.appendChild(checkboxInput);
  34. checkboxLabel.appendChild(document.createTextNode(labelText));
  35. checkboxContainer.appendChild(checkboxLabel);
  36. return checkboxContainer;
  37. };
  38. /**
  39. * Creates a section element
  40. * @param {Element} panel The parent element
  41. * @param {String} headerText The text to display at the top of the section
  42. * @param {String} sectionVisibleBinding The name of the variable used for visible binding
  43. * @param {String} toggleSectionVisibilityBinding The name of the function used to toggle visibility
  44. * @return {Element}
  45. */
  46. InspectorShared.createSection = function (
  47. panel,
  48. headerText,
  49. sectionVisibleBinding,
  50. toggleSectionVisibilityBinding
  51. ) {
  52. //>>includeStart('debug', pragmas.debug);
  53. Check.defined("panel", panel);
  54. Check.typeOf.string("headerText", headerText);
  55. Check.typeOf.string("sectionVisibleBinding", sectionVisibleBinding);
  56. Check.typeOf.string(
  57. "toggleSectionVisibilityBinding",
  58. toggleSectionVisibilityBinding
  59. );
  60. //>>includeEnd('debug');
  61. var section = document.createElement("div");
  62. section.className = "cesium-cesiumInspector-section";
  63. section.setAttribute(
  64. "data-bind",
  65. 'css: { "cesium-cesiumInspector-section-collapsed": !' +
  66. sectionVisibleBinding +
  67. " }"
  68. );
  69. panel.appendChild(section);
  70. var sectionHeader = document.createElement("h3");
  71. sectionHeader.className = "cesium-cesiumInspector-sectionHeader";
  72. sectionHeader.appendChild(document.createTextNode(headerText));
  73. sectionHeader.setAttribute(
  74. "data-bind",
  75. "click: " + toggleSectionVisibilityBinding
  76. );
  77. section.appendChild(sectionHeader);
  78. var sectionContent = document.createElement("div");
  79. sectionContent.className = "cesium-cesiumInspector-sectionContent";
  80. section.appendChild(sectionContent);
  81. return sectionContent;
  82. };
  83. export default InspectorShared;