<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>KindEditor Examples</title>
<style>
.ke-tabs-example li {
padding: 0 5px;
}
.ke-icon-example1 {
background-image: url(../skins/default/default.gif);
background-position: 0px -672px;
width: 16px;
height: 16px;
}
.ke-icon-example2 {
background-image: url(../skins/default/default.gif);
background-position: 0px -672px;
width: 16px;
height: 16px;
}
</style>
<link rel="stylesheet" href="../themes/default/default.css" />
<link rel="stylesheet" href="../themes/simple/simple.css" />
<script charset="utf-8" src="../kindeditor-min.js"></script>
<script charset="utf-8" src="../lang/zh_CN.js"></script>
<script>
// 自定义插件 #1
KindEditor.lang({
example1 : '插入HTML'
});
KindEditor.plugin('example1', function(K) {
var self = this, name = 'example1';
self.clickToolbar(name, function() {
self.insertHtml('<strong>测试内容</strong>');
});
});
// 自定义插件 #2
KindEditor.lang({
example2 : 'CLASS样式'
});
KindEditor.plugin('example2', function(K) {
var self = this, name = 'example2';
function click(value) {
var cmd = self.cmd;
if (value === 'adv_strikethrough') {
cmd.wrap('<span style="background-color:#e53333;text-decoration:line-through;"></span>');
} else {
cmd.wrap('<span class="' + value + '"></span>');
}
cmd.select();
self.hideMenu();
}
self.clickToolbar(name, function() {
var menu = self.createMenu({
name : name,
width : 150
});
menu.addItem({
title : '红底白字',
click : function() {
click('red');
}
});
menu.addItem({
title : '绿底白字',
click : function() {
click('green');
}
});
menu.addItem({
title : '黄底白字',
click : function() {
click('yellow');
}
});
menu.addItem({
title : '自定义删除线',
click : function() {
click('adv_strikethrough');
}
});
});
});
function getParam(url, name) {
return url.match(new RegExp('[?&]' + name + '=([^?&]+)', 'i')) ? unescape(RegExp.$1) : '';
}
KindEditor.ready(function(K) {
var tabTitleList = ['默认模式', '简单模式', '异步加载', '多语言', '只读模式', '回车换行设置', '统计字数', 'HTML过滤', 'URL设置', '自定义风格', '自定义插件'];
var optionMap = {
'content0' : {
cssPath : '../plugins/code/prettify.css',
allowFileManager : true
},
'content1' : {
cssPath : '../plugins/code/prettify.css',
resizeType : 1,
allowPreviewEmoticons : false,
allowImageUpload : false,
items : [
'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
'insertunorderedlist', '|', 'emoticons', 'image', 'link']
},
'content2' : {
cssPath : '../plugins/code/prettify.css',
basePath : '../'
},
'content3' : {
cssPath : '../plugins/code/prettify.css',
langType : 'en'
},
'content4' : {
cssPath : '../plugins/code/prettify.css',
readonlyMode : true
},
'content5' : {
cssPath : '../plugins/code/prettify.css',
newlineTag : 'br'
},
'content6' : {
cssPath : '../plugins/code/prettify.css',
afterChange : function() {
K('#tab6 .word_count1').html(this.count());
K('#tab6 .word_count2').html(this.count('text'));
}
},
'content7' : {
cssPath : '../plugins/code/prettify.css',
filterMode : true
},
'content8' : {
cssPath : '../plugins/code/prettify.css',
urlType : ''
},
'content9' : {
cssPath : '../plugins/code/prettify.css',
themeType : 'simple'
},
'content10' : {
cssPath : ['../plugins/code/prettify.css', 'index.css'],
items : ['source', 'removeformat', 'example1', 'example2']
}
};
var editor = null;
var tabs = K.tabs({
src : K('#tabs'),
cls : 'ke-tabs-example',
afterSelect : function(i) {
if (editor) {
editor.remove();
editor = null;
}
if (i == 2) {
return;
}
editor = K.create('#tab' + i + ' textarea[name=content]', optionMap['content' + i]);
}
});
K.each(tabTitleList, function(i, title) {
tabs.add({
title : title,
panel : K('#tab' + i)
});
})
var index = parseInt(getParam(location.href, 'tab') || 0, 10);
tabs.select(index);
K('#tab' + index).show();
K('#tab0 input[name=getHtml]').click(function(e) {
alert(editor.html());
});
K('#tab0 input[name=isEmpty]').click(function(e) {
alert(editor.isEmpty());
});
K('#tab0 input[name=getText]').click(function(e) {
alert(editor.text());
});
K('#tab0 input[name=selectedHtml]').click(function(e) {
alert(editor.selectedHtml());
});
K('#tab0 input[name=setHtml]').click(function(e) {
editor.html('<h3>Hello KindEditor</h3>');
});
K('#tab0 input[name=setText]').click(function(e) {
editor.text('<h3>Hello KindEditor</h3>');
});
K('#tab0 input[name=insertHtml]').click(function(e) {
editor.insertHtml('<strong>插入HTML</strong>');
});
K('#tab0 input[name=appendHtml]').click(function(e) {
editor.appendHtml('<strong>添加HTML</strong>');
});
K('#tab0 input[name=clear]').click(function(e) {
editor.html('');
});
K('#tab2 input[name=load]').click(function() {
K.loadScript('../kindeditor.js', function() {
editor = K.create('#tab2 textarea', optionMap.content2);
});
});
K('#tab2 input[name=remove]').click(function() {
if (editor) {
editor.remove();
editor = null;
}
});
K('#tab3 select[name=lang]').change(function() {
if (editor) {
editor.remove();
editor = null;
}
optionMap.content3.langType = this.value;
editor = K.create('#tab3 textarea', optionMap.content3);
});
K('#tab4 input[name=readonly]').click(function() {
editor.readonly();
});
K('#tab4 input[name=cancel]').click(function() {
editor.readonly(false);
});
K('#tab5 select[name=newlineTag]').change(function() {
if (editor) {
editor.remove();
editor = null;
}
optionMap.content5.newlineTag = this.value;
editor = K.create('#tab5 textarea', optionMap.content5);
});
K('#tab8 select[name=urlType]').change(function() {
if (editor) {
editor.remove();
editor = null;
}
optionMap.content8.urlType = this.value;
editor = K.create('#tab8 textarea', optionMap.content8);
});
K('#tab9 select[name=themeType]').change(function() {
if (editor) {
editor.remove();
editor = null;
}
optionMap.content9.themeType = this.value;
editor = K.create('#tab9 textarea', optionMap.content9);
});
});
</script>
</head>
<body>
<div id="tabs"></div>
<!-- 默认模式 -->
<div id="tab0" style="display:none;">
<form>
<textarea name="content" style="width:800px;height:400px;visibility:hidden;">
<p>
引入文件:
</p>
<pre class="prettyprint">
&lt;link rel="stylesheet" href="../themes/default/default.css" /&gt;
&lt;script charset="utf-8" src="../kindeditor.js"&gt;&lt;/script&gt;
&lt;script charset="utf-8" src="../lang/zh_CN.js"&gt;&lt;/script&gt;
</pre>
<p>
JavaScript代码:
</p>
<pre class="prettyprint">