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.

147 lines
4.8KB

  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 : 'PowerQuery', value : 'powerquery' },
  69. { text : 'PowerShell', value : 'powershell' },
  70. { text : 'Python', value : 'python' },
  71. { text : 'R', value : 'r' },
  72. { text : 'Ruby', value : 'ruby' },
  73. { text : 'Rust', value : 'rust' },
  74. { text : 'SASS', value : 'sass' },
  75. { text : 'Scala', value : 'scala' },
  76. { text : 'SCSS', value : 'scss' },
  77. { text : 'Shell Session', value : 'shell-session' },
  78. { text : 'Solidity', value : 'solidity' },
  79. { text : 'Splunk SPL', value : 'splunk-spl' },
  80. { text : 'SQL', value : 'sql' },
  81. { text : 'Swift', value : 'swift' },
  82. { text : 'TSX', value : 'tsx' },
  83. { text : 'Twig', value : 'twig' },
  84. { text : 'TypeScript', value : 'typescript' },
  85. { text : 'Visual Basic', value : 'visual-basic' },
  86. { text : 'YAML', value : 'yaml' },
  87. ],
  88. onselect : function() {
  89. code.language = this.value();
  90. },
  91. },
  92. {
  93. type : 'textbox',
  94. name : 'snippet',
  95. placeholder : 'Add Code Here',
  96. value : '',
  97. minWidth : 400,
  98. minHeight : 300,
  99. multiline : true,
  100. value : code.snippet,
  101. oninput : function() {
  102. code.snippet = this.value();
  103. }
  104. }
  105. ],
  106. onsubmit : function() {
  107. ed.insertContent('<pre><code class="language-'+ code.language +'">'+ tinymce.DOM.encode(code.snippet) + '</code></pre>');
  108. }
  109. });
  110. }
  111. });
  112. },
  113. createControl : function(n, cm) {
  114. return null;
  115. },
  116. });
  117. tinymce.PluginManager.add('prismatic_buttons', tinymce.plugins.PrismaticButtons);
  118. })();