Sandcastle-header.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. addToolbarButton : function(text, onclick, toolbarID) {
  26. window.Sandcastle.declare(onclick);
  27. var button = document.createElement('button');
  28. button.type = 'button';
  29. button.className = 'SuperMap3D-button';
  30. button.onclick = function() {
  31. window.Sandcastle.reset();
  32. window.Sandcastle.highlight(onclick);
  33. onclick();
  34. };
  35. button.textContent = text;
  36. document.getElementById(toolbarID || 'toolbar').appendChild(button);
  37. },
  38. addDefaultToolbarButton : function(text, onclick, toolbarID) {
  39. window.Sandcastle.addToolbarButton(text, onclick, toolbarID);
  40. defaultAction = onclick;
  41. },
  42. addDefaultToolbarMenu : function(options, toolbarID) {
  43. window.Sandcastle.addToolbarMenu(options, toolbarID);
  44. defaultAction = options[0].onselect;
  45. },
  46. addToolbarMenu : function(options, toolbarID) {
  47. var menu = document.createElement('select');
  48. menu.className = 'SuperMap3D-button';
  49. menu.onchange = function() {
  50. window.Sandcastle.reset();
  51. var item = options[menu.selectedIndex];
  52. if (item && typeof item.onselect === 'function') {
  53. item.onselect();
  54. }
  55. };
  56. document.getElementById(toolbarID || 'toolbar').appendChild(menu);
  57. if (!defaultAction && typeof options[0].onselect === 'function') {
  58. defaultAction = options[0].onselect;
  59. }
  60. for (var i = 0, len = options.length; i < len; ++i) {
  61. var option = document.createElement('option');
  62. option.textContent = options[i].text;
  63. option.value = options[i].value;
  64. menu.appendChild(option);
  65. }
  66. },
  67. reset : function() {
  68. }
  69. };
  70. if (window.location.protocol === 'file:') {
  71. if (window.confirm("You must host this app on a web server.\nSee contributor's guide for more info?")) {
  72. window.location = 'https://github.com/AnalyticalGraphicsInc/SuperMap3D/wiki/Contributor%27s-Guide';
  73. }
  74. }
  75. }());