code.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*******************************************************************************
  2. * KindEditor - WYSIWYG HTML Editor for Internet
  3. * Copyright (C) 2006-2011 kindsoft.net
  4. *
  5. * @author Roddy <luolonghao@gmail.com>
  6. * @site http://www.kindsoft.net/
  7. * @licence http://www.kindsoft.net/license.php
  8. *******************************************************************************/
  9. // google code prettify: http://google-code-prettify.googlecode.com/
  10. // http://google-code-prettify.googlecode.com/
  11. KindEditor.plugin('code', function(K) {
  12. var self = this, name = 'code';
  13. self.clickToolbar(name, function() {
  14. var lang = self.lang(name + '.'),
  15. html = ['<div style="padding:10px 20px;">',
  16. '<div class="ke-dialog-row">',
  17. '<select class="ke-code-type">',
  18. '<option value="js">JavaScript</option>',
  19. '<option value="html">HTML</option>',
  20. '<option value="css">CSS</option>',
  21. '<option value="php">PHP</option>',
  22. '<option value="pl">Perl</option>',
  23. '<option value="py">Python</option>',
  24. '<option value="rb">Ruby</option>',
  25. '<option value="java">Java</option>',
  26. '<option value="vb">ASP/VB</option>',
  27. '<option value="cpp">C/C++</option>',
  28. '<option value="cs">C#</option>',
  29. '<option value="xml">XML</option>',
  30. '<option value="bsh">Shell</option>',
  31. '<option value="">Other</option>',
  32. '</select>',
  33. '</div>',
  34. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>',
  35. '</div>'].join(''),
  36. dialog = self.createDialog({
  37. name : name,
  38. width : 450,
  39. title : self.lang(name),
  40. body : html,
  41. yesBtn : {
  42. name : self.lang('yes'),
  43. click : function(e) {
  44. var type = K('.ke-code-type', dialog.div).val(),
  45. code = textarea.val(),
  46. cls = type === '' ? '' : ' lang-' + type,
  47. html = '<pre class="prettyprint' + cls + '">\n' + K.escape(code) + '</pre> ';
  48. if (K.trim(code) === '') {
  49. alert(lang.pleaseInput);
  50. textarea[0].focus();
  51. return;
  52. }
  53. self.insertHtml(html).hideDialog().focus();
  54. }
  55. }
  56. }),
  57. textarea = K('textarea', dialog.div);
  58. textarea[0].focus();
  59. });
  60. });