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
2.9 KiB

  1. define([
  2. 'html!ui/templates/messages/tplTab'
  3. ], function (
  4. tplTab
  5. ) {
  6. const extensionObj = {
  7. renderKeyboard: function () {
  8. this.find('.keyboard').remove();
  9. let mainContainer = this.find('.main');
  10. let container = $('<div class="keyboard"></div>')
  11. .appendTo(mainContainer);
  12. let keyboard = {
  13. 0: 'qwertyuiop|asdfghjkl|zxcvbnm',
  14. 1: 'QWERTYUIOP|ASDFGHJKL|ZXCVBNM',
  15. 2: '1234567890|@#&*-+=()|_$"\';/'
  16. }[this.kbUpper].split('');
  17. //Hacky: Insert control characters in correct positions
  18. //Backspace goes after 'm'
  19. if (this.kbUpper === 0) {
  20. keyboard.splice(keyboard.indexOf('z'), 0, 'caps');
  21. keyboard.splice(keyboard.indexOf('m') + 1, 0, '<<');
  22. } else if (this.kbUpper === 1) {
  23. keyboard.splice(keyboard.indexOf('Z'), 0, 'caps');
  24. keyboard.splice(keyboard.indexOf('M') + 1, 0, '<<');
  25. } else if (this.kbUpper === 2)
  26. keyboard.splice(keyboard.indexOf('/') + 1, 0, '<<');
  27. keyboard.push(...['|', '123', ',', 'space', '.', 'send']);
  28. let row = 0;
  29. keyboard.forEach(k => {
  30. if (k === '|') {
  31. row++;
  32. const postGapCount = row === 4 ? 0 : row - 1;
  33. for (let i = 0; i < postGapCount; i++)
  34. $('<div class="gap" />').appendTo(container);
  35. $('<div class="newline" />').appendTo(container);
  36. const preGapCount = row === 3 ? 0 : row;
  37. for (let i = 0; i < preGapCount; i++)
  38. $('<div class="gap" />').appendTo(container);
  39. return;
  40. }
  41. let className = (k.length === 1) ? 'key' : 'key special';
  42. if (k === ' ') {
  43. k = '.';
  44. className = 'key hidden';
  45. }
  46. className += ' ' + k;
  47. let elKey = $(`<div class="${className}">${k}</div>`)
  48. .appendTo(container);
  49. if (!className.includes('hidden'))
  50. elKey.on('click', this.clickKey.bind(this, k));
  51. });
  52. },
  53. clickKey: function (key) {
  54. window.navigator.vibrate(20);
  55. let elInput = this.find('input');
  56. const handler = {
  57. caps: () => {
  58. this.kbUpper = (this.kbUpper + 1) % 2;
  59. this.renderKeyboard();
  60. },
  61. 123: () => {
  62. this.kbUpper = (this.kbUpper === 2) ? 0 : 2;
  63. this.renderKeyboard();
  64. },
  65. space: () => this.clickKey(' '),
  66. '<<': () => {
  67. elInput.val(elInput.val().slice(0, -1));
  68. this.find('.input').html(elInput.val());
  69. },
  70. send: () => {
  71. this.sendChat({ which: 13 });
  72. this.find('.input').html('');
  73. this.find('input').val('');
  74. }
  75. }[key];
  76. if (handler) {
  77. handler();
  78. return;
  79. }
  80. elInput.val(elInput.val() + key);
  81. this.enforceMaxMsgLength();
  82. this.find('.input').html(elInput.val());
  83. }
  84. };
  85. return {
  86. init: function () {
  87. $.extend(this, extensionObj);
  88. this.kbUpper = 0;
  89. this.el.on('click', this.toggle.bind(this, true));
  90. this.renderKeyboard();
  91. $(tplTab)
  92. .appendTo(this.find('.filters'))
  93. .addClass('btnClose')
  94. .html('x')
  95. .on('click', this.toggle.bind(this, false, true));
  96. }
  97. };
  98. });