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.

126 lines
3.6 KiB

  1. define(["sugar-web/graphics/palette", "mustache"],
  2. function(palette, mustache) {
  3. var trigopalette = {};
  4. var isIos = (navigator.userAgent.match(/iPad|iPhone|iPod/g) ? true : false )
  5. trigopalette.trigoPalette = function(invoker, primaryText) {
  6. palette.Palette.call(this, invoker, primaryText);
  7. this.trigoChangeEvent = document.createEvent("CustomEvent");
  8. this.trigoChangeEvent.initCustomEvent('trigoClick', true, true, {});
  9. this.template =
  10. '<tbody>' +
  11. '{{#rows}}' +
  12. '<tr>' +
  13. '{{#.}}' +
  14. '<td>' +
  15. '<button style="background:none; border-radius:0px; border:0px; margin:3px; width:55px; height:55px; background-image: url({{backgroundSvg}})" value="{{value}}"></button>' +
  16. '</td>' +
  17. '{{/.}}' +
  18. '</tr>' +
  19. '{{/rows}}' +
  20. '</tbody>';
  21. var trigoElem = document.createElement('table');
  22. trigoElem.className = "trigos";
  23. var trigoData = {
  24. rows: [
  25. [{
  26. title: "COS",
  27. value: "cos(",
  28. backgroundSvg: "icons/trigonometry-cos.svg"
  29. }, {
  30. title: "SIN",
  31. value: "sin(",
  32. backgroundSvg: "icons/trigonometry-sin.svg"
  33. }, {
  34. "title": "TAN",
  35. value: "tan(",
  36. backgroundSvg: "icons/trigonometry-tan.svg"
  37. }],
  38. [{
  39. "title": "ACOS",
  40. value: "acos(",
  41. backgroundSvg: "icons/trigonometry-acos.svg"
  42. }, {
  43. "title": "ASIN",
  44. value: "asin(",
  45. backgroundSvg: "icons/trigonometry-asin.svg"
  46. }, {
  47. "title": "ATAN",
  48. value: "atan(",
  49. backgroundSvg: "icons/trigonometry-atan.svg"
  50. }],
  51. [{
  52. "title": "COSH",
  53. value: "cosh(",
  54. backgroundSvg: "icons/trigonometry-cosh.svg"
  55. }, {
  56. "title": "SINH",
  57. value: "sinh(",
  58. backgroundSvg: "icons/trigonometry-sinh.svg"
  59. }, {
  60. "title": "TANH",
  61. value: "tanh(",
  62. backgroundSvg: "icons/trigonometry-tanh.svg"
  63. }]
  64. ]
  65. };
  66. trigoElem.innerHTML = mustache.render(this.template, trigoData);
  67. this.setContent([trigoElem]);
  68. // Pop-down the palette when a item in the menu is clicked.
  69. this.buttons = trigoElem.querySelectorAll('button');
  70. var that = this;
  71. function popDownOnButtonClick(event) {
  72. that.trigoChangeEvent.detail.value = event.target.value;
  73. that.getPalette().dispatchEvent(that.trigoChangeEvent);
  74. that.popDown();
  75. }
  76. for (var i = 0; i < this.buttons.length; i++) {
  77. if (isIos) {
  78. this.buttons[i].addEventListener('touchstart', popDownOnButtonClick);
  79. } else {
  80. this.buttons[i].addEventListener('click', popDownOnButtonClick);
  81. }
  82. }
  83. };
  84. var setColor = function(index) {
  85. // Click the nth button
  86. var event = document.createEvent("MouseEvents");
  87. event.initEvent("click", true, true);
  88. this.buttons[index].dispatchEvent(event);
  89. };
  90. var addEventListener = function(type, listener, useCapture) {
  91. return this.getPalette().addEventListener(type, listener, useCapture);
  92. };
  93. trigopalette.trigoPalette.prototype =
  94. Object.create(palette.Palette.prototype, {
  95. setColor: {
  96. value: setColor,
  97. enumerable: true,
  98. configurable: true,
  99. writable: true
  100. },
  101. addEventListener: {
  102. value: addEventListener,
  103. enumerable: true,
  104. configurable: true,
  105. writable: true
  106. }
  107. });
  108. return trigopalette;
  109. });