template.js 2.5 KB

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