not really known
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
3.6 KiB

  1. define(["sugar-web/graphics/palette"], function (palette) {
  2. 'use strict';
  3. var custompalette = {};
  4. custompalette.CustomPalette = function (game, invoker, primaryText, menuData) {
  5. console.log(game);
  6. console.log(invoker);
  7. var g = game;
  8. palette.Palette.call(this, invoker, primaryText);
  9. var div = document.createElement('div');
  10. var lrods = document.createElement("label");
  11. lrods.innerHTML = "Rods:";
  12. lrods.setAttribute("for","rods");
  13. var rods = document.createElement("INPUT");
  14. rods.setAttribute("type", "number");
  15. rods.setAttribute("min","1");
  16. rods.setAttribute("style","width:40px;margin:5px;");
  17. rods.setAttribute("id","rods");
  18. rods.value=g.customarr[0];
  19. var ltop = document.createElement("label");
  20. ltop.innerHTML = "Top:";
  21. ltop.setAttribute("for","top");
  22. var top = document.createElement("INPUT");
  23. top.setAttribute("type", "number");
  24. top.setAttribute("min","1");
  25. top.setAttribute("style","width:40px;margin:5px;");
  26. top.setAttribute("id","top");
  27. top.value=g.customarr[1];
  28. var lbottom = document.createElement("label");
  29. lbottom.innerHTML = "Bottom:";
  30. lbottom.setAttribute("for","bottom");
  31. var bottom = document.createElement("INPUT");
  32. bottom.setAttribute("type", "number");
  33. bottom.setAttribute("min","1");
  34. bottom.setAttribute("style","width:40px;margin:5px;");
  35. bottom.setAttribute("id","bottom");
  36. bottom.value=g.customarr[2];
  37. var lfactor = document.createElement("label");
  38. lfactor.innerHTML = "Factor:";
  39. lfactor.setAttribute("for","factor");
  40. var factor = document.createElement("INPUT");
  41. factor.setAttribute("type", "number");
  42. factor.setAttribute("min","1");
  43. factor.setAttribute("style","width:40px;margin:5px;");
  44. factor.setAttribute("id","factor");
  45. factor.value=g.customarr[3];
  46. var lbase = document.createElement("label");
  47. lbase.innerHTML = "Base:";
  48. lbase.setAttribute("for","base");
  49. var base = document.createElement("INPUT");
  50. base.setAttribute("type", "number");
  51. base.setAttribute("min","1");
  52. base.setAttribute("style","width:40px;margin:5px;");
  53. base.setAttribute("id","base");
  54. base.value=g.customarr[4];
  55. var submit = document.createElement('button');
  56. submit.className = 'toolbutton';
  57. submit.setAttribute('id','new-button');
  58. submit.setAttribute('title','Create');
  59. submit.onclick = function() {
  60. that.setAbacus();
  61. }
  62. function isNormalInteger(str) {
  63. var n = Math.floor(Number(str));
  64. return String(n) === str && n > 0;
  65. }
  66. this.setAbacus = function() {
  67. if(isNormalInteger(rods.value)){
  68. that.popDown();
  69. g.updateCustom(parseInt(rods.value),parseInt(top.value),parseInt(bottom.value),parseInt(factor.value),parseInt(base.value));
  70. g.initAbacus(10);
  71. }
  72. }
  73. div.appendChild(lrods);
  74. div.appendChild(rods);
  75. div.appendChild(ltop);
  76. div.appendChild(top);
  77. div.appendChild(lbottom);
  78. div.appendChild(bottom);
  79. div.appendChild(lfactor);
  80. div.appendChild(factor);
  81. div.appendChild(lbase);
  82. div.appendChild(base);
  83. div.appendChild(submit);
  84. this.setContent([div]);
  85. var that = this;
  86. };
  87. var addEventListener = function (type, listener, useCapture) {
  88. return this.getPalette().addEventListener(type, listener, useCapture);
  89. };
  90. custompalette.CustomPalette.prototype =
  91. Object.create(palette.Palette.prototype, {
  92. addEventListener: {
  93. value: addEventListener,
  94. enumerable: true,
  95. configurable: true,
  96. writable: true
  97. }
  98. });
  99. custompalette.CustomPalette.prototype.setShared = function(state) {
  100. this.setShared(state);
  101. }
  102. return custompalette;
  103. });