(.*?)<\/div>/igm, "\n$1") //
text
-> \ntext
.replace(/
(.*?)<\/p>/igm, "\n$1"); //
text
-> \ntext
return res;
}
function stripTags(el, tagName) {
var els = el.getElementsByTagName(tagName.toUpperCase());
for (var i = 0; i < els.length; i++) {
while (els[i].firstChild)
els[i].parentNode.insertBefore(els[i].removeChild(els[i].firstChild), els[i]);
els[i].parentNode.removeChild(els[i--]);
}
}
if(typeof String.prototype.trim !== 'function') {
String.prototype.trim = function() {
return this.replace(/^\s+/, '').replace(/\s+$/, '');
};
}
function cmt4_getCleanText(ele) {
var clone = ele.cloneNode(true);
clone.innerHTML = cmt4_html2txt(clone.innerHTML);
stripTags(clone, '*');
return clone.innerHTML.replace(/(?:\s| )*$/g, '');
}
// 清除评论内容
function cmt4_cleanContent(textarea) {
textarea.value = '';
textarea.removeAttribute('data-submit');
var ifr = textarea.parentNode.getElementsByTagName('iframe');
if(!ifr || ifr.length < 1) return;
ifr = ifr[0];
getIframeBody(ifr).innerHTML = '';
}
function cmt4_vote(relEle) {
cmt4_usejq(function(){
var $ele = $(relEle),
id = $ele.attr('data-id'),
$num = $ele.find('.cmtSupportNum'),
cur = parseInt($num.text(), 10);
var postUrl = '//cmt.pconline.com.cn/action/comment/support.jsp';
var postData = {
version:2,
cid: id,
sp: 1,
r: Math.random()
};
var successHandle = function(data) {
if(data.code == 1) { // success
$num.text(cur + 1);
$ele.data('done', '1');
cmt4_voteSuccess($ele);
} else { // false
if(data.msg) {
alert(data.msg);
} else {
alert('+1 失败');
}
}
};
postCORS(postUrl, function(data) {
try {
data = data.replace(/\\/g,"\\\\");
data = eval('('+data+')');
successHandle(data);
} catch(e) {
alert("咦,好像出错了,再试下或刷新看看?!");
}
}, postData, {withCookie: true});
});
}
function cmt4_voteSuccess($ele) {
var pos = $ele.offset(),
top = pos.top,
left = pos.left,
$plus = $('J-plus1'),
w = $plus.width(),
h = $plus.height(),
dl = ($ele.width() - w) / 2;
$('#J-plus1').stop().hide(0)
.css({
top: top - 10,
left: left + dl
})
.show(0)
.animate({
top: top - 10 - 50,
opacity: 0
}, 1000, function(){
$('#J-plus1').hide().css('opacity', 1);
});
$ele.css({
'color': '#ccc',
'text-decoration': 'none',
'cursor': 'default'
});
}
// 这个函数写死了form表单里元素的name
function cmt4_checkFrm(f){
if(f.content.value=='') { f.content.focus(); alert('评论内容不能为空!'); return false; }
if(f.content.value==cmt4_getAuditInfo()){ f.content.focus(); alert('请先输入您的评论!'); return false; }
if(f.content.value.length>500) { f.content.focus(); alert('评论内容字数超过500!'); return false; }
if(f.title.value=='') f.title.value=document.title;
if(f.title.value=='') f.title.value='[无标题]';
f.username.value=document.getElementById('usernameInput').value;
document.getElementById('Submit').disabled=true;
return true;
}
function reply(item, floor, showName, createTime) {
// if opened, hide it
var $parentNext = $(item).parent().parent().next(),
$operateOptions = $(item).parent();
$('.cmtMain .cmtOperateOptions').css('visibility', '');
if($parentNext.attr('id') == 'pl_add' && $parentNext.css('display') == 'block') {
$('#pl_add').slideUp();
$operateOptions.css('visibility', '');
return;
}
$operateOptions.css('visibility', 'visible');
document.getElementById('replyFloor').value= floor;
var preContent = '回复' + floor + '楼(' + showName + '):';
//var auditInfo = "注:所有评论通过审核后才会被公开。";
var auditInfo = preContent;
//document.getElementById('content_pop').focus();
//document.getElementById('pop_info').value = auditInfo;
document.getElementById('replyShowName').value = preContent;
cmt4_showAuditInfo2(auditInfo,1);
var td = $(item).parent().parent().parent();
var content = td.find('>.commentContent').html();
var preReply = td.find('.reply').html();
var replyContent = document.getElementById('replyContent');
replyContent.value = "";
if(preReply != null) {
replyContent.value = '
' + preReply + '
';
}
replyContent.value += '
' + floor + '楼' + showName + '' + createTime + '
';
showFB('add', item);
return false;
}
function cmt4__comment_show_entry_(placeHolder) {
var div = document.createElement('div');
if(placeHolder == null) placeHolder = document.getElementById("_comment_tag_");
if(placeHolder == null) placeHolder = document.getElementById("comment_tag");
if(placeHolder == null) {
alert(placeHolder);
return div;
}
div.id = placeHolder.id;
placeHolder.parentNode.replaceChild(div,placeHolder);
return div;
}
if(!window.jQuery){
var js=document.createElement("script");
js.src="//www1.pconline.com.cn/script/jquery-pconline1.2.js";
document.getElementsByTagName("head")[0].appendChild(js);
}
function cmt4_cleanMsg(){
//$('#msg').html("");
var _msg = document.getElementById("msg");
if(_msg){
_msg.innerHTML = "";
}
}
function cmt4_putFace(img, win){
var ifr = $(img).parents('form').find('.cmtEditor').get(0);
var html = '
';
var prefix = '{';
var postfix = '}';
cmt4_insert_code(prefix, postfix, html, ifr, win);
}
function cmt4_insert_code(prefix, postfix, value, iframe, win){
// 如果是默认文字,先移掉
if(iframe.id == 'cmtEditor_pop') {
cmt4_showAuditInfo2(3, 0);
} else {
cmt4_showAuditInfo(0, iframe.id);
}
insertToCursor(iframe, value);
$(".cmtfaceList").hide();
}
function cmt4_chgCap() {
// var c = document.getElementById("captchax");
// if(c) c.src="http://captcha.pcauto.com.cn/captcha/v.jpg?"+new Date().getTime();
var src = "//captcha.pconline.com.cn/captcha/v.jpg?"+new Date().getTime();
//$("img[id='captchax']").each(function(index,item){
$("img.imgCode").each(function(index,item){
item.src = src;
});
}
function cmt4_hasLogin() {
if(document.cookie.match(/(^|; )common_session_id=[^;]+/)) {
return true;
} else {
return false;
}
}
function cmt4_needCaptchaForNonLogin() {
// 非登录情况下,是否一定需要验证码
var mustNeed = true;
if (mustNeed && !cmt4_hasLogin()) {
return true;
} else {
return false;
}
}
function cmt4_showCaptcha() {
$("input[name='needCaptcha']").each(function(index, item) {
item.value = "1";
});
$(".captcha_line").show();
cmt4_chgCap();
}
function cmt4_hideCaptcha() {
$("input[name='needCaptcha']").each(function(index, item) {
item.value = "0";
});
$(".captcha_line").hide();
}
//function cmt4_chgCap_pop() {
//var c = document.getElementById("captchax_pop");
// if(c) c.src="http://captcha.pconline.com.cn/captcha/v.jpg?"+new Date().getTime();
//}
cmt4_firstcaptcha=true;
function cmt4_textLimitCheck(thisArea, maxLength){
if (thisArea.value.length > maxLength){
alert('你只能输入' + maxLength + '字。 \r超出的将自动去除。');
thisArea.value = thisArea.value.substring(0, maxLength);
thisArea.focus();
}
document.getElementById('cmtCountNum').innerHTML = thisArea.value.length;
}
function cmt4_getCookie(name) {
var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
if(arr != null) return (arr[2]); return null;
}
function cmt4_loadSessionId() {
return cmt4_getCookie('common_session_id');
}
function cmt4_checkForm() {
var usernameInput = document.getElementById('usernameInput2').value;
if (usernameInput == ""){
document.getElementById("msg").innerHTML = "请输入用户名";
return false;
}
var passwordInput = document.getElementById('passwordInput').value;
if (passwordInput == ""){
document.getElementById("msg").innerHTML = "请输入密码";
return false;
}
return true;
}
function cmt4_checkLogin() {
cmt4_cleanMsg();
var time=0;
var checker = setInterval(function(){
if(time++ < 30 && !document.cookie.match(/(^|; )common_session_id=[^;]+/)) return; //3秒钟
if(document.cookie.match(/(^|; )common_session_id=[^;]+/)) {
clearInterval(checker);
var cmu = decodeURIComponent(cmt4_getCookie('cmu'));
var sessionId = cmt4_loadSessionId();
var resp_enc = 'gbk';
if(cmu != "" && cmu != "null" && cmu != "undefined" && sessionId!=null){
$.getJSON("//my.pconline.com.cn/intf/getLogedUser.jsp?resp_enc=" + resp_enc + "&callback=?",function(data){
var spanLogin = document.getElementById("loginSpan");
var spanPopLogin = document.getElementById("loginSpan_pop");
var showName = data.nickName || cmu;
var logindHtml = cmt4_getLoginedHTML(showName);
if(spanLogin && logindHtml!=''){
$("span[name='loginSpan']").each(function(index,item){
item.innerHTML = logindHtml
});
}
if(spanPopLogin && logindHtml!='') spanPopLogin.innerHTML = logindHtml;
flushFace(data);
});
cmt4_changeAuditInfoAfterLogin();
cmt4_hideCaptcha();
hiddenFB(); //关闭登录弹窗
}
}else{
var _msg = document.getElementById("msg");
if(_msg){
clearInterval(checker);
_msg.innerHTML = "
登录失败! 请检查帐号和密码是否正确。";
document.getElementById('captchaTpl').style.cssText = "display:table-row;";
var src ="//captcha.pconline.com.cn/captcha/v.jpg?" + new Date().getTime();
document.getElementById('popCaptchaImg').src = src;
}
}
},100);
}
function cmt4_needJS(fn,src,callback) {
if(typeof callback == 'undefined' || callback == null) callback = function(){};
if(typeof fn != 'undefined' && fn != null && fn != '') return callback();
var status = typeof _needJS_ == 'undefined' ? _needJS_ = {loaded:[],loading:[]} : _needJS_;
for(var i=0; i < status.loaded.length; i++) {
if(status.loaded[i] == src) return callback();
}
function idx(src) { //供后面的代码调用
for(var i=0; i < status.loading.length;i++) if(status.loading[i].src==src) return i;
}
var loading = status.loading[idx(src)];
if(loading != null) {
loading.callbacks.push(callback);
return;
}
status.loading.push(loading = {src:src,callbacks:[callback]});
var js = document.createElement('script');
js.src = src;
js.onload = js.onreadystatechange = function() {
if(typeof js.readyState == 'undefined' || js.readyState == 'loaded' || js.readyState == 'complete') {
js.onload = js.onreadystatechange = null;
status.loaded.push(loading.src);
var callbacks = loading.callbacks;
status.loading.splice(idx(src),1);
for(var i = 0; i < callbacks.length; i++) {
loading.callbacks[i]();
}
}
}
document.getElementsByTagName('head')[0].appendChild(js);
}
function Get_Cookie( check_name ) {
check_name = escape( check_name );
// first we'll split this cookie up into name/value pairs
// note: document.cookie only returns name=value, not the other components
var a_all_cookies = document.cookie.split( ';' );
var a_temp_cookie = '';
var cookie_name = '';
var cookie_value = '';
var b_cookie_found = false; // set boolean t/f default f
var i = '';
var len = a_all_cookies.length;
for ( i = 0; i < len; i++ )
{
// now we'll split apart each name=value pair
a_temp_cookie = a_all_cookies[i].split( '=' );
// and trim left/right whitespace while we're at it
cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
// if the extracted name matches passed check_name
if ( cookie_name == check_name )
{
b_cookie_found = true;
// we need to handle case where cookie has no value but exists (no = sign, that is):
if ( a_temp_cookie.length > 1 )
{
cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
}
// note that in cases where cookie is initialized but no value, null is returned
return cookie_value;
break;
}
a_temp_cookie = null;
cookie_name = '';
}
if ( !b_cookie_found )
{
return null;
}
}
function Set_Cookie( name, value, expires, path, domain, secure ) {
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );
// if the expires variable is set, make the correct expires time, the
// current script below will set it for x number of days, to make it
// for hours, delete * 24, for minutes, delete * 60 * 24
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
//alert( 'today ' + today.toGMTString() );// this is for testing purpose only
var expires_date = new Date( today.getTime() + (expires) );
//alert('expires ' + expires_date.toGMTString());// this is for testing purposes only
document.cookie = escape( name ) + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + //expires.toGMTString()
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}
//use id as the cookie name
function setCookie(cookieName, commentId, domain, expires) {
// get cookie
var cookie = Get_Cookie(cookieName);
if(!expires) {
expires = 90; // 默认90天
}
if(cookie) { // exist cookie
cookie = cookie.split('#'); // covert to array
cookie.push(commentId);
Set_Cookie(cookieName, cookie.join("#") , expires, '/', domain, '');
} else { // first to set cookie
Set_Cookie(cookieName, commentId , expires, '/', domain, '');
}
}
var UN_AUDIT_COOKIE_NAME = 'CMT4_UN_AUDIT_';
// conPostfix : 用来区分 #contentxxx
function cmt4_comment(conPostfix) {
conPostfix = conPostfix || '';
cmt4_getArea();
cmt4_usejq(function(){
var $=window.jQuery;
cmt4_cleanMsg();
var postUrl = "//cmt.pconline.com.cn/action/comment/create.jsp";
var postData = {
isEncode: 1,
content: encodeURI($('#content' + conPostfix).val()),
id: $('#id').val(),
captcha: $('#captcha'+conPostfix).val(),
needCaptcha: $("#needCaptcha"+conPostfix).val(),
username: encodeURI($("#usernameInput").val()),
url: $("#url").val(),
title: encodeURI($("#title").val()),
columnId: '',
area: encodeURI($("#area").val()),
replyFloor2: $("#replyFloor").val(),
partId: $("#partIdq").val() || "",
syncsites: cmt4_getSyncStrVal()
};
var successHandle = function(data) {
var res = data.resultMsg;
if(data.resultCode>=0) {
var afterAudit = (data.resultCode == 0);
var nc = "
" + $('#newComment').html() + "";
var userJump = '//my.pconline.com.cn/';
if(data.userId > 0 && userJump != ''){
nc = nc.replace('
','
'+data.showName+'');
}
// replace avatar
var userAvatarStr = '';
if(data.userId > 0 && userJump != '') {
nc = nc.replace('','
' + data.showName + '');
userAvatarStr = '
';
} else {
nc = nc.replace('','
' + data.showName + '');
userAvatarStr = '
';
}
nc = nc.replace('', userAvatarStr);
nc = nc.replaceAll("", data.floor);
nc = nc.replaceAll("", data.commentId);
// nc = nc.replace("", data.createTime.substring(data.createTime.indexOf("-")+1));
nc = nc.replace("", "刚刚");
nc = nc.replace("", data.brief);
var quoteSpan = document.getElementById("quoteSpan");
if(quoteSpan){
if('pconline'=='pconline'){//for pcauto
nc = nc.replaceAll("",quoteSpan.innerHTML);
}else{
if(data.brief == ''){
nc = nc.replaceAll("",quoteSpan.innerHTML);
}
}
}
nc = nc.replaceAll("","");
if(quoteSpan) quoteSpan.innerHTML = "";
if(afterAudit){//先审后出不能引用和回复
// 添加先审后出提示
nc = nc.replaceAll("",'
(感谢参与评论,您的评论内容将在审核后公开。)
');
// 把未审的写到cookie里
//setCookie(UN_AUDIT_COOKIE_NAME + data.topicId, data.commentId, '.pconline.com.cn');
} else { // 先出后审
nc = nc.replaceAll("", "
回复顶[0]");
// add comment_total
var a = $("#comment_total").html();
a++;
$("#comment_total").html(a);
$("#comment_total2").html(a);
}
if(conPostfix == '_pop'){
nc = nc.replace("", "
" + document.getElementById('replyContent').value + "
");
}
$('#commentTable').prepend(nc);
if(!afterAudit){
bindVoteEventNew();//add new comment vote bind
}
//$('#content').val("");
//cmt4_cleanContent(document.getElementById('content' + conPostfix));
var contentArea = document.getElementById('content' + conPostfix);
if(contentArea) {
cmt4_cleanContent(contentArea);
}
res = res + cmt4_getExtraAuditInfo();
hiddenFB(2);
$("#replyFloor").val('');
}
if(document.getElementById("needAlert")){
alert(res);
}
var captcha = false || data.resultCode==-9;
$("input[name='captcha']").each(function(index, item) {
$(item).attr("value", "");
});
if (cmt4_needCaptchaForNonLogin() || captcha || data.commentCount > global.max_comment_count) {
cmt4_showCaptcha();
}else{
cmt4_hideCaptcha();
}
if(data.resultCode != -8 && data.resultCode != 1 && data.resultCode != 0) {
alert(res);
}
//var hideTag = 1;
//if(data.resultCode >= 0){//发表成功,锚点回到newestCmt
// hideTag = 2;
//}
//hiddenFB(hideTag);
return false;
};
var errorHandle = function() {
alert('数据提交失败 ╮(╯_╰)╭ ,尝试重新提交或刷新');
};
var completeHandle = function() {
if(document.getElementById('Submit'))document.getElementById('Submit').disabled=false;
if(document.getElementById('Submit2'))document.getElementById('Submit2').disabled=false;
if(document.getElementById('Submit_pop'))document.getElementById('Submit_pop').disabled=false;
if(document.getElementById('content'+conPostfix)) {
document.getElementById('content'+conPostfix).removeAttribute('data-submit');
}
//$("#replyFloor").val('');
};
postCORS(postUrl, function(data) {
data = data.replace(/\\/g,"\\\\");
try {
data = eval('('+data+')');
successHandle(data);
} catch(e) {
errorHandle();
}
completeHandle();
}, postData, {withCookie: true});
return false;
});
}
function cmt4_showAuditInfo(tag, editorId){
editorId = editorId || 'cmtEditor1';
var auditInfo = cmt4_getAuditInfo();
var ifr = document.getElementById(editorId);
var doc = ifr.contentWindow.document || ifr.contentDocument;
var obj = doc.body;
if(obj){
var v = cmt4_getCleanText(obj);
if(tag == 1){//显示
if(v == ""){
obj.innerHTML = auditInfo;
obj.style.color="#aaa";
}
}else{//不显示
if(v == auditInfo){
obj.innerHTML = "";
obj.style.color="#aaa";
}
}
}
}
function cmt4_showAuditInfo2(str,tag){
var s = str;
if(s=="0"||s=="2"||s=="3"){
s = document.getElementById("replyShowName").value;
}
var ifr = document.getElementById("cmtEditor_pop");
var doc = ifr.contentWindow.document || ifr.contentDocument;
var obj2 = doc.body;
if(obj2){
var v = cmt4_getCleanText(obj2);
if(tag == 1){//显示
if(v == "") {
obj2.innerHTML = s;
obj2.style.color="#aaa";
}
}else{//不显示
//alert('obj2.value='+v+'==s='+s+'flag'+(v == s));
if(v == s){
obj2.innerHTML = "";
obj2.style.color="#aaa";
}
if(s=="3"){
if(v == s){
obj2.innerHTML = "";
obj2.style.color="#aaa";
}
}
}
}
}
function cmt4_getExtraAuditInfo(){
var _extra_audit_info_ = "";
if("false"=="true"){ // todo: "false" 这里用了 OPEN_EXTRA_AUDIT_INFO 这个 jsp 变量
var sessionId = cmt4_loadSessionId();
if(sessionId!=null){ //登录
_extra_audit_info_ = "";
}else{
_extra_audit_info_ = "温馨Tips:登录后评论可直接发表。";
}
}
return _extra_audit_info_;
}
function cmt4_changeAuditInfoAfterLogin(){
var ifr = document.getElementById("cmtEditor1");
var doc = ifr.contentWindow.document || ifr.contentDocument;
var obj = doc.body,
v;
if(obj){
v = cmt4_getCleanText(obj);
if(v == "注:所有评论通过审核后才会被公开。" || v == "温馨Tips:登录后评论可直接发表,匿名评论须通过审核后才会被公开。" || v == "共建和谐社会,留言中请勿恶意攻击国家、党及其他用户或工作人员;请勿发布任何广告留言,我们将会予以删除或者冻结ID、封锁IP。营造文明友善、观点鲜明、顺畅沟通的良好评论环境,有赖您的支持与配合。"){
obj.innerHTML = cmt4_getAuditInfo();
}
}
}
// todo: 下面的 "false" == "true" 的判断是从后台写的?
function cmt4_getAuditInfo(){
var auditInfo = "注:所有评论通过审核后才会被公开。";
if("false"=="true"){
var sessionId = cmt4_loadSessionId();
if(sessionId!=null){ //登录
auditInfo = "共建和谐社会,留言中请勿恶意攻击国家、党及其他用户或工作人员;请勿发布任何广告留言,我们将会予以删除或者冻结ID、封锁IP。营造文明友善、观点鲜明、顺畅沟通的良好评论环境,有赖您的支持与配合。";
}else{
auditInfo = "温馨Tips:登录后评论可直接发表,匿名评论须通过审核后才会被公开。";
}
}
//alert(auditInfo);
return auditInfo;
}
//初始化
cmt4_showAuditInfo(1);
if(document.getElementById('cmtEditor2')) {
cmt4_showAuditInfo(1, 'cmtEditor2');
}
String.prototype.replaceAll = function(s1,s2){
return this.replace(new RegExp(s1,"gm"),s2);
}
function cmt4_getLoginedHTML(accountName){
return "
欢迎您,\"/> | 退出 ".replaceAll("",accountName);
}
function cmt4_loadAccountName(){
var cmu = decodeURIComponent(cmt4_getCookie('cmu'));
var sessionId = cmt4_loadSessionId();
var resp_enc = 'gbk';
if(cmu != "" && cmu != "null" && cmu != "undefined" && sessionId!=null){
cmt4_usejq(function(){
$.getJSON("//my.pconline.com.cn/intf/getLogedUser.jsp?resp_enc=" + resp_enc + "&callback=?",function(data){
var spanLogin = document.getElementById("loginSpan");
var spanPopLogin = document.getElementById("loginSpan_pop");
var showName = data.nickName || cmu;
var logindHtml = cmt4_getLoginedHTML(showName);
if(spanLogin && logindHtml!=''){
$("span[name='loginSpan']").each(function(index,item){
item.innerHTML = logindHtml.replaceAll('usernameInput','usernameInput_'+ index);
});
}
if(spanPopLogin && logindHtml!='') spanPopLogin.innerHTML = logindHtml;
flushFace(data);
});
});
}
}
function flushFace(data){
$(".cmt4_myface").each(function(index,item){
item.src = cmt4_getAvatar(data.id);
$(item).parent().attr("href",$(item).parent().attr("href")+data.id);
});
}
var cmt4_fmComment983000089 = document.getElementById('fmComment983000089');
if(cmt4_fmComment983000089){
cmt4_loadAccountName();
}
// ===============================地区获取================================
var COOKIE_NAME_IP = "CMT4_IP_AREA";
function cmt4_getArea() {
var cookie = Get_Cookie(COOKIE_NAME_IP);
if(cookie) { // 存在cookie
// 直接把cookie值不为1时,传到input.area里。
if(cookie != 1 && document.getElementById("area")) {
document.getElementById("area").value = cookie;
}
} else { // 不存在
var script = document.createElement('script');
script.src = "//whois.pconline.com.cn/ipJson.jsp?callback=cmt4_getAreaBack";
document.getElementsByTagName('head')[0].appendChild(script);
}
}
function cmt4_getAreaBack(location) {
var area = "";
if(location.pro == location.city) {
area = location.city;
} else {
area = location.pro + location.city;
}
// 无论area是否获取,都应该写一个cookie标识。
if(!area) {
area = 1;
} else {
// 把结果写到input.area里
if(document.getElementById("area")){
document.getElementById("area").value = area;
}
}
// 把结果写到cookie
Set_Cookie(COOKIE_NAME_IP, area, 90, '/', '.pcauto.com.cn', '');
}
//这里要预先取一次,因为是ajax异步方式取用户IP所在地区,不能在用户提交表单的时候调用
cmt4_getArea();
// ===============================================================
// ===============================获取评论总数=======================
function getTopicTotal(){
return 0;
}
// ===============================获取查看评论的链接地址(即评论列表页)=======================
function getTopicUrl(){
return "//cmt.pconline.com.cn/topic/a0/r0/p1/ps60/t.html"+('' == '' ? "?url=http://www.aryapackersandmovers.com/news/nation/brand/tjtoyota/0604/373236.html&columnId=" : "");
}
// 网站连接状态,1表示已连接,0表示未连接
var siteLinkStatus = {
weibo: 1,
tqq: 1,
qzone: 1
};
//当前选择的同步分享状态,默认应和网站连接状态相同
// 提交表单前需要把这些状态填入隐藏的input以发送到后台评论系统
var siteSyncSelect = {
weibo: 1,
tqq: 0,
qzone: 1
};
// 把当前同步选择变成字符串已发送到后台,由后台来实现同步发送到微博等
function cmt4_getSyncStr() {
return 'syncsites=' + cmt4_getSyncStr();
}
function cmt4_getSyncStrVal() {
var str = '',
arr = [];
for(var i in siteSyncSelect) {
if (siteSyncSelect[i]) {
arr.push(i);
}
}
return arr.join(',');
}
function cmt4_syncShareStatus() {
$('.cmtSite').each(function(){
var $this = $(this);
var site = $this.attr('data-site');
if(siteSyncSelect[site]) {
$this.addClass(site + 'on');
} else {
$this.removeClass(site + 'on');
}
});
}
cmt4_usejq(function(){
$('.cmtSite').click(function(){
var $this = $(this),
site = $this.attr('data-site'),
status = parseInt(siteLinkStatus[site], 10),
select = parseInt(siteSyncSelect[site], 10);
if(!status) {
// show alert
// http://my.pcauto.com.cn/setting/share.jsp
alert('需先建立连接');
return;
}
if (select) {
siteSyncSelect[site] = 0;
} else {
siteSyncSelect[site] = 1;
}
cmt4_syncShareStatus();
});
// eidtor
initEditor(document.getElementById('cmtEditor1'));
if(document.getElementById('cmtEditor2')) {
initEditor(document.getElementById('cmtEditor2'));
}
bindHoverReply();
bindHoverShare();
if (cmt4_needCaptchaForNonLogin()) {
cmt4_showCaptcha();
}
});
// 把 iframe 变成编辑模式,同时和其兄弟节点 textarea 进行关联,用于最后拷贝内容过去
function initEditor(ifr) {
var textarea = $(ifr).siblings('.tbxCmt').get(0);
var doc = ifr.contentDocument || ifr.contentWindow.document;
var cw = ifr.contentWindow;
doc.designMode = 'on';
var defaultHtml = '';
doc.open();
doc.write(defaultHtml);
doc.close();
doc.body.contenteditable = 'true';
// firefox 使用 jQuery 1.2.6 在 body 上 bind 有问题
// ie6 下 onkeypress 时 传递的 event 有问题,导致 cmt4_keypress 异常
if(navigator.userAgent.indexOf('Firefox') !== -1) {
doc.body.onkeypress = function(e){
e = e || window.event;
cw.parent.cmt4_keypress(textarea, e);
};
doc.body.onfocus = function() {
if(ifr.id == 'cmtEditor_pop') {
cw.parent.cmt4_showAuditInfo2(3, 0);
} else {
cw.parent.cmt4_showAuditInfo(0, ifr.id);
}
doc.body.style.color = '#000';
};
doc.body.onblur = function(){
if(ifr.id == 'cmtEditor_pop') {
cw.parent.cmt4_showAuditInfo2(2, 1);
} else {
cw.parent.cmt4_showAuditInfo(1, ifr.id);
cw.parent.cmt4_copyContent(textarea);
}
};
} else {
$(doc.body).bind('keypress',function(e){
e = e || window.event;
cw.parent.cmt4_keypress(textarea, e);
})
.bind('focus', function(){
if(ifr.id == 'cmtEditor_pop') {
cw.parent.cmt4_showAuditInfo2(3, 0);
} else {
cw.parent.cmt4_showAuditInfo(0, ifr.id);
}
doc.body.style.color = '#000';
})
.bind('blur', function(){
if(ifr.id == 'cmtEditor_pop') {
cw.parent.cmt4_showAuditInfo2(2, 1);
} else {
cw.parent.cmt4_showAuditInfo(1, ifr.id);
cw.parent.cmt4_copyContent(textarea);
}
});
}
// 默认状态
if(ifr.id == 'cmtEditor_pop') {
cw.parent.cmt4_showAuditInfo2(2, 1);
} else {
cw.parent.cmt4_showAuditInfo(1, ifr.id);
cw.parent.cmt4_copyContent(textarea);
}
if(navigator.userAgent.indexOf('MSIE') !== -1) {
var bookmark;
//记录IE的编辑光标
$(ifr).bind("beforedeactivate",function(){//在文档失去焦点之前
var range = doc.selection.createRange();
bookmark = range.getBookmark();
});
//恢复IE的编辑光标
$(ifr).bind("activate",function(){
if(bookmark){
var range = doc.body.createTextRange();
range.moveToBookmark(bookmark);
range.select();
bookmark = null;
}
});
}
}
function insertToCursor(iframe, html){
iframe.contentWindow.focus();
var iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
if(iframeDocument.selection){
/****这里需要解决IE丢失光标位置的问题,详见核心代码四**************/
iframeDocument.selection.createRange().pasteHTML(html);
}else{
var selection = iframe.contentWindow.getSelection();
var range;
if (selection) {
if(selection.rangeCount < 1) return;
range = selection.getRangeAt(0);
}else {
range = iframeDocument.createRange();
}
var oFragment = range.createContextualFragment(html),
oLastNode = oFragment.lastChild ;
range.insertNode(oFragment) ;
range.setEndAfter(oLastNode ) ;
range.setStartAfter(oLastNode );
selection.removeAllRanges();//清除选择
selection.addRange(range);
}
}
function bindHoverReply() {
$('.reply').bind('mouseenter', function(e) {
$(this).parents('.cmtMainIn').find('.reply .cmtOperate').css('visibility', 'hidden');
$(this).children('.tbTB').children('.cmtOperate').css('visibility', 'visible');
})
.bind('mouseleave', function(e) {
$(this).children('.tbTB').children('.cmtOperate').css('visibility', 'hidden');
var $p = $(this).parent();
if($p.hasClass('reply')) {
$p.children('.tbTB').children('.cmtOperate').css('visibility', 'visible');
} else if($p.hasClass('tbTB')) {
$p.children('.cmtOperate').css('visibility', 'visible');
}
});
}
function bindHoverShare() {
$('.cmtOperate .share').hoverIntent({
over: toggleShare,
out: toggleShare,
timeout: 300
});
}
function toggleShare() {
$(this).toggleClass('shareOn');
}
function cmt4_getAvatar(id) {
id = '' + id; // make sure is string
// 每两位用 / 分割,最后可能剩一位
var ret = [], i = 0, l = id.length;
while(i + 2 <= l) {
ret.push(id.slice(i, i+2));
i += 2;
}
if(i < l) {
ret.push(id.charAt(i));
}
return '//i7.3conline.com/images/upload/upc/face/' + ret.join('/') + '/' + id + '_50x50';
}
function bindVoteEvent() {
$('.cmtOperate .cmtVote').bind('click', function(e){
if($(this).data('done') != '1'){
cmt4_vote(this);
}
e.preventDefault();
});
}
function cmt4_deny(relEle) {
if(!confirm('真的扣留吗?'))return false;
cmt4_usejq(function(){
var $ele = $(relEle),
id = $ele.attr('data-id');
var postUrl = '//cmt.pconline.com.cn/adm/action/comment_do.jsp';
var postData = {
method: 'batDeny',
ids: id
};
var successHandle = function(data) {
if(data.statusCode == 200) { // success
window.location.reload();
}else if(data.statusCode == 301 || data.statusCode == 300){
//backend common feedback result
alert(data.message);
window.location.reload();
} else { // false
if(data.message) {
alert(data.message);
} else {
alert('扣留失败');
}
}
};
postCORS(postUrl, function(data) {
try {
data = data.replace(/\\/g,"\\\\");
data = eval('('+data+')');
successHandle(data);
} catch(e) {
alert("咦,好像出错了,再试下或刷新看看?!");
}
}, postData, {withCookie: true});
});
}
function cmt4_batchDeny(relEle) {
var items = $("#cmt4Form").find("input[name='id']:checked");
if(!items || items.length == 0){
alert("请选择要操作的记录");
return;
}
if(!confirm('真的扣留吗?'))return false;
cmt4_usejq(function(){
var $ele = $(relEle);
var cids = new Array();
items.each(function(){
cids.push($(this).val());
});
var postUrl = '//cmt.pconline.com.cn/adm/action/comment_do.jsp';
var postData = {
method: 'batDeny',
ids: cids.join(',')
};
var successHandle = function(data) {
if(data.statusCode == 200) { // success
window.location.reload();
}else if(data.statusCode == 301 || data.statusCode == 300){
//backend common feedback result
alert(data.message);
window.location.reload();
} else { // false
if(data.message) {
alert(data.message);
} else {
alert('扣留失败');
}
}
};
postCORS(postUrl, function(data) {
try {
data = data.replace(/\\/g,"\\\\");
data = eval('('+data+')');
successHandle(data);
} catch(e) {
alert("咦,好像出错了,再试下或刷新看看?!");
}
}, postData, {withCookie: true});
});
}
function bindDenyEvent() {
$('.cmtConsoleActions .cmtDeny').bind('click', function(e){
cmt4_deny(this);
e.preventDefault();
});
$('#cmtConsoleBatchActionBtn').bind('click', function(e){
cmt4_batchDeny(this);
e.preventDefault();
});
}
function cmt4_commend(relEle) {
cmt4_usejq(function(){
var $ele = $(relEle),
id = $ele.attr('data-id');
var postUrl = '//cmt.pconline.com.cn/adm/action/comment_do.jsp';
var postData = {
method: 'commend',
id: id
};
var successHandle = function(data) {
if(data.statusCode == 200) { // success
window.location.reload();
}else if(data.statusCode == 301 || data.statusCode == 300){
//backend common feedback result
alert(data.message);
window.location.reload();
} else { // false
if(data.message) {
alert(data.message);
} else {
alert('推荐/取消推荐失败');
}
}
};
postCORS(postUrl, function(data) {
try {
data = data.replace(/\\/g,"\\\\");
data = eval('('+data+')');
successHandle(data);
} catch(e) {
alert("咦,好像出错了,再试下或刷新看看?!");
}
}, postData, {withCookie: true});
});
}
$('#popCaptchaImg').click(function(){
var src = "//captcha.pconline.com.cn/captcha/v.jpg?" + new Date().getTime();
$('#popCaptchaImg').attr('src',src);
})
function bindCommendEvent() {
$('.cmtConsoleActions .cmtCommend').bind('click', function(e){
cmt4_commend(this);
e.preventDefault();
});
}
//new comment add bind
function bindVoteEventNew(){
$('.cmtOperate .cmtNew').bind('click', function(e){
if($(this).data('done') != '1'){
cmt4_vote(this);
}
e.preventDefault();
});
$('.cmtOperate .cmtNew').attr('class','cmtVote');
}
// 点击登录