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.

139 lines
4.6KB

  1. /* Prismatic - TinyMCE Buttons for Prism.js */
  2. (function() {
  3. 'use strict';
  4. tinymce.create('tinymce.plugins.PrismaticButtons', {
  5. init : function(ed, url) {
  6. ed.addButton('button_prism', {
  7. title : 'Add Prism.js code',
  8. icon : 'code',
  9. onclick : function() {
  10. var code = {
  11. language : '',
  12. snippet : ''
  13. };
  14. ed.windowManager.open({
  15. title : 'Add Prism.js code',
  16. tooltip : 'Add Prism.js code',
  17. minWidth : 400,
  18. minHeight : 300,
  19. body : [
  20. {
  21. type : 'listbox',
  22. name : 'language',
  23. value : '',
  24. minWidth : 400,
  25. value : code.language,
  26. values : [
  27. { text : 'Language..', value : '' },
  28. { text : 'Apache', value : 'apacheconf' },
  29. { text : 'AppleScript', value : 'applescript' },
  30. { text : 'Arduino', value : 'arduino' },
  31. { text : 'Bash', value : 'bash' },
  32. { text : 'Batch', value : 'batch' },
  33. { text : 'C', value : 'c' },
  34. { text : 'C#', value : 'csharp' },
  35. { text : 'C++', value : 'cpp' },
  36. { text : 'C-like', value : 'clike' },
  37. { text : 'CoffeeScript', value : 'coffeescript' },
  38. { text : 'CSS', value : 'css' },
  39. { text : 'D', value : 'd' },
  40. { text : 'Dart', value : 'dart' },
  41. { text : 'Diff', value : 'diff' },
  42. { text : 'Elixir', value : 'elixir' },
  43. { text : 'G-code', value : 'gcode' },
  44. { text : 'Git', value : 'git' },
  45. { text : 'Go', value : 'go' },
  46. { text : 'GraphQL', value : 'graphql' },
  47. { text : 'Groovy', value : 'groovy' },
  48. { text : 'HTML', value : 'markup' },
  49. { text : 'HCL', value : 'hcl' },
  50. { text : 'HTTP', value : 'http' },
  51. { text : 'Ini', value : 'ini' },
  52. { text : 'Java', value : 'java' },
  53. { text : 'JavaScript', value : 'javascript' },
  54. { text : 'JSON', value : 'json' },
  55. { text : 'JSX', value : 'jsx' },
  56. { text : 'Kotlin', value : 'kotlin' },
  57. { text : 'LaTeX', value : 'latex' },
  58. { text : 'Liquid', value : 'liquid' },
  59. { text : 'Lua', value : 'lua' },
  60. { text : 'Makefile', value : 'makefile' },
  61. { text : 'Markdown', value : 'markdown' },
  62. { text : 'Markup', value : 'markup' },
  63. { text : 'NGINX', value : 'nginx' },
  64. { text : 'Objective-C', value : 'objectivec' },
  65. { text : 'Pascal', value : 'pascal' },
  66. { text : 'Perl', value : 'perl' },
  67. { text : 'PHP', value : 'php' },
  68. { text : 'PowerShell', value : 'powershell' },
  69. { text : 'Python', value : 'python' },
  70. { text : 'R', value : 'r' },
  71. { text : 'Ruby', value : 'ruby' },
  72. { text : 'Rust', value : 'rust' },
  73. { text : 'SASS', value : 'sass' },
  74. { text : 'Scala', value : 'scala' },
  75. { text : 'SCSS', value : 'scss' },
  76. { text : 'Shell Session', value : 'shell-session' },
  77. { text : 'Solidity', value : 'solidity' },
  78. { text : 'SQL', value : 'sql' },
  79. { text : 'Swift', value : 'swift' },
  80. { text : 'TSX', value : 'tsx' },
  81. { text : 'Twig', value : 'twig' },
  82. { text : 'TypeScript', value : 'typescript' },
  83. { text : 'Visual Basic', value : 'visual-basic' },
  84. { text : 'YAML', value : 'yaml' },
  85. ],
  86. onselect : function() {
  87. code.language = this.value();
  88. },
  89. },
  90. {
  91. type : 'textbox',
  92. name : 'snippet',
  93. placeholder : 'Add Code Here',
  94. value : '',
  95. minWidth : 400,
  96. minHeight : 300,
  97. multiline : true,
  98. value : code.snippet,
  99. oninput : function() {
  100. code.snippet = this.value();
  101. }
  102. }
  103. ],
  104. onsubmit : function() {
  105. ed.insertContent('<pre><code class="language-'+ code.language +'">'+ tinymce.DOM.encode(code.snippet) + '</code></pre>');
  106. }
  107. });
  108. }
  109. });
  110. },
  111. createControl : function(n, cm) {
  112. return null;
  113. },
  114. });
  115. tinymce.PluginManager.add('prismatic_buttons', tinymce.plugins.PrismaticButtons);
  116. })();