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.

tribute.js 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import {emojiKeys, emojiHTML, emojiString} from './emoji.js';
  2. export const issuesTribute = window.config.Tribute ? new Tribute({
  3. values: window.config.tributeValues,
  4. noMatchTemplate() { return null },
  5. menuItemTemplate(item) {
  6. const div = $('<div/>');
  7. div.append($('<img/>', {src: item.original.avatar}));
  8. div.append($('<span/>', {class: 'name'}).text(item.original.name));
  9. if (item.original.fullname && item.original.fullname !== '') {
  10. div.append($('<span/>', {class: 'fullname'}).text(item.original.fullname));
  11. }
  12. return div.html();
  13. }
  14. }) : null;
  15. export const emojiTribute = window.config.Tribute ? new Tribute({
  16. collection: [{
  17. trigger: ':',
  18. requireLeadingSpace: true,
  19. values(query, cb) {
  20. const matches = [];
  21. for (const name of emojiKeys) {
  22. if (name.includes(query)) {
  23. matches.push(name);
  24. if (matches.length > 5) break;
  25. }
  26. }
  27. cb(matches);
  28. },
  29. lookup(item) {
  30. return item;
  31. },
  32. selectTemplate(item) {
  33. if (typeof item === 'undefined') return null;
  34. return emojiString(item.original);
  35. },
  36. menuItemTemplate(item) {
  37. return `<div class="tribute-item">${emojiHTML(item.original)}<span>${item.original}</span></div>`;
  38. }
  39. }]
  40. }) : null;
  41. export function initTribute() {
  42. if (!window.config.Tribute) return;
  43. let content = document.getElementById('content');
  44. if (content !== null) {
  45. issuesTribute.attach(content);
  46. }
  47. const emojiInputs = document.querySelectorAll('.emoji-input');
  48. if (emojiInputs.length > 0) {
  49. emojiTribute.attach(emojiInputs);
  50. }
  51. content = document.getElementById('content');
  52. if (content !== null) {
  53. emojiTribute.attach(document.getElementById('content'));
  54. }
  55. }