var comment = new object();
var $c = function(tagname)
{
return document.createelement(tagname);
};
string.prototype.trim = function()
{
return this.replace(/^\s*|\s*$/g,);
};
string.prototype.reallength = function()
{
return this.replace(/[^\x00-\xff]/g,**).length;
};
string.prototype.left = function(n)
{
if (this.length > n)
{
return this.substr(0, n) + '...';
}
else
{
return this;
}
};
array.prototype.remove = function(n)
{
if (n {
return this;
}
else
{
return this.slice(0, n).concat(this.slice(n + 1, this.length));
}
};
function findposx(obj)
{
var curleft = 0;
if (obj && obj.offsetparent)
{
while (obj.offsetparent)
{
curleft += obj.offsetleft;
obj = obj.offsetparent;
}
}
else if (obj && obj.x) curleft += obj.x;
return curleft;
}
function findposy(obj)
{
var curtop = 0;
if (obj && obj.offsetparent)
{
while (obj.offsetparent)
{
curtop += obj.offsettop;
obj = obj.offsetparent;
}
}
else if (obj && obj.y) curtop += obj.y;
return curtop;
}
var input_domain = 'http://input.comment.qq.com';
var index_domain = 'http://comment1.qq.com';
var pinglun_domain = 'http://pinglun.qq.com';
var js_domain = 'http://pinglun.qq.com';
var img_domain = 'http://mat1.qq.com/pinglun';
comment.configure = {
version: '1.0',
newline: '\n',
site_length: 20,
key_length: 20,
id_length: 10,
index_line_sum: 10000,
index_width: 5,
default_mode: 'origin_count',
default_order: 1,
default_reply_per_page: 10,
quote_str_len: 60,
intro_len: 150,
debate_intro_len: 200,
content_len: 200,
reply_default_title: '请填写标题',
intro_min_length: 20,
request_delay: 100,
login_frame_delay: 2000,
reply_type_def: {
'1': '[精] ',
'2': '[荐] ',
'3': '[专] '
},
posturl: input_domain + '/post.cmt',
logouturl: input_domain + '/cgi-bin/qqlogout',
commentindex: 'http://pinglun.qq.com/',
loginiframeurl: index_domain + '/i_login.htm',
defaultlogourl: img_domain + '/images/defpic.jpg'
}
comment.define = {
getreplytype: function(type)
{
if (comment.configure.reply_type_def[type])
{
return comment.configure.reply_type_def[type];
}
else
{
return '';
}
}
}
comment.pgv_count = function(option)
{
if (typeof(pgvmain) == 'function')
{
pvrepeatcount = 1;
pvcurdomain = sdomain;
if (option)
{
if (option.domain)
{
pvcurdomain = option.domain;
}
if (option.path)
{
pvcururl = option.path;
}
}
pgvmain();
//debug.log('call pgv function');
}
}
comment.urlfactory = {
get3leveldir: function(id)
{
var path = parseint(id / 1000000) + '/';
path += parseint(id / 1000) + '/';
path += id / 1;
return path;
},
getcommenturl: function(id)
{
return (this.get3leveldir(id) + '/');
},
getdebateurl: function(id)
{
return this.get3leveldir(id);
},
getuserurl: function(id)
{
return this.get3leveldir(id);
},
getreplyurl: function(key)
{
var path = key.substr(0, 8);
path += '/' + (key.substr(8, 4));
path += '/' + (key.substr(12, 2));
path += '/' + key;
return path;
},
getindexurl: function(id)
{
var length = id.tostring().length;
if (length {
for (var i = 0; i {
id = '0' + id;
}
}
return id;
},
getindexdir: function(mode)
{
var modes = {
'origin_count': 'originindex',
'total_count': 'allindex',
'top_count': 'topindex'
};
return modes[mode];
},
getrangeheader: function(start, length, line_len)
{
var range_start = start * line_len;
var range_length = length * line_len;
return ['range','bytes=' + range_start + '-' + (parseint(range_start) + parseint(range_length) - 1 - comment.configure.newline.length)];
},
getcommentnormalurl: function(site, id)
{
return 'comment.htm?site=' + site + '&id=' + id;
},
getcommentgroupurl: function(site, id)
{
return 'comment_group.htm?site=' + site + '&id=' + id;
},
getcommentdebateurl: function(site, id)
{
return 'comment_debate.htm?site=' + site + '&id=' + id;
},
getcommentuserurl: function(uin)
{
return 'comment_user.htm?uin=' + uin;
},
getcommentuserlink: function(uin, nick)
{
return '' + (nick ? nick : uin) + '';
},
getcommentlistlink: function(site_en, site_cn, sort_en, sort_cn, classname)
{
if (classname)
{
classname = 'class=' + classname + '';
}
else
{
classname = '';
}
return '评论首页 >> '
+ '' + site_cn + ' >> '
+ '' + sort_cn + '';
}
}
comment.contentformat = {
decode: function(content)
{
return content.split(comment.configure.newline);
}
}
comment.dataobjectfactory = function(content, model)
{
content = comment.contentformat.decode(content);
var datamodel = comment.dataobject[model];
if (content.length - 1 != datamodel.length)
{
if (model != 'commentinfo' && model != 'listsum')
{
//alert('[debug 信息] o/r 映射失败,远程数据和本地模型数量不匹配!请检查!');
}
}
var dataobject = new object();
for (var i = 0; i {
dataobject[datamodel[i]] = content[i];
}
return dataobject;
}
comment.dataobject = {
'commentinfo':
[
'site_cn',
'sort_en',
'sort_cn',
'source',
'source_url',
'title',
'url',
'intro',
'intro_img',
'group_id',
'intro_show',
'create_time',
'debate_id'
],
'groupinfo':
[
'site_cn',
'title',
'url',
'intro',
'intro_img',
'comment_id',
'intro_show',
'create_time'
],
'debateinfo':
[
'site_cn',
'title',
'url',
'intro',
'intro_img',
'agree_id',
'disagree_id',
'middle_id',
'intro_show',
'create_time'
],
'sum':
[
'origin_count',
'total_count',
'top_count'
],
'reply':
[
'comment_id',
'uin',
'nickname',
'pub_time',
'pass_time',
'ip',
'title',
'content',
'reply_key',
'is_del',
'reply_type',
'reply_kind',
'tips'
],
'pksum':
[
'agree',
'disagree',
'middle'
],
'listsum':
[
'all'
],
'usersum':
[
'total_count',
'top_count',
'is_expert'
],
'userinfo':
[
'user_img',
'user_intro'
]
}
/* 控制器类 */
comment.control = new object();
/* 分页控制器 */
comment.control.pagination = class.create();
comment.control.pagination.prototype = {
initialize: function(option)
{
this.totalpage = option.totalpage;
this.currpage = 1;
this.zoom_start = 3;
this.zoom_end = 613;
this.bindcontrol();
},
reset: function(option)
{
this.totalpage = option.totalpage;
this.currpage = 1;
this.movepagecontrol(this.currpage);
},
updateorder: function()
{
},
countcurrpage: function(offset)
{
var page = parseint(offset * this.totalpage / this.zoom_end) + 1;
if (page > this.totalpage)
{
page = this.totalpage;
}
return page;
},
movepagecontrol: function(topage)
{
if (topage this.totalpage)
{
return;
}
var offset = 0;
if (topage == 1)
{
offset = this.zoom_start;
}
else if (topage == this.totalpage)
{
offset = this.zoom_end;
}
else
{
offset = this.zoom_start + (topage - 1) * (this.zoom_end / (this.totalpage - 1));
}
$('scrfloat').style.left = offset + 'px';
//$('scrfloat_2').style.left = offset + 'px';
},
bindcontrol: function()
{
var self = this;
var tooltip = $('page_tip');
var offsetx = 10;
var offsety = -10;
function getsite(o)
{
var obj = o;
var objs = obj.offsetleft;
while (obj != obj.offsetparent && obj.offsetparent)
{
obj = obj.offsetparent;
if (obj.tagname == 'span')
{
objs += obj.offsetleft;
}
}
return objs;
}
event.observe($('scr'), 'mousedown', mdown, false);
//event.observe($('scr_2'), 'mousedown', mdown, false);
var flag = false;
function mdown()
{
flag = true;
if(window.event.srcelement.id != 'scr'
&& window.event.srcelement.id != 'scr_2')
{
$('scrfloat').style.left = $('scrfloat').offsetleft;
//$('scrfloat_2').style.left = $('scrfloat').style.left;
}
else
{
$('scrfloat').style.left = (window.event.x - 5);
//$('scrfloat_2').style.left = $('scrfloat').style.left;
}
tooltip.style.display = 'block';
t = $('scrfloat').offsetleft;
tooltip.innerhtml = self.countcurrpage(t);
tooltip.style.left = window.event.clientx + offsetx + 'px';
tooltip.style.top = window.event.clienty + offsety + document.documentelement.scrolltop + 'px';
}
function mmove()
{
if(flag)
{
$('scrfloat').style.left = window.event.clientx - getsite($('scr')) - 5 + 'px';
//$('scrfloat_2').style.left = window.event.clientx - getsite($('scr')) - 5 + 'px';
}
if (parseint($('scrfloat').style.left.replace('px', '')) > self.zoom_end)
{
$('scrfloat').style.left = self.zoom_end + 'px';
//$('scrfloat_2').style.left = $('scrfloat').style.left;
}
if (parseint($(scrfloat).style.left.replace('px', '')) {
$('scrfloat').style.left = self.zoom_start + 'px';
//$('scrfloat_2').style.left = $('scrfloat').style.left;
}
if (flag)
{
t = $('scrfloat').offsetleft;
tooltip.innerhtml = self.countcurrpage(t);
tooltip.style.left = window.event.clientx + offsetx + 'px';
tooltip.style.top = window.event.clienty + offsety + document.documentelement.scrolltop + 'px';
}
}
function mup()
{
if (flag)
{
t = $('scrfloat').offsetleft;
self.setcurrpage(self.countcurrpage(t));
}
flag = false;
tooltip.style.display = 'none';
}
function mend()
{
window.event.returnvalue = false;
}
window.document.onmousemove = mmove;
window.document.ondragstart = mend;
window.document.onmouseup = mup;
event.observe($('up'), 'click', mupbtn, false);
event.observe($('down'), 'click', mdownbtn, false);
function mupbtn()
{
self.setcurrpage(self.currpage - 1, 1);
}
function mdownbtn()
{
self.setcurrpage(self.currpage + 1, 1);
}
},
nextpage: function()
{
if (this.currpage {
++this.currpage;
this.onpagechange();
}
},
previouspage: function()
{
if (this.currpage > 0)
{
--this.currpage;
this.onpagechange();
}
},
setcurrpage: function(page, move)
{
if (page > 0 && page {
this.currpage = page;
this.onpagechange();
if (move != null)
{
this.movepagecontrol(page);
}
}
},
onpagechange: function()
{
},
getcurrpage: function()
{
return this.currpage;
}
}
comment.iterator = {
getindex: function(objcomment)
{
var rangelist = new array();
function getindexid(reply_id)
{
return parseint(reply_id / comment.configure.index_line_sum);
}
function getreplypos(reply_id)
{
return (reply_id % comment.configure.index_line_sum);
}
if (objcomment.order == 0)
{
var reply_start = (objcomment.currpage - 1) * objcomment.replyperpage;
var start_index_id = getindexid(reply_start);
var start_reply_id = getreplypos(reply_start);
var currreply = 1;
var replysum = 0;
while (currreply++)
{
if (reply_start + currreply > objcomment.totalreply)
{
rangelist.push({
url: comment.urlfactory.getindexurl(start_index_id),
range: comment.urlfactory.getrangeheader(start_reply_id, currreply - replysum - 1, objcomment.index_line_len)
});
break;
}
if (currreply == objcomment.replyperpage)
{
rangelist.push({
url: comment.urlfactory.getindexurl(start_index_id),
range: comment.urlfactory.getrangeheader(start_reply_id, currreply - replysum, objcomment.index_line_len)
});
break;
}
if (start_reply_id + currreply > comment.configure.index_line_sum)
{
rangelist.push({
url: comment.urlfactory.getindexurl(start_index_id),
range: comment.urlfactory.getrangeheader(start_reply_id, currreply, objcomment.index_line_len)
});
start_index_id++;
start_reply_id = 0;
replysum = currreply - 1;
}
}
}
else
{
var reply_start = objcomment.totalreply - 1 - (objcomment.currpage - 1) * objcomment.replyperpage;
var start_index_id = getindexid(reply_start);
var start_reply_id = getreplypos(reply_start);
var currreply = 1;
var replysum = 0;
while (currreply++)
{
if (reply_start - currreply {
rangelist.push({
url: comment.urlfactory.getindexurl(start_index_id),
range: comment.urlfactory.getrangeheader(0, start_reply_id + 1, objcomment.index_line_len)
});
break;
}
if (currreply == objcomment.replyperpage)
{
rangelist.push({
url: comment.urlfactory.getindexurl(start_index_id),
range: comment.urlfactory.getrangeheader(start_reply_id - currreply + replysum + 1, currreply - replysum, objcomment.index_line_len)
});
break;
}
if (start_reply_id - currreply {
rangelist.push({
url: comment.urlfactory.getindexurl(start_index_id),
range: comment.urlfactory.getrangeheader(0, start_reply_id + 1, objcomment.index_line_len)
});
start_index_id--;
start_reply_id = comment.configure.index_line_sum - 1;
replysum = currreply;
}
}
}
return rangelist;
}
}
/* 显示样式控制器 */
comment.control.display = class.create();
comment.control.display.prototype = {
initialize: function()
{
}
}
/* 页面显示类 */
comment.page = new object();
/* 评论页控制接口 */
comment.page.base = {
changemode: function(mode)
{
this.mode = mode;
this.totalreply = this.data_sum[mode];
this.totalpage = parseint(this.totalreply / this.replyperpage)
+ (this.totalreply % this.replyperpage != 0 ? 1 : 0);
},
changeorder: function(order)
{
if (this.order == order)
return;
this.order = order;
this.currpage = 1;
this.resetpagecontrol();
this.bindpagenav();
this.bindreplylist();
this.bindordercontrol();
},
bindordercontrol: function()
{
var self = this;
if (self.order == 0)
{
$('order_front').style.cursor = 'none';
$('order_front').style.color = '#000';
$('order_front').onclick = function(e)
{
return false;
}
$('order_desc').style.cursor = 'pointer';
$('order_desc').style.color = '#3b78af';
$('order_desc').onclick = function()
{
self.changeorder(1);
return false;
}
}
else if (self.order == 1)
{
$('order_front').style.cursor = 'pointer';
$('order_front').style.color = '#3b78af';
$('order_front').onclick = function(e)
{
self.changeorder(0);
return false;
}
$('order_desc').style.cursor = 'none';
$('order_desc').style.color = '#000';
$('order_desc').onclick = function()
{
return false;
}
}
},
bindrowsperpage: function()
{
var self = this;
$a($('rows_page').getelementsbytagname('a')).each(function(button)
{
button.onclick = function()
{
self.replyperpage = button.value;
self.currpage = 1;
self.resetpagecontrol();
self.bindpagenav();
self.bindreplylist();
return false;
}
});
},
selecttab: function(mode)
{
var self = this;
$a($('mode_tab').getelementsbytagname('p')).each(function(tab)
{
if (tab.value == mode)
{
$a($('mode_tab').getelementsbytagname('p')).each(function(t)
{
if (t.value != '')
{
t.classname = 'none';
}
});
tab.classname = 'c';
}
});
},
appendtab: function(option)
{
var ptab = $c('p');
ptab.innerhtml = option.title;
ptab.value = '';
$('mode_tab').appendchild(ptab);
ptab.onclick = function()
{
window.open(option.url);
}
return false;
},
bindtabcontrol: function()
{
var self = this;
$a($('mode_tab').getelementsbytagname('p')).each(function(tab)
{
var mode = tab.value;
if (mode != '')
{
tab.onclick = function()
{
$a($('mode_tab').getelementsbytagname('p')).each(function(t)
{
t.classname = 'none';
});
this.classname = 'c';
self.currpage = 1;
self.changemode(mode)
self.resetpagecontrol();
self.bindpagenav();
self.bindreplylist();
return false;
}
}
});
},
bindpagerandom: function()
{
var self = this;
$a($('page_random', 'page_random_2')).each(function(button)
{
button.onclick = function()
{
if (self.totalpage == 1)
{
self.currpage = 1;
}
else
{
self.currpage = math.floor(math.random() * (self.totalpage + 1));
if (self.currpage == 0)
{
self.currpage = 1;
}
}
self.bindpagenav();
self.bindreplylist();
return false;
