Files
leanote/public/blog/js/ck/common-min.js
2015-01-08 00:36:28 +08:00

1 line
6.8 KiB
JavaScript

function reIsOk(e){return e&&"object"==typeof e&&e.Ok}function showAlert(e,t,n,o){$(e).html(t).removeClass("alert-danger").removeClass("alert-success").removeClass("alert-warning").addClass("alert-"+n).show(),o&&$(o).focus()}function hideAlert(e,t){t?setTimeout(function(){$(e).hide()},t):$(e).hide()}function ajaxGet(e,t,n){$.get(e,t,n)}function ajaxPost(e,t,n){$.post(e,t,n)}function ajaxGetP(e,t,n){ajaxP("GET",e,t,n)}function ajaxPostP(e,t,n){ajaxP("POST",e,t,n)}function ajaxP(e,t,n,o){n=n||{},o=o||function(){},$.ajax({dataType:"jsonp",url:t,type:e,data:n,jsonp:"callback",jsonpCallback:"jsonpCallback",success:o})}function getShareUrl(){return location.href}function getShareTitle(e){return encodeURI(e+" (来自leanote.com)")}function shareSinaWeibo(e,t,n){var o="http://service.weibo.com/share/share.php?title="+getShareTitle(t)+"&url="+getShareUrl(e);window.open(o,"Share",windowParam)}function shareTencentWeibo(e,t,n){var o="801542571",i="http://share.v.t.qq.com/index.php?c=share&a=index&appkey="+o+"&title="+getShareTitle(t)+"&url="+getShareUrl(e)+"&pic="+n;window.open(i,"Share",windowParam)}function shareQQ(e,t,n){var o="http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url="+getShareUrl(e)+"&title="+t+"&pics="+n;window.open(o,"Share",windowParam)}function shareRenRen(e,t,n){var o="http://widget.renren.com/dialog/share?resourceUrl="+getShareUrl(e)+"&srcUrl="+getShareUrl(e)+"&title="+getShareTitle(t)+"&pic="+n;window.open(o,"Share",windowParam)}function shareTwitter(e,t,n){var o="https://twitter.com/intent/tweet?text="+getShareTitle(t)+"&pic="+n;window.open(o,"Share",windowParam)}function shareFacebook(e,t,n){var o=" http://www.facebook.com/sharer.php?t="+getShareTitle(t)+"&pic="+n;window.open(o,"Share",windowParam)}function goNowToDatetime(e){return e?e.substr(0,10)+" "+e.substr(11,8):""}function goNowToDate(e){if(!e)return"";var t=e.substr(0,10)+" "+e.substr(11,8),n=t.split(" "),o=n[0].split("-"),i=parseInt(o[0],10),a=parseInt(o[1],10)-1,r=parseInt(o[2],10),s=n[1].split(":"),l=parseInt(s[0],10),c=parseInt(s[1],10)-1,d=parseInt(s[2],10),f=new Date(i,a,r,l,c,d);return f}function getDateDiff(e){var t=(new Date).getTime(),n=t-e;if(0>n)return"";var o=n/diff.month,i=n/(7*diff.day),a=n/diff.day,r=n/diff.hour,s=parseInt(n/diff.minute);return result=o>=1?parseInt(o)+"个月前":i>=1?parseInt(i)+"周前":a>=1?parseInt(a)+"天前":r>=1?parseInt(r)+"小时前":s>1?s+"分钟前":"刚刚"}function weixin(){var e=window.location.href,t=$.trim($(".title").text()),n=$.trim($("#desc").text()),o=$("#content img").eq(0).attr("src");window.shareData={imgUrl:o,timeLineLink:e,sendFriendLink:e,weiboLink:e,tTitle:t,tContent:n,fTitle:t,fContent:n,wContent:n},document.addEventListener("WeixinJSBridgeReady",function i(){WeixinJSBridge.on("menu:share:appmessage",function(e){WeixinJSBridge.invoke("sendAppMessage",{img_url:window.shareData.imgUrl,img_width:"200",link:window.shareData.sendFriendLink,desc:window.shareData.fContent,title:window.shareData.fTitle},function(e){hs_guide("none"),_report("send_msg",e.err_msg)})}),WeixinJSBridge.on("menu:share:timeline",function(e){WeixinJSBridge.invoke("shareTimeline",{img_url:window.shareData.imgUrl,img_width:"200",link:window.shareData.timeLineLink,desc:window.shareData.tContent,title:window.shareData.tTitle},function(e){hs_guide("none"),_report("timeline",e.err_msg)})}),WeixinJSBridge.on("menu:share:weibo",function(e){WeixinJSBridge.invoke("shareWeibo",{content:window.shareData.wContent,url:window.shareData.weiboLink},function(e){hs_guide("none"),_report("weibo",e.err_msg)})})},!1)}function scrollTo(e,t,n){for(var o=$("#content"),i=o.find(t+":contains("+n+")"),a=$('#blogNavContent [data-a="'+t+"-"+encodeURI(n)+'"]'),r=a.size(),s=0;r>s&&a[s]!=e;++s);if(i.size()>=s+1){i=i.eq(s);var l=i.offset().top;LEA.isMobile&&(l-=50);var c=$(document).scrollTop();return void $("html,body").animate({scrollTop:l},200)}}function genNav(){for(var e=$("#content"),t=e.html(),n=[],o=e.find("h1,h2,h3,h4,h5,h6").toArray(),i="<ul>",a=0;a<o.length;++a){var r=$(o[a]).text(),s=o[a].tagName.toLowerCase();i+='<li class="nav-'+s+'"><a data-a="'+s+"-"+encodeURI(r)+'" onclick="scrollTo(this, \''+s+"', '"+r+"')\">"+r+"</a></li>"}return i+="</ul>",$("#blogNavContent").html(i),o.length?!0:($("#blogNavContent").html("无"),!1)}function initNav(){function e(){var e=r.scrollTop();i>=e?$("#blogNav").css("top",i-e):LEA.isMobile?$("#blogNav").css("top",50):$("#blogNav").css("top",10)}var t=genNav();if(t){var n=$(".title"),o=n.offset(),i=o.top+10;LEA.isMobile&&(i+=30),0>i&&(i=10);var a=n.width()+o.left-100;$("#blogNav").css("top",i).css("left",a),$("#blogNav").show(),$("#blogNavNav").click(function(){var e=$("#blogNavContent");e.is(":hidden")?e.show():e.hide()});var r=$(document);e(),$(window).scroll(e)}}function goLogin(){var e=siteUrl+"/login?from="+encodeURI(location.href);location.href=e}function goRegister(){var e=siteUrl+"/register?from="+encodeURI(location.href);location.href=e}function needLogin(){if("undefined"==typeof visitUserInfo||!visitUserInfo||!visitUserInfo.UserId){var e=siteUrl+"/login?from="+encodeURI(location.href),t=siteUrl+"/register?from="+encodeURI(location.href);try{var n=BootstrapDialog.show({title:"你还未登录",message:'<div class="needLogin" style="border:none"><a href="'+e+'">立即登录</a>, 发表评论.<br />没有帐号? <a href="'+t+'">立即注册</a>',nl2br:!1})}catch(o){}return!0}return!1}function scrollToTarget(e,t){t||(t=0);var n=$(e),o=n.offset().top+t;$("html,body").animate({scrollTop:o},300)}function getCurVisitUserInfo(){}function incReadNum(e){$.cookie(e)||($.cookie(e,1),ajaxGet(getCurHostUrl()+"/blog/incReadNum",{noteId:e}))}function getCurHostUrl(){return"//"+location.host}function getLeanoteUrl(){return siteUrl||"http://leanote.com"}function getPostStat(e,t){ajaxGet(getCurHostUrl()+"/blog/getPostStat",{noteId:e},t)}function getLikes(e,t){ajaxGetP(getLeanoteUrl()+"/blog/getLikes",{noteId:e},t)}function getLikesAndComments(e,t){ajaxGetP(getLeanoteUrl()+"/blog/getLikesAndComments",{noteId:e},t)}function getComments(e,t){ajaxGetP(getLeanoteUrl()+"/blog/listComments",{noteId:e,page:t},callback)}function likePost(e,t){ajaxPostP(getLeanoteUrl()+"/blog/likePost",{noteId:e},t)}function commentPost(e,t,n,o){var i={noteId:self.noteId,toCommentId:t,content:n};ajaxPostP(getLeanoteUrl()+"/blog/commentPost",i,o)}function deleteComment(e,t,n){ajaxPostP(getLeanoteUrl()+"/blog/deleteComment",{noteId:e,commentId:t},n)}function likeComment(e,t){ajaxPostP(getLeanoteUrl()+"/blog/likeComment",{commentId:e},t)}function isMobile(){var e=navigator.userAgent;LEA.isMobile=!1,LEA.isMobile=/Mobile|Android|iPhone/i.test(e),!LEA.isMobile&&$(document).width()<=600&&(LEA.isMobile=!0)}var windowParam="width=700, height=580, top=180, left=320, toolbar=no, menubar=no, scrollbars=no, location=yes, resizable=no, status=no",diff={minute:6e4,hour:36e5,day:864e5,halfamonth:1296e6,month:2592e6},LEA={isMobile:!1};$(function(){isMobile()});