template.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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('template', function(K) {
  10. var self = this, name = 'template', lang = self.lang(name + '.'),
  11. htmlPath = self.pluginsPath + name + '/html/';
  12. function getFilePath(fileName) {
  13. return htmlPath + fileName + '?ver=' + encodeURIComponent(K.DEBUG ? K.TIME : K.VERSION);
  14. }
  15. self.clickToolbar(name, function() {
  16. var lang = self.lang(name + '.'),
  17. arr = ['<div style="padding:10px 20px;">',
  18. '<div class="ke-header">',
  19. // left start
  20. '<div class="ke-left">',
  21. lang. selectTemplate + ' <select>'];
  22. K.each(lang.fileList, function(key, val) {
  23. arr.push('<option value="' + key + '">' + val + '</option>');
  24. });
  25. html = [arr.join(''),
  26. '</select></div>',
  27. // right start
  28. '<div class="ke-right">',
  29. '<input type="checkbox" id="keReplaceFlag" name="replaceFlag" value="1" /> <label for="keReplaceFlag">' + lang.replaceContent + '</label>',
  30. '</div>',
  31. '<div class="ke-clearfix"></div>',
  32. '</div>',
  33. '<iframe class="ke-textarea" frameborder="0" style="width:458px;height:260px;background-color:#FFF;"></iframe>',
  34. '</div>'].join('');
  35. var dialog = self.createDialog({
  36. name : name,
  37. width : 500,
  38. title : self.lang(name),
  39. body : html,
  40. yesBtn : {
  41. name : self.lang('yes'),
  42. click : function(e) {
  43. var doc = K.iframeDoc(iframe);
  44. self[checkbox[0].checked ? 'html' : 'insertHtml'](doc.body.innerHTML).hideDialog().focus();
  45. }
  46. }
  47. });
  48. var selectBox = K('select', dialog.div),
  49. checkbox = K('[name="replaceFlag"]', dialog.div),
  50. iframe = K('iframe', dialog.div);
  51. checkbox[0].checked = true;
  52. iframe.attr('src', getFilePath(selectBox.val()));
  53. selectBox.change(function() {
  54. iframe.attr('src', getFilePath(this.value));
  55. });
  56. });
  57. });