?? doc_comment_ref.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 + -