Sandcastle-header.js 4.0 KB

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