使用集成的php输出kindeditor无法初始化
function showEditor($id, $value='', $width='700px', $height='300px', $style='visibility:hidden;',$upload_state="true", $media_open=false, $type='all'){ //是否开启多媒体 $media = ''; if ($media_open){ $media = ", 'flash', 'media'"; } switch($type) { case 'basic': $items = "['source', '|', 'fullscreen', 'undo', 'redo', 'cut', 'copy', 'paste', '|', 'about']"; break; case 'simple': $items = "['source', '|', 'fullscreen', 'undo', 'redo', 'cut', 'copy', 'paste', '|', 'fontname', 'fontsize', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline', 'removeformat', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist', 'insertunorderedlist', '|', 'emoticons', 'image', 'link', '|', 'about']"; break; default: $items = "['source', '|', 'fullscreen', 'undo', 'redo', 'print', 'cut', 'copy', 'paste', 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript', 'superscript', '|', 'selectall', 'clearhtml','quickformat','|', 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image'".$media.", 'table', 'hr', 'emoticons', 'link', 'unlink', '|', 'about']"; break; } //图片、Flash、视频、文件的本地上传都可开启。默认只有图片,要启用其它的需要修改resource\kindeditor\php下的upload_json.php的相关参数 echo '<textarea id="'. $id .'" name="'. $id .'" style="width:'. $width .';height:'. $height .';'. $style .'">'.$value.'</textarea>'; echo '<script src="'. RESOURCE_SITE_URL .'/kindeditor/kindeditor-min.js" charset="utf-8"></script>'; echo ' <script src="'. RESOURCE_SITE_URL .'/kindeditor/kindeditor-min.js" charset="utf-8"></script> <script src="'. RESOURCE_SITE_URL .'/kindeditor/lang/zh_CN.js" charset="utf-8"></script> <script> var KE; KindEditor.ready(function(K) { KE = K.create("textarea[name=\''.$id.'\']", { items : '.$items.', cssPath : "' . RESOURCE_SITE_URL . '/kindeditor/themes/default/default.css", allowImageUpload : '.$upload_state.', allowFlashUpload : false, allowMediaUpload : false, allowFileManager : false, syncType:"form", afterCreate : function() { var self = this; self.sync(); }, afterChange : function() { var self = this; self.sync(); }, afterBlur : function() { var self = this; self.sync(); } }); KE.appendHtml = function(id,val) { this.html(this.html() + val); if (this.isCreated) { var cmd = this.cmd; cmd.range.selectNodeContents(cmd.doc.body).collapse(false); cmd.select(); } return this; } }); </script> '; return true; }
页面直接引用php <?php showEditor('content');?>发现无法初始化
后来发现 异步加载主要的问题是KindEditor.ready无法执行,修改在页面上引用即可
<script src="<?php echo RESOURCE_SITE_URL.DS.'kindeditor/kindeditor-min.js';?>" charset="utf-8"></script> <script src="<?php echo RESOURCE_SITE_URL.DS.'kindeditor/lang/zh_CN.js';?>" charset="utf-8"></script> <script> KindEditor.basePath = '/data/resource/kindeditor/'; KindEditor.create("#file_content", { items : ['source', '|', 'fullscreen', 'undo', 'redo', 'print', 'cut', 'copy', 'paste', 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript', 'superscript', '|', 'selectall', 'clearhtml','quickformat','|', 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'table', 'hr', 'emoticons', 'link', 'unlink', '|', 'about'], //cssPath : "<?php echo RESOURCE_SITE_URL.DS.'kindeditor/themes/default/default.css';?>", allowImageUpload : true, allowFlashUpload : false, allowMediaUpload : false, allowFileManager : false, syncType:"form", afterCreate : function() { var self = this; self.sync(); }, afterChange : function() { var self = this; self.sync(); }, afterBlur : function() { var self = this; self.sync(); } }); KindEditor.appendHtml = function(id,val) { this.html(this.html() + val); if (this.isCreated) { var cmd = this.cmd; cmd.range.selectNodeContents(cmd.doc.body).collapse(false); cmd.select(); } return this; } </script>
参考:http://www.cnblogs.com/zuri/p/6846866.html
http://kindeditor.net/view.php?bbsid=4&postid=6206