InspectorShared.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 (labelText, checkedBinding, enableBinding) {
  16. //>>includeStart('debug', pragmas.debug);
  17. Check.typeOf.string('labelText', labelText);
  18. Check.typeOf.string('checkedBinding', checkedBinding);
  19. //>>includeEnd('debug');
  20. var checkboxContainer = document.createElement('div');
  21. var checkboxLabel = document.createElement('label');
  22. var checkboxInput = document.createElement('input');
  23. checkboxInput.type = 'checkbox';
  24. var binding = 'checked: ' + checkedBinding;
  25. if (defined(enableBinding)) {
  26. binding += ', enable: ' + enableBinding;
  27. }
  28. checkboxInput.setAttribute('data-bind', binding);
  29. checkboxLabel.appendChild(checkboxInput);
  30. checkboxLabel.appendChild(document.createTextNode(labelText));
  31. checkboxContainer.appendChild(checkboxLabel);
  32. return checkboxContainer;
  33. };
  34. /**
  35. * Creates a section element
  36. * @param {Element} panel The parent element
  37. * @param {String} headerText The text to display at the top of the section
  38. * @param {String} sectionVisibleBinding The name of the variable used for visible binding
  39. * @param {String} toggleSectionVisibilityBinding The name of the function used to toggle visibility
  40. * @return {Element}
  41. */
  42. InspectorShared.createSection = function (panel, headerText, sectionVisibleBinding, toggleSectionVisibilityBinding) {
  43. //>>includeStart('debug', pragmas.debug);
  44. Check.defined('panel', panel);
  45. Check.typeOf.string('headerText', headerText);
  46. Check.typeOf.string('sectionVisibleBinding', sectionVisibleBinding);
  47. Check.typeOf.string('toggleSectionVisibilityBinding', toggleSectionVisibilityBinding);
  48. //>>includeEnd('debug');
  49. var section = document.createElement('div');
  50. section.className = 'cesium-cesiumInspector-section';
  51. section.setAttribute('data-bind', 'css: { "cesium-cesiumInspector-section-collapsed": !' + sectionVisibleBinding + ' }');
  52. panel.appendChild(section);
  53. var sectionHeader = document.createElement('h3');
  54. sectionHeader.className = 'cesium-cesiumInspector-sectionHeader';
  55. sectionHeader.appendChild(document.createTextNode(headerText));
  56. sectionHeader.setAttribute('data-bind', 'click: ' + toggleSectionVisibilityBinding);
  57. section.appendChild(sectionHeader);
  58. var sectionContent = document.createElement('div');
  59. sectionContent.className = 'cesium-cesiumInspector-sectionContent';
  60. section.appendChild(sectionContent);
  61. return sectionContent;
  62. };
  63. export default InspectorShared;