⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 doc_comment_ref.js

📁 hudong维客系统
💻 JS
字号:
/**
 *脚本文件
 *公司: 互动在线(北京)科技有限公司 (hoodong.com)
 *文件名:doc_comment_ref.js
 *功能:提取引用评论的信息,返回UBB标签格式的文本。
 *作者: 熊玉辉
 *创建时间: 2006-09-21 11:11
 *
 */

var gRefContent = "";

function setRefContent()
{
 	var fatherNode = window.event.srcElement.parentNode;
 	gRefContent = GetContent(fatherNode);
 	document.docCommentForm.doccomment.focus();
 	document.docCommentForm.doccomment.value = gRefContent; 	
}
   
function GetContent(v_fatherNode)   
{
  var inforList = new Array;
  var inforNode = null ;
  var contentNode = null ;
  if ("TD" == v_fatherNode.nodeName.toUpperCase())
  {
  	inforNode = v_fatherNode.parentNode;
  	contentNode = inforNode.nextSibling;
	 	while (contentNode != null)
	 	{
	   	if ("TR" == contentNode.nodeName.toUpperCase())
	   	{
	   		contentNode = contentNode.firstChild;
	   		break;
	   	}
	  	contentNode = contentNode.nextSibling; 	
	  }
  }
	else
	{
  	inforNode = v_fatherNode;
  	contentNode = v_fatherNode.nextSibling;
	}
 
 	inforList = GetAllTextNodes(inforNode); 	
 	var content = "";

 	while (contentNode != null)
 	{
   	if ("DIV" == contentNode.nodeName.toUpperCase() || "TD" == contentNode.nodeName.toUpperCase())
   	{
   		content = GetChildContent(contentNode);// div ,content node
   		break;
   	}
   	contentNode = contentNode.nextSibling;
	}
 	return joinContent(inforList[0], inforList[1], content);
}

function joinContent(v_id, v_date, v_content)
{
	var strResult="";
	strResult = strResult + '[quote]';
	strResult = strResult + '原帖由 [i]'+ v_id +'[/i] 于 '+v_date+' 发表 ' +v_content;
	strResult = strResult + '[/quote]';
	return strResult;
}
	//去左空格; 
	function LTrim(s)
	{ 
		return s.replace( /^\s*/, ""); 
	} 
	//去右空格; 
	function RTrim(s)
	{ 
		return s.replace( /\s*$/, ""); 
	} 
	//去左右空格; 
	function Trim(s)
	{ 
		return RTrim(LTrim(s)); 
	}
	function GetAllTextNodes(v_fatherNode)
	{
		var nodesList = new Array;
		var layer = v_fatherNode.childNodes;
		var childNum = layer.length;
	
		for (var i = 0; i < childNum; i++)
		{
			var childNode = layer[i];
			var noteType = childNode.nodeType;
			if (3 == noteType && 0 != Trim(childNode.data).length) /* Text node */
			{
				nodesList[nodesList.length] = childNode.data;
			}
			if (1 == noteType) /* Element node */
			{
				nodesList = nodesList.concat(GetAllTextNodes(childNode));
			}
		}
		return nodesList;
	}
	
	function GetChildContent(v_fatherNode)// div ,content node --> ([quote][/quote]) (content)
	{
		var content = "";
		var quoteContent = "";

		fatherNode = v_fatherNode.cloneNode(true);
		var layer = fatherNode.childNodes;
		var childNum = layer.length;
		for (var i = 0; i < childNum; i++)
		{
			var childNode = layer[i];
	   	if ("SPAN" == childNode.nodeName.toUpperCase())
	   	{
	   		var quoteNode = childNode.cloneNode(true);
	   		fatherNode.removeChild(childNode);
	   		quoteContent = GetQuoteContent(quoteNode);// span ,quote node 内容节点中的引用内容
	   		break;
	   	}
		}
		content = fatherNode.innerText;//内容节点中的内容
		return FormatContent(content, quoteContent);
	}
	
	function GetQuoteContent(v_fatherNode)// span ,quote node
	{
		var content = "";
		var quoteContent = "";
		
		var fatherNode = v_fatherNode.cloneNode(true);
		var flag = 0;
		var layer = fatherNode.childNodes;
		var childNum = layer.length;
		for (var i = 0; i < childNum; i++)
		{
			var childNode = layer[i];
			if ("DIV" == childNode.nodeName.toUpperCase())
	   	{
	   		flag++;
	   		if (2 == flag)//第二个DIV子节点
	   		{
	   			var childSpan = getSpanNodes(childNode);
	   			if (childSpan != null)//
	   			{
	   				var childnode =childNode.cloneNode(true);
	   				childNode.removeChild(childSpan);
	   				content = childNode.innerText;//引用节点中的内容
	   				quoteContent = GetQuoteContent(childSpan);
	   			}
	   			else
	   			{	
	   				content = childNode.innerText;
	   			}
	   			break;
	   		}
	   	}
		}
		return FormatContent(content, quoteContent);
	}
	function getSpanNodes(v_fatherNode)
	{
		var result = null;
		var layer = v_fatherNode.childNodes;
		var childNum = layer.length;
		for (var i = 0; i < childNum; i++)
		{
			var childNode = layer[i];			
			if ("SPAN" == childNode.nodeName.toUpperCase())
	   	{
				return childNode;
	  	} 
		}
		 return result;
	}

	function FormatContent(v_content, v_quote)
	{
   	var str1 = "原帖由";
   	var str2 = "于 ";
   	var str3 = " 发表";
		var pos1 = v_content.indexOf(str1);
		var pos2 = v_content.indexOf(str2);
		var pos3 = v_content.indexOf(str3);
		if (pos1 >= pos2 || pos2 >= pos3)
		{
			return v_quote + v_content;
		}
		var name = v_content.substring(pos1+str1.length, pos2);
		var time = v_content.substring(pos2+str2.length, pos3);
		var content = v_content.substring(pos3+str3.length, v_content.length);
		return joinContent(name, time, v_quote+content);
  }
    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -