合元网络
标题:
门户文章发布编辑器增加一键排版功能
[打印本页]
作者:
admin
时间:
2016-10-15
标题:
门户文章发布编辑器增加一键排版功能
这个功能很实用!
如题,其实就是将网摘文章直接粘贴到发布文章编辑器内,点一下“一键排版”后,自动去掉源站的标签格式,只保留文字及图片信息,并且段落首行自动缩进两个字符,图片自动居中显示,段落与段落保留一行的间距。废话不多说:实现方法如下:
1、找到网站根目录下\source\module\home\home_editor.php文件,用文本编辑软件打开,找到第195行粘贴内容如下:
<a href="javascript:;" class="icoOnekey" title="一键排版" onClick="Onekey()"></a>
2、找到第177行粘贴内容如下:a.icoOnekey{background-position:-610px 1px;};
3、找到第29行粘贴内容如下:
function Onekey() {
var temps =
new Array();
var imgs =
window.frames["HtmlEditor"].document.images;
if (imgs != null
&& imgs.length > 0) {
for (j = 0; j <
imgs.length; j++) {
var pic =
document.createElement("IMG");
pic.alt
= imgs[j].alt;
pic.src =
imgs[j].src;
pic.width =
imgs[j].width;
pic.height =
imgs[j].height;
pic.align =
imgs[j].align;
temps[temps.length] =
pic;
}
var picid =
0;
for (j = 0; j < imgs.length;) {
imgs[j].outerHTML = "\n#hhcd_pic" + picid +
"#\n";
picid++;
}
}
var tmps =
window.frames["HtmlEditor"].document.body.innerText.split("\n");
var html = "";
for (i = 0; i < tmps.length;
i++)
{
var tmp =
tmps.trim();
if (tmp.length > 0)
{
if(tmp.indexOf("hhcd_pic")>0)
{
html+=tmp+"\n";
}
else
{
html += "
" +
tmp + "
\n";
}
}
}
if (temps != null
&& temps.length > 0) {
for (j = 0; j
< temps.length; j++) {
var imghtml = "
temps[j].src + "\" alt=\"" + temps[j].alt + "\" width=\"" + temps[j].width + "\"
height=\"" + temps[j].height + "\" align=\"" + temps[j].align +
"\">
";
html =
html.replace("#hhcd_pic" + j + "#", imghtml);
}
}
window.frames["HtmlEditor"].document.body.innerHTML=html;
}
String.prototype.trim
= function()
{
return this.replace(/(^[\s ]*)|([\s ]*$)/g,
"");
};
注:不支持Firefox浏览器
复制代码
欢迎光临 合元网络 (http://heyuan18.com/)
Powered by Discuz! X3.2