admin 发表于 2018-3-22 13:01:53

discuz教程:门户文章发布编辑器增加一键排版功能

这个功能很实用!  如题,其实就是将网摘文章直接粘贴到发布文章编辑器内,点一下“一键排版”后,自动去掉源站的标签格式,只保留文字及图片信息,并且段落首行自动缩进两个字符,图片自动居中显示,段落与段落保留一行的间距。注:不支持Firefox浏览器废话不多说:实现方法如下:  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.alt;

  pic.src =

  imgs.src;

  pic.width =

  imgs.width;

  pic.height =

  imgs.height;

  pic.align =

  imgs.align;

  temps =

  pic;

  }

  var picid =

  0;

  for (j = 0; j < imgs.length;) {

imgs.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.src + "\" alt=\"" + temps.alt + "\" width=\"" + temps.width + "\"

  height=\"" + temps.height + "\" align=\"" + temps.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,

  "");

  };

页: [1]
查看完整版本: discuz教程:门户文章发布编辑器增加一键排版功能