kindeditor.html.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php if($extView = $this->getExtViewFile(__FILE__)){include $extView; return helper::cd();}?>
  2. <?php
  3. $module = $this->moduleName;
  4. $method = $this->methodName;
  5. if(!isset($config->$module->editor->$method)) return;
  6. $editor = $config->$module->editor->$method;
  7. $editor['id'] = explode(',', $editor['id']);
  8. $editorLangs = array('en' => 'en', 'zh-cn' => 'zh_CN', 'zh-tw' => 'zh_TW', 'ja' => 'ja');
  9. $editorLang = isset($editorLangs[$app->getClientLang()]) ? $editorLangs[$app->getClientLang()] : 'en';
  10. /* set uid for upload. */
  11. $uid = uniqid('');
  12. ?>
  13. <?php js::import($jsRoot . 'kindeditor/kindeditor.min.js'); ?>
  14. <script src='<?php echo $jsRoot;?>kindeditor/plugins/holder/holder.js'></script>
  15. <?php js::import($jsRoot . "kindeditor/lang/{$editorLang}.js");?>
  16. <script>
  17. (function($) {
  18. var kuid = '<?php echo $uid;?>';
  19. var editor = <?php echo json_encode($editor);?>;
  20. var K = KindEditor;
  21. var measurementTools =
  22. [ 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic','underline', '|',
  23. 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist', 'insertunorderedlist', '|',
  24. 'emoticons', 'image', 'code', 'link', 'table', '|', 'removeformat','undo', 'redo', 'fullscreen', 'source', 'about', 'holder'];
  25. var bugTools =
  26. [ 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic','underline', '|',
  27. 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist', 'insertunorderedlist', '|',
  28. 'emoticons', 'image', 'code', 'link', '|', 'removeformat','undo', 'redo', 'fullscreen', 'source', 'about'];
  29. var simpleTools =
  30. [ 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic','underline', '|',
  31. 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist', 'insertunorderedlist', '|',
  32. 'emoticons', 'image', 'code', 'link', 'table', '|', 'removeformat','undo', 'redo', 'fullscreen', 'source', 'about'];
  33. var fullTools =
  34. [ 'formatblock', 'fontname', 'fontsize', 'lineheight', '|', 'forecolor', 'hilitecolor', '|', 'bold', 'italic','underline', 'strikethrough', '|',
  35. 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', '|',
  36. 'insertorderedlist', 'insertunorderedlist', '|',
  37. 'emoticons', 'image', 'insertfile', 'hr', '|', 'link', 'unlink', '/',
  38. 'undo', 'redo', '|', 'selectall', 'cut', 'copy', 'paste', '|', 'plainpaste', 'wordpaste', '|', 'removeformat', 'clearhtml','quickformat', '|',
  39. 'indent', 'outdent', 'subscript', 'superscript', '|',
  40. 'table', 'code', '|', 'pagebreak', 'anchor', '|',
  41. 'fullscreen', 'source', 'preview', 'about'];
  42. var docTools =
  43. [ 'formatblock', 'fontname', 'fontsize', 'lineheight', '|', 'forecolor', 'hilitecolor', '|', 'bold', 'italic','underline', 'strikethrough', '|',
  44. 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', '|',
  45. 'insertorderedlist', 'insertunorderedlist', '|',
  46. 'emoticons', 'image', 'hr', '|', 'link', '|',
  47. 'undo', 'redo', '|', 'selectall', 'cut', 'copy', 'paste', '|', 'plainpaste', 'wordpaste', '|', 'removeformat', 'clearhtml','quickformat', '|',
  48. 'indent', 'outdent', 'subscript', 'superscript', '|',
  49. 'table', 'code', 'pagebreak',
  50. 'source'];
  51. var editorToolsMap = {fullTools: fullTools, simpleTools: simpleTools, bugTools: bugTools, measurementTools: measurementTools, docTools: docTools};
  52. // Kindeditor default options
  53. var editorDefaults =
  54. {
  55. cssPath: [config.themeRoot + 'zui/css/min.css'],
  56. width: '100%',
  57. height: '200px',
  58. filterMode: true,
  59. bodyClass: 'article-content',
  60. urlType: 'absolute',
  61. uploadJson: createLink('file', 'ajaxUpload', 'uid=' + kuid),
  62. allowFileManager: true,
  63. langType: '<?php echo $editorLang?>',
  64. cssData: 'html,body {background: none}.article-content{overflow:visible}.article-content, .article-content table td, .article-content table th {line-height: 1.3846153846; font-size: 13px;}.article-content .table-auto {width: auto!important; max-width: 100%;}',
  65. placeholderStyle: {fontSize: '13px', color: '#888'},
  66. pasteImage: {postUrl: createLink('file', 'ajaxPasteImg', 'uid=' + kuid), placeholder: <?php echo json_encode($lang->noticePasteImg);?>},
  67. syncAfterBlur: true,
  68. spellcheck: false
  69. };
  70. window.editor = {};
  71. // Init kindeditor
  72. var setKindeditor = function(element, options)
  73. {
  74. var $editor = $(element);
  75. var pasted = false;
  76. var editorID = $editor.attr('id');
  77. options = $.extend({}, editorDefaults, $editor.data(), options);
  78. if(editorID === undefined)
  79. {
  80. editorID = 'kindeditor-' + $.zui.uuid();
  81. $editor.attr('id', editorID);
  82. }
  83. var editorTool = editorToolsMap[options.tools || editor.tools] || simpleTools;
  84. /* Remove fullscreen in modal. */
  85. if(config.onlybody == 'yes')
  86. {
  87. var newEditorTool = new Array();
  88. for(i in editorTool)
  89. {
  90. if(editorTool[i] != 'fullscreen') newEditorTool.push(editorTool[i]);
  91. }
  92. editorTool = newEditorTool;
  93. }
  94. $.extend(options,
  95. {
  96. holderEditText: '<?php echo $this->lang->edit?>', // 设置 holder 鼠标悬停时的提示编辑文本
  97. holderEdit: true, // 启用编辑 holder 功能
  98. items: editorTool,
  99. placeholder: $editor.attr('placeholder') || options.placeholder || '',
  100. pasteImage: {postUrl: createLink('file', 'ajaxPasteImg', 'uid=' + kuid), placeholder: $editor.attr('placeholder') || <?php echo json_encode($lang->noticePasteImg);?>},
  101. });
  102. try
  103. {
  104. var keditor = K.create('#' + editorID, options);
  105. window.editor['#'] = window.editor[editorID] = keditor;
  106. $editor.data('keditor', keditor);
  107. return keditor;
  108. }
  109. catch(e){return false;}
  110. };
  111. // Init kindeditor with jquery way
  112. $.fn.kindeditor = function(options)
  113. {
  114. return this.each(function()
  115. {
  116. setKindeditor(this, options);
  117. });
  118. };
  119. // Init all kindeditor
  120. var initKindeditor = function(afterInit)
  121. {
  122. var $submitBtn = $('form :input[type=submit]');
  123. if($submitBtn.length)
  124. {
  125. $submitBtn.next('#uid').remove();
  126. $submitBtn.after("<input type='hidden' id='uid' name='uid' value=" + kuid + ">");
  127. }
  128. if($.isFunction(afterInit)) afterInit();
  129. $.each(editor.id, function(key, editorID)
  130. {
  131. setKindeditor('#' + editorID);
  132. });
  133. };
  134. // Init all kindeditors when document is ready
  135. $(initKindeditor);
  136. }(jQuery));
  137. </script>