Jforum使用FCKeditor的两种方法

来源:互联网 发布:papi酱起诉被驳回知乎 编辑:程序博客网 时间:2024/05/29 10:30

Jforum论坛使用在线编辑器很不直观,如果字符加了修饰,要发表后才能看到效果,不能所见即所得,很不shuan,

Jforum使用FCKeditor的两种方法:

把FCKeditor下载解压到项目中,

1,使用java调用jspTag自定义标签创建fckeditor,这种方法要在java代码里引入fck,


首先在JForum.java引入包:

import freemarker.ext.jsp.TaglibFactory;
import freemarker.ext.servlet.FreemarkerServlet;
import freemarker.ext.servlet.HttpRequestHashModel;
import freemarker.ext.servlet.ServletContextHashModel;
import freemarker.template.DefaultObjectWrapper;


然后在JForum.java的207行加入下面代码

/****************
* add by dyhjjk 支持用户自定义标签*/
 
// include the context variables to enable Freemarker custom tag support   
context.put(FreemarkerServlet.KEY_JSP_TAGLIBS, new TaglibFactory(this.getServletContext()));   
DefaultObjectWrapper wrapper = new DefaultObjectWrapper();   
context.put(FreemarkerServlet.KEY_APPLICATION, new ServletContextHashModel(this, wrapper));   
context.put(FreemarkerServlet.KEY_REQUEST, new HttpRequestHashModel(req, res, wrapper));   

页面中创建FCKeditor:

在post_form.htm的368行加入下面代码:

<#assign tmp="">
<#function bb>
<#if post?exists>
<#if quote?exists>
<#assign tmp="[quote="+quoteUser+"]"+post.text?html+"[/quote]">
<#else>
<#assign tmp=post.text?html>
</#if></#if>
<#return tmp>
</#function>
<@FCK.editor instanceName="message" height="300" toolbarSet="bbcode" value="${bb()}">
</@FCK.editor>

再把原先的BB_code删除掉;


2,第二种方法比较简单,

首先在post_form.htm中引入FCKeditor.js文件;用js创建FCKeditor,在post_form.htm添加下面代码:

window.onload=function(){
var fckEditor=new FCKeditor('message');
fckEditor.BasePath='${contextPath}/jforum/fckeditor_2.6.6/';
fckEditor.ToolbarSet="bbcode";
fckEditor.Width="100%";
fckEditor.Height="430";
fckEditor.ToolbarStartExpanded=false;
fckEditor.ReplaceTextarea();
}

在fckconfig.js中加入自定义工具栏:

FCKConfig.ToolbarSets["bbcode"] = [
['Source', 'Cut', 'Copy', 'Paste', 'PasteText', 'PasteWord'],
['FitWindow', 'ShowBlocks', '-', 'About'],
['Undo', 'Redo', '-', 'SelectAll', 'RemoveFormat'],
'/',
['Bold', 'Italic', 'Underline'],
['OrderedList', 'UnorderedList', '-', 'Outdent'],
['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyFull'],
['Link', 'Unlink'],
['Image','Smiley','Rule'],
['TextColor', 'BGColor']
];

上面是发表文章用的,用FCKeditor保存数据后,显示的时候不正常,因为JForum原来是用BB_CODE在表示的,

如加粗标签用[b][/b]表示,和html标签不一样,所以在显示的时候,在PostCommon.java中做了处理,现在用FCKeditor

来编辑,保存的数据标签和html标签一致,所以不需要做转化了,可以在PostCommon函数入口直接return掉,就ok

0 0