trumbowyg.ruby.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* ===========================================================
  2. * trumbowyg.ruby.js v1.0
  3. * Ruby text plugin for Trumbowyg
  4. * http://alex-d.github.com/Trumbowyg
  5. * ===========================================================
  6. * Author : Fathi Anshory (0x00000F5C)
  7. * Twitter : @fscchannl
  8. * Comment : Since I use trumbowyg in my project and required it to insert ruby text, so I thought I can contribute a little. :D
  9. */
  10. (function ($) {
  11. 'use strict';
  12. $.extend(true, $.trumbowyg, {
  13. langs: {
  14. // jshint camelcase:false
  15. en: {
  16. ruby: 'Add ruby text',
  17. rubyModal: 'Ruby modal',
  18. rubyText: 'Ruby text'
  19. },
  20. da: {
  21. ruby: 'Tilføj ruby tekst',
  22. rubyModal: 'Ruby modal',
  23. rubyText: 'Ruby tekst'
  24. },
  25. fr: {
  26. ruby: 'Ajouter du texte ruby',
  27. rubyModal: 'Modale ruby',
  28. rubyText: 'Texte ruby'
  29. },
  30. hu: {
  31. ruby: 'Ruby szöveg hozzáadás',
  32. rubyModal: 'Ruby modal',
  33. rubyText: 'Ruby szöveg'
  34. },
  35. id: {
  36. ruby: 'Sisipkan teks ruby',
  37. rubyModal: 'Modal teks ruby',
  38. rubyText: 'Teks ruby'
  39. },
  40. ko: {
  41. ruby: '루비 문자 넣기',
  42. rubyModal: '대상 문자',
  43. rubyText: '루비 문자'
  44. },
  45. pt_br: {
  46. ruby: 'Adicionar texto ruby',
  47. rubyModal: 'Modal ruby',
  48. rubyText: 'Texto ruby'
  49. },
  50. tr: {
  51. ruby: 'Ruby metni ekle',
  52. rubyModal: 'Ruby modal',
  53. rubyText: 'Ruby metni'
  54. },
  55. zh_tw: {
  56. ruby: '加入 ruby 文字',
  57. rubyModal: 'Ruby 彈跳視窗',
  58. rubyText: 'Ruby 文字'
  59. },
  60. // jshint camelcase:true
  61. },
  62. plugins: {
  63. ruby: {
  64. init: function (trumbowyg) {
  65. var btnDef = {
  66. fn: function () {
  67. trumbowyg.saveRange();
  68. trumbowyg.openModalInsert(
  69. trumbowyg.lang.ruby,
  70. {
  71. rubyText: {
  72. label: trumbowyg.lang.rubyText,
  73. required: false,
  74. },
  75. modal: {
  76. label: trumbowyg.lang.rubyModal,
  77. value: trumbowyg.getRangeText(),
  78. required: true
  79. }
  80. },
  81. function (v) {
  82. var node = $('<ruby title="' + v.rubyText + '">' + v.modal + '<rp> (</rp><rt>' + v.rubyText + '</rt><rp>)</rp></ruby>')[0];
  83. trumbowyg.range.deleteContents();
  84. trumbowyg.range.insertNode(node);
  85. trumbowyg.syncCode();
  86. trumbowyg.$c.trigger('tbwchange');
  87. return true;
  88. }
  89. );
  90. }
  91. };
  92. trumbowyg.addBtnDef('ruby', btnDef);
  93. }
  94. }
  95. }
  96. });
  97. })(jQuery);