通过查找“短消息”“搜索”等代码,我发现用的脚本文件并不通用,所以要达到通用的目的,只能把那段脚本加在 common.js 里面,这样才能保证通用性,至于之前的帖子嘛……先无视吧。
在 common.js 里面加入以下代码(之前如果已经在 post_editor.js 文件添加了代码的话请删除,当时没有考虑通用性的问题):复制内容到剪贴板
代码:
function toentities()
{
if($("srchtxt")) // search by text
$("srchtxt").value = TextToEntities($("srchtxt").value, false);
if($("srchname")) // search by username
$("srchname").value = TextToEntities($("srchname").value, false);
if($("pm_textarea")) // pm
$("pm_textarea").value = TextToEntities($("pm_textarea").value, false);
if($("subject")) // thread subject
$("subject").value = TextToEntities($("subject").value, false);
if($("message")) // thread content
$("message").value = TextToEntities($("message").value, false);
if($("tags")) // tags
$("tags").value = TextToEntities($("tags").value, false);
if(document.getElementsByName("polloptions")[0]) //polloptions
document.getElementsByName("polloptions")[0].value = TextToEntities(document.getElementsByName("polloptions")[0].value, false);
if($("activityclass")) // activityclass
$("activityclass").value = TextToEntities($("activityclass").value, false);
if($("activityplace")) // activityplace
$("activityplace").value = TextToEntities($("activityplace").value, false);
if($("activitycity")) // activitycity
$("activitycity").value = TextToEntities($("activitycity").value, false);
if($("counterdesc")) // counter sellers
$("counterdesc").value = TextToEntities($("counterdesc").value, false);
if($("aboutcounter")) // about counter
$("aboutcounter").value = TextToEntities($("aboutcounter").value, false);
if($("item_name")) // sold item's name
$("item_name").value = TextToEntities($("item_name").value, false);
if($("item_locus")) // sold item's location
$("item_locus").value = TextToEntities($("item_locus").value, false);
if($("affirmpoint")) // affirm point
$("affirmpoint").value = TextToEntities($("affirmpoint").value, false);
if($("negapoint")) // nega point
$("negapoint").value = TextToEntities($("negapoint").value, false);
if($("umpire")) // umpire
$("umpire").value = TextToEntities($("umpire").value, false);
if(typeof(editdoc) != "undefined") // thread
{
if(wysiwyg)
{
editdoc.body.innerHTML = TextToEntities(getEditorContents(), true);
}
else
{
editdoc.value = TextToEntities(getEditorContents(), false);
}
}
}
function TextToEntities(str, andEntity)
{
var strFull = new Array();
var intLowChar;
var strEntity;
var strChar;
var intChar;
for (var i = 0; i < str.length; i++)
{
strChar = str.charAt(i);
intChar = str.charCodeAt(i);
//CodePoint=((HighSurr-0xD800)/64+1)*0x10000+(HighSurr-0xD800) mod 64*1024+LowSurr-0xDC00
if(intChar >= 0xD800 && intChar <= 0xDBFF)
{
intLowChar = str.charCodeAt(i + 1);
intChar = ((intChar - 0xD800) / 64 + 1) * 0x10000 + (intChar - 0xD800) % 64 * 1024 + intLowChar - 0xDC00;
i++;
if(andEntity)
{
strEntity = "&#" + intChar + ";";
}
else
{
strEntity = "&#" + intChar + ";";
}
strFull.push(strEntity);
}
else
{
strFull.push(strChar);
}
}
return strFull.join("");
}然后是 post.js 文件,在 function ctlent(event) 的 if 语句后面加上 toentities(); 函数,修改后的代码如下:复制内容到剪贴板
代码:
function ctlent(event) {
if(postSubmited == false && (event.ctrlKey && event.keyCode == 13) || (event.altKey && event.keyCode == 83) && $('postsubmit')) {
toentities();
if(in_array($('postsubmit').name, ['topicsubmit', 'replysubmit', 'editsubmit', 'pmsubmit']) && !validate($('postform'))) {
…………接着改以下文件(第一行为原来的代码,第二行为修改后的代码):
// global.func.php复制内容到剪贴板
代码:
$string = preg_replace('/&((#(\d{3,5}|x[a-fA-F0-9]{4})|[a-zA-Z][a-z0-9]{2,5});)/', '&\\1',
$string = preg_replace('/&((#(\d{3,6}|x[a-fA-F0-9]{5})|[a-zA-Z][a-z0-9]{2,5});)/', '&\\1',// post_js.htm复制内容到剪贴板
代码:
$('postform').onsubmit = function() {validate(this);if($('postsubmit').name != 'editsubmit') return false};
$('postform').onsubmit = function() {toentities();validate(this);if($('postsubmit').name != 'editsubmit') return false};// pm_send.htm复制内容到剪贴板
代码:
<form method="post" id="postform" action="pm.php?action=send&pmsubmit=yes" onSubmit="return validate(this)">
<form method="post" id="postform" action="pm.php?action=send&pmsubmit=yes" onSubmit="toentities();return validate(this)">// search.htm复制内容到剪贴板
代码:
<form method="post" action="search.php" {if $qihoo['status']}onSubmit="if(this.srchtype[0].value=='qihoo' && this.srchtype[0].checked) this.target='_blank'; else this.target=''; return true;"{/if}>
<form method="post" action="search.php" onSubmit="toentities();{if $qihoo['status']}if(this.srchtype[0].value=='qihoo' && this.srchtype[0].checked) this.target='_blank'; else this.target=''; return true;{/if}">// pm_search.htm复制内容到剪贴板
代码:
<form method="post" onSubmit="if(this.srchtype[0].value=='qihoo' && this.srchtype[0].checked) this.target='_blank'; else this.target=''; return true;">
<form method="post" onSubmit="toentities();if(this.srchtype[0].value=='qihoo' && this.srchtype[0].checked) this.target='_blank'; else this.target=''; return true;">// forumdisplay.htm复制内容到剪贴板
代码:
<form method="post" id="postform" action="post.php?action=newthread&fid=$fid&extra=$extra&topicsubmit=yes" onSubmit="return validate(this)">
<form method="post" id="postform" action="post.php?action=newthread&fid=$fid&extra=$extra&topicsubmit=yes" onSubmit="toentities();return validate(this)">// viewthread.htm复制内容到剪贴板
代码:
<form method="post" id="postform" action="post.php?action=reply&fid=$fid&tid=$tid&extra=$extra&replysubmit=yes" onSubmit="return validate(this)">
<form method="post" id="postform" action="post.php?action=reply&fid=$fid&tid=$tid&extra=$extra&replysubmit=yes" onSubmit="toentities();return validate(this)">// viewthread_fastreply.htm复制内容到剪贴板
代码:
<form method="post" id="postform" action="post.php?action=reply&fid=$fid&tid=$tid&extra=$extra&replysubmit=yes" onSubmit="return validate(this)">
<form method="post" id="postform" action="post.php?action=reply&fid=$fid&tid=$tid&extra=$extra&replysubmit=yes" onSubmit="toentities();return validate(this)">// post_editpost_activity.htm复制内容到剪贴板
代码:
<form method="post" id="postform" action="post.php?action=edit&extra=$extra&editsubmit=yes&mod=$mod" $enctype onSubmit="return validate(this)">
<form method="post" id="postform" action="post.php?action=edit&extra=$extra&editsubmit=yes&mod=$mod" $enctype onSubmit="toentities();return validate(this)">这些代码大多都是加入了提交时的转换函数,这样在提交时就自动会转化了。