code.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. });