Sandcastle-header.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. (function () {
  2. "use strict";
  3. var defaultAction;
  4. var bucket = window.location.href;
  5. var pos = bucket.lastIndexOf("/");
  6. if (pos > 0 && pos < bucket.length - 1) {
  7. bucket = bucket.substring(pos + 1);
  8. }
  9. window.Sandcastle = {
  10. bucket: bucket,
  11. declare: function () {},
  12. highlight: function () {},
  13. registered: [],
  14. finishedLoading: function () {
  15. window.Sandcastle.reset();
  16. if (defaultAction) {
  17. window.Sandcastle.highlight(defaultAction);
  18. defaultAction();
  19. defaultAction = undefined;
  20. }
  21. document.body.className = document.body.className.replace(/(?:\s|^)sandcastle-loading(?:\s|$)/, " ");
  22. },
  23. addToggleButton: function (text, checked, onchange, toolbarID) {
  24. window.Sandcastle.declare(onchange);
  25. var input = document.createElement("input");
  26. input.checked = checked;
  27. input.type = "checkbox";
  28. input.style.pointerEvents = "none";
  29. var label = document.createElement("label");
  30. label.appendChild(input);
  31. label.appendChild(document.createTextNode(text));
  32. label.style.pointerEvents = "none";
  33. var button = document.createElement("button");
  34. button.type = "button";
  35. button.className = "cesium-button";
  36. button.appendChild(label);
  37. button.onclick = function () {
  38. window.Sandcastle.reset();
  39. window.Sandcastle.highlight(onchange);
  40. input.checked = !input.checked;
  41. onchange(input.checked);
  42. };
  43. document.getElementById(toolbarID || "toolbar").appendChild(button);
  44. },
  45. addToolbarButton: function (text, onclick, toolbarID) {
  46. window.Sandcastle.declare(onclick);
  47. var button = document.createElement("button");
  48. button.type = "button";
  49. button.className = "cesium-button";
  50. button.onclick = function () {
  51. window.Sandcastle.reset();
  52. window.Sandcastle.highlight(onclick);
  53. onclick();
  54. };
  55. button.textContent = text;
  56. document.getElementById(toolbarID || "toolbar").appendChild(button);
  57. },
  58. addDefaultToolbarButton: function (text, onclick, toolbarID) {
  59. window.Sandcastle.addToolbarButton(text, onclick, toolbarID);
  60. defaultAction = onclick;
  61. },
  62. addDefaultToolbarMenu: function (options, toolbarID) {
  63. window.Sandcastle.addToolbarMenu(options, toolbarID);
  64. defaultAction = options[0].onselect;
  65. },
  66. addToolbarMenu: function (options, toolbarID) {
  67. var menu = document.createElement("select");
  68. menu.className = "cesium-button";
  69. menu.onchange = function () {
  70. window.Sandcastle.reset();
  71. var item = options[menu.selectedIndex];
  72. if (item && typeof item.onselect === "function") {
  73. item.onselect();
  74. }
  75. };
  76. document.getElementById(toolbarID || "toolbar").appendChild(menu);
  77. if (!defaultAction && typeof options[0].onselect === "function") {
  78. defaultAction = options[0].onselect;
  79. }
  80. for (var i = 0, len = options.length; i < len; ++i) {
  81. var option = document.createElement("option");
  82. option.textContent = options[i].text;
  83. option.value = options[i].value;
  84. menu.appendChild(option);
  85. }
  86. },
  87. reset: function () {},
  88. };
  89. if (window.location.protocol === "file:") {
  90. if (window.confirm("You must host this app on a web server.\nSee contributor's guide for more info?")) {
  91. window.location = "https://github.com/CesiumGS/cesium/wiki/Contributor%27s-Guide";
  92. }
  93. }
  94. })();