/*
* jQuery 1.2.2 - New Wave Javascript
*
* Copyright (c) 2007 John Resig (jquery.com)
* Dual licensed under the MIT (MIT-LICENSE.txt)
* and GPL (GPL-LICENSE.txt) licenses.
*
* $Date: 2008-01-14 17:56:07 -0500 (Mon, 14 Jan 2008) $
* $Rev: 4454 $
*/
function _$(e) {return document.getElementById(e);}
function moveForm(a) {
if(a)$("#commentform").prependTo("#comment-"+a+">ul");
else $("#commentform").appendTo("#cmtForm");
$('#comment_reply_ID').val(a);
a>0?$('#reRoot').show():$('#reRoot').hide();
}
var c, t, c, now;
function AjaxSendComment(){
r = $('#comment_reply_ID').val(), t, c, now = parseInt(Math.random()*1000);
if (r == 0) {
c = $("#comments");
} else {
var u = $("#comment-"+r+">ul:first");
if (u) {
c = u;
} else {
c = document.createElement('ul');
$("#comment-"+r).appendChild(c);
c = $("#comment-"+r+">ul:first");
}
}
var content = $('#comment').val().replace(/\r\n\r\n/g, "
").replace(/\r\n/g, "
").replace(/\n\n/g, "
").replace(/\n/g, "
");
content = "
" + content + "
";
var author = "admin", email="a@b.c";
var author = $("#author").val(), email = $("#email").val();
//check the author and content input area is fixed
if(content == "" || ( (needemail=="1") && (author == "" || email == ""))){
if(author ==""){ alert("name is necessary"); if($("#authorrequire"))$("#authorrequire").css({color:"rgb(255,0,0)"});$("#author").focus();}
else if(email==""){ alert("email is necessary");; if($("#emailrequire"))$("#emailrequire").css({color:"red"});$("#email").focus();}
else{ alert("comment can not be empty");$("#comment").focus();}
return true;
}
var dateObj = new Date();
var now = "tmp-"+encodeURI(dateObj.getTime());
c.append("You submit a new comment...
");
comment_preview(false);moveForm(0);
$.ajax({
type: "POST",
timeout: 100000,
url: $("#commentform").attr("action"),
data: $("#commentform").serialize(),
error:function(emsg) {
alert("评论失败,可能原因如下:\n1.留言过快;\n2.E-mail格式不正确;\n3.留言重复;\n4.留言超时, 服务器临时抽风")
$('#'+now).remove();
$('#comment').focus();
},
success: function(msg){
$('#comment').val('');
$('#finish').hide('slow',function(){$(this).remove();});
}
});
return true;
}
function comment_preview(i) {
if (typeof(i)=='undefined' && $('#copreview').css("display") != 'block' || typeof(i) != 'undefined' && i == true) {
if ($('#copreview').css("display") != 'block') {
$.ajax({
type: "POST",
timeout: 100000,
url: blogurl + '/wp-content/plugins/ajaxcomment/preview.php',
data: $("#commentform").serialize(),
success: function(msg){
$('#commentdiv').css({display:'none'});
$('#copreview').html(msg).css({display:'block'});
$('#prectr').val('Edit');
}
});
}
} else {
if ($('#copreview').css("display") != 'none') {
$('#prectr').val('Preview');
$('#commentdiv').css({display:'block'});
$('#copreview').css({display:'none'});
$('#comment').focus();
}
}
}
function ajaxShowPost(u, e, j, s, m){
if ( u.match(/getpost/) ) nowurl=u;
ajaxStatus('block');
$.ajax({
type: "GET",
timeout: 10000,
url: u,
success: function(msg){
ajaxStatus('none');
if (j) window.location.href = "#"+j;
if (s) eval(s);
$('#'+e).html(msg);
}
});
}
function ajaxStatus(s) {
if (!$("#ajax")) return;
$("#ajax").css({display:s});
}
// Retrieve the value of the cookie with the specified name.
var aCookie = document.cookie.split("; ");
function GetCookie(sName, id) {
// cookies are separated by semicolons
var something = _$(id);
if (!something) return false;
for (var i=0; i < aCookie.length; i++) {
// a name alue pair (a crumb) is separated by an equal sign
var aCrumb = aCookie[i].split("=");
if (sName == aCrumb[0]) {
something.value = unescape(decodeURI(aCrumb[1]));
return true;
}
}
// a cookie with the requested name does not exist
return true;
}
function login(id) {
// cookies are separated by semicolons
var something = _$(id), author = "", url = "http://zhiqiang.org/link/";
if (!something) return 0;
for (var i=0; i < aCookie.length; i++) {
// a name alue pair (a crumb) is separated by an equal sign
var aCrumb = aCookie[i].split("=");
var sName = aCrumb[0];
if (sName=="comment_author_"+md5)
author = unescape(decodeURI(aCrumb[1]));
else if (sName=="comment_author_url_"+md5)
url=unescape(decodeURI(aCrumb[1]));
}
if (author) something.innerHTML = "欢迎回来, " + author + "";
return 0;
}
function ecai() {
if(_$("cai"))_$("cai").style.display = "none";
else return;
if(_$("caie"))_$("caie").style.display = "block";
_$("author").focus();
if (_$('cogr') && _$('email').value) {
_$('cogr').src = blogurl + "/wp-content/gravatars/" + _$('email').value + '.jpg';
}
}
function hcai() {
if(_$("caie"))_$("caie").style.display = "none";
else return;
if(_$("cai"))_$("cai").style.display = "block";
_$("ca").innerHTML = _$("author").value;
_$("ca").href = _$("url").value;
}
if (typeof(md5)!="undefined") {
GetCookie("comment_author_"+md5, "author");
GetCookie("comment_author_"+md5, "authorname");
GetCookie("comment_author_email_"+md5, "email");
GetCookie("comment_author_url_"+md5, "url");
if (_$("author") && _$("author").value) {
hcai();
}
login("login");
}
document.editComment = {
callback: function(s, i){
_$('cif').style.display = 'none';
if(_$('commentIframe'))_$('commentIframe').style.display='none';
if (s) insertAtCursor(_$('comment'), i);
// _$('comment').value += i;
comment_preview(false);
_$('comment').focus();
},
addTag: function(s, l, r){
comment_preview(false);
var el = _$(s);
if (el.setSelectionRange) {
//Mozilla or FireFox Code
var st = el.scrollTop;
var ss = el.selectionStart;
var se = el.selectionEnd;
el.value = el.value.substring(0,ss) + l + el.value.substring(ss,se) + r + el.value.substring(se,el.value.length);
el.selectionStart = se+l.length+r.length;
el.selectionEnd = se+l.length+r.length;
el.scrollTop = st;
}
else if (document.selection && document.selection.createRange) {
//Internet Explorer Code
el.focus(); //Makes sure tags are being added to the textarea
var range = document.selection.createRange();
range.text = l + range.text + r; //Adds beginning and end tags.
}
el.focus();
},
init: function(u) {
_$('cif').innerHTML = '';},
constructIframe: function(u, l) {
if (!_$('commentIframe')) document.editComment.init(u);
else _$('commentIframe').src = u;
_$('cif').style.display = 'block';
},
selectText: function(e) {
if (typeof(e) == 'string') e = _$(e);
if (document.selection) {
sel = document.selection.createRange();
return sel.text;
}
//MOZILLA/NETSCAPE support
else if (e.selectionStart || e.selectionStart == '0') {
var startPos = e.selectionStart;
var endPos = e.selectionEnd;
return e.value.substr(startPos, endPos-startPos);
}
else return '';
}
};
function insertAtCursor(e, v) {
//IE support
if (document.selection && false) {
e.focus();
sel = document.selection.createRange();
sel.text = v;
}
//MOZILLA/NETSCAPE support
else if (e.selectionStart || e.selectionStart == '0') {
var startPos = e.selectionStart;
var endPos = e.selectionEnd;
e.value = e.value.substring(0, startPos) + v + e.value.substring(endPos, e.value.length);
} else {
e.value += v;
}
}
function testKeyCode( evt, intKeyCode ) {
if ( window.createPopup ) return evt.keyCode == intKeyCode;
else return evt.which == intKeyCode;
}
function addKey(e, fk) {
if (typeof(e) == 'string') e = _$(e);
if (!e) return;
if (typeof(ctr) == 'undefined') ctr = false;
if (typeof(alt) == 'undefined') alt = false;
e.onkeydown = function(evt) {
if (evt == null) evt = event;
for (k=0; k < fk.length; k++)
if (evt.ctrlKey == fk[k][2] && evt.altKey == fk[k][3] && testKeyCode(evt, fk[k][1]))
eval(fk[k][0]);
}
}
addKey('comment', [
["document.editComment.constructIframe(blogurl + '/wp-content/themes/yuewei/editlink.html');", 75, false, true],
["document.editComment.constructIframe(blogurl + '/wp-content/themes/yuewei/emotions.html');", 76, false, true],
["comment_preview(true);", 27, false, false],
["comment_preview(true);", 80, false, true],
["document.editComment.addTag('comment', '', '');", 66, false, true],
["document.editComment.addTag('comment', '', '');", 73, false, true],
["document.editComment.addTag('comment', '', '');", 85, false, true],
['AjaxSendComment();', 13, true, false],
['AjaxSendComment();', 83, false, true]
]);
function toggle(e) {
if (!e) return;
if (e.style.height != '32px') {
e.style.overflowX='hidden';e.style.overflowY='auto';e.style.height = "32px";
} else {e.style.overflow="visible"; e.style.height = '';}
}