plainpaste.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. KindEditor.plugin('plainpaste', function(K) {
  10. var self = this, name = 'plainpaste';
  11. self.clickToolbar(name, function() {
  12. var lang = self.lang(name + '.'),
  13. html = '<div style="padding:10px 20px;">' +
  14. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  15. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>' +
  16. '</div>',
  17. dialog = self.createDialog({
  18. name : name,
  19. width : 450,
  20. title : self.lang(name),
  21. body : html,
  22. yesBtn : {
  23. name : self.lang('yes'),
  24. click : function(e) {
  25. var html = textarea.val();
  26. html = K.escape(html);
  27. html = html.replace(/ {2}/g, ' &nbsp;');
  28. if (self.newlineTag == 'p') {
  29. html = html.replace(/^/, '<p>').replace(/$/, '</p>').replace(/\n/g, '</p><p>');
  30. } else {
  31. html = html.replace(/\n/g, '<br />$&');
  32. }
  33. self.insertHtml(html).hideDialog().focus();
  34. }
  35. }
  36. }),
  37. textarea = K('textarea', dialog.div);
  38. textarea[0].focus();
  39. });
  40. });