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.
 
 
 

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