trumbowyg.ruby.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. en: {
  15. ruby: 'Add ruby text',
  16. rubyModal: 'Ruby modal',
  17. rubyText: 'Ruby text'
  18. },
  19. da: {
  20. ruby: 'Tilføj ruby tekst',
  21. rubyModal: 'Ruby modal',
  22. rubyText: 'Ruby tekst'
  23. },
  24. fr: {
  25. ruby: 'Ajouter du texte ruby',
  26. rubyModal: 'Modale ruby',
  27. rubyText: 'Texte ruby'
  28. },
  29. id: {
  30. ruby: 'Sisipkan teks ruby',
  31. rubyModal: 'Modal teks ruby',
  32. rubyText: 'Teks ruby'
  33. },
  34. tr: {
  35. ruby: 'Ruby metni ekle',
  36. rubyModal: 'Ruby modal',
  37. rubyText: 'Ruby metni'
  38. },
  39. zh_tw: {
  40. ruby: '加入 ruby 文字',
  41. rubyModal: 'Ruby 彈跳視窗',
  42. rubyText: 'Ruby 文字'
  43. },
  44. },
  45. plugins: {
  46. ruby: {
  47. init: function (trumbowyg) {
  48. var btnDef = {
  49. fn: function () {
  50. trumbowyg.saveRange();
  51. trumbowyg.openModalInsert(
  52. trumbowyg.lang.ruby,
  53. {
  54. rubyText: {
  55. label: trumbowyg.lang.rubyText,
  56. required: false,
  57. },
  58. modal: {
  59. label: trumbowyg.lang.rubyModal,
  60. value: trumbowyg.getRangeText(),
  61. required: true
  62. }
  63. },
  64. function (v) {
  65. var node = $('<ruby title="' + v.rubyText + '">' + v.modal + '<rp> (</rp><rt>' + v.rubyText + '</rt><rp>)</rp></ruby>')[0];
  66. trumbowyg.range.deleteContents();
  67. trumbowyg.range.insertNode(node);
  68. trumbowyg.syncCode();
  69. trumbowyg.$c.trigger('tbwchange');
  70. return true;
  71. }
  72. );
  73. }
  74. };
  75. trumbowyg.addBtnDef('ruby', btnDef);
  76. }
  77. }
  78. }
  79. });
  80. })(jQuery);