1
0

trumbowyg.mention.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /* ===========================================================
  2. * trumbowyg.mention.js v0.1
  3. * Mention plugin for Trumbowyg
  4. * http://alex-d.github.com/Trumbowyg
  5. * ===========================================================
  6. * Author : Viper
  7. * Github: https://github.com/Globulopolis
  8. * Website: http://киноархив.com
  9. */
  10. (function ($) {
  11. 'use strict';
  12. var defaultOptions = {
  13. source: [],
  14. formatDropdownItem: formatDropdownItem,
  15. formatResult: formatResult
  16. };
  17. $.extend(true, $.trumbowyg, {
  18. langs: {
  19. // jshint camelcase:false
  20. en: {
  21. mention: 'Mention'
  22. },
  23. da: {
  24. mention: 'Nævn'
  25. },
  26. fr: {
  27. mention: 'Mentionner'
  28. },
  29. hu: {
  30. mention: 'Említ'
  31. },
  32. ko: {
  33. mention: '언급'
  34. },
  35. pt_br: {
  36. mention: 'Menção'
  37. },
  38. ru: {
  39. mention: 'Упомянуть'
  40. },
  41. tr: {
  42. mention: 'Bahset'
  43. },
  44. zh_tw: {
  45. mention: '標記'
  46. },
  47. // jshint camelcase:true
  48. },
  49. plugins: {
  50. mention: {
  51. init: function (trumbowyg) {
  52. trumbowyg.o.plugins.mention = $.extend(true, {}, defaultOptions, trumbowyg.o.plugins.mention || {});
  53. var btnDef = {
  54. dropdown: buildDropdown(trumbowyg.o.plugins.mention.source, trumbowyg)
  55. };
  56. trumbowyg.addBtnDef('mention', btnDef);
  57. }
  58. }
  59. }
  60. });
  61. /**
  62. * Build dropdown list
  63. *
  64. * @param {Array} items Items
  65. * @param {object} trumbowyg Editor
  66. *
  67. * @return {Array}
  68. */
  69. function buildDropdown(items, trumbowyg) {
  70. var dropdown = [];
  71. $.each(items, function (i, item) {
  72. var btn = 'mention-' + i,
  73. btnDef = {
  74. hasIcon: false,
  75. text: trumbowyg.o.plugins.mention.formatDropdownItem(item),
  76. fn: function () {
  77. trumbowyg.execCmd('insertHTML', trumbowyg.o.plugins.mention.formatResult(item));
  78. return true;
  79. }
  80. };
  81. trumbowyg.addBtnDef(btn, btnDef);
  82. dropdown.push(btn);
  83. });
  84. return dropdown;
  85. }
  86. /**
  87. * Format item in dropdown.
  88. *
  89. * @param {object} item Item object.
  90. *
  91. * @return {string}
  92. */
  93. function formatDropdownItem(item) {
  94. return item.login;
  95. }
  96. /**
  97. * Format result pasted in editor.
  98. *
  99. * @param {object} item Item object.
  100. *
  101. * @return {string}
  102. */
  103. function formatResult(item) {
  104. return '@' + item.login + ' ';
  105. }
  106. })(jQuery);