solo-skins/metro-hot/js/metro-hot.min.js

1 line
4.0 KiB
JavaScript

var MetroHot={headerH:$("#header").height()+30+($("#header > div").get(1)?30:0),responsiveType:"large",goTranslate:function(){window.open("http://translate.google.com/translate?sl=auto&tl=auto&u="+location.href)},init:function(){var e="";$("#admin a").each((function(){$(this).attr("href").indexOf("/logout")>-1&&(e=$(this).attr("href"))})),$("#logout, .logout").attr("href",e),$(".header .title, .navigation").mouseover((function(){$(".navigation").show()})).mouseout((function(){$(".navigation").hide()})),$(".header .title").click((function(){window.location.href=Label.servePath}));var t=$("#top > span").first().text();if($(".online-count .text").append(t.substr(1,t.length)),1===$("#dynamic").length)return $(window).scroll((function(){$(window).scrollTop()>MetroHot.headerH?$("#goTop").fadeIn("slow"):$("#goTop").hide()})).click((function(e){"title"!==e.target.className&&"title"!==e.target.parentElement.className&&$(".navigation").slideUp()})),void $("body").css("min-height","inherit");$(window).scroll((function(){$(window).scrollTop()>MetroHot.headerH?$("#goTop").fadeIn("slow"):$("#goTop").hide()})).click((function(e){"title"!==e.target.className&&"title"!==e.target.parentElement.className&&$(".navigation").slideUp()})).resize((function(){var e=window.innerWidth,t="large";e>460&&e<=860?t="mid":window<460&&(t="small"),MetroHot.responsiveType!==t&&($(window).scroll(),MetroHot.responsiveType)})),$(window).scroll()},loadImg:function(e){e.style.marginTop=(220-e.height)/2+"px"},share:function(){var e=$(".share .text"),t=e.find(".icon-wechat"),a=t.data("url"),n=t.data("avatar"),i=encodeURIComponent(t.data("title")+" - "+t.data("blogtitle")),l=encodeURIComponent(a),r={};r.weibo="http://v.t.sina.com.cn/share/share.php?title="+i+"&url="+l+"&pic="+n,r.qqz="https://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url="+l+"&sharesource=qzone&title="+i+"&pics="+n,r.twitter="https://twitter.com/intent/tweet?status="+i+" "+l,e.find("span").click((function(){var e=$(this).data("type");if(e)return"wechat"===e?(0===t.find("canvas").length?$.ajax({method:"GET",url:Label.staticServePath+"/js/lib/jquery.qrcode.min.js",dataType:"script",cache:!0,success:function(){t.qrcode({width:111,height:111,text:a})}}):t.find("canvas").slideToggle(),!1):void window.open(r[e],"_blank","top=100,left=200,width=648,height=618")}))},loadRandomArticles:function(){$.ajax({url:Label.servePath+"/articles/random",type:"POST",success:function(e,t){var a=e.randomArticles;if(a&&0!==a.length){for(var n="",i=0;i<a.length&&i<5;i++){var l=a[i],r=l.articleTitle;n+="<li><a rel='nofollow' title='"+r+"' href='"+Label.servePath+l.articlePermalink+"'>"+r+"</a></li>"}var o="<ul>"+n+"</ul>";$("#randomArticles .text").append(o)}else $("#randomArticles").remove()}})},loadRelevantArticles:function(e){$.ajax({url:Label.servePath+"/article/id/"+e+"/relevant/articles",type:"GET",success:function(e,t){var a=e.relevantArticles;if(a&&0!==a.length){for(var n="",i=0;i<a.length&&i<5;i++){var l=a[i],r=l.articleTitle;n+="<li><a rel='nofollow' title='"+r+"' href='"+Label.servePath+l.articlePermalink+"'>"+r+"</a></li>"}var o="<ul>"+n+"</ul>";$("#relevantArticles .text").append(o)}else $("#relevantArticles").remove()},error:function(){$("#relevantArticles").remove()}})},loadExternalRelevantArticles:function(e){var t=this.tips;try{$.ajax({url:"http://rhythm.b3log.org:80/get-articles-by-tags.do?tags="+e+"&blogHost="+t.blogHost+"&paginationPageSize="+t.externalRelevantArticlesDisplayCount,type:"GET",cache:!0,dataType:"jsonp",error:function(){$("#externalRelevantArticles").remove()},success:function(e,t){var a=e.articles;if(a&&0!==a.length){for(var n="",i=0;i<a.length&&i<5;i++){var l=a[i],r=l.articleTitle;n+="<li><a rel='nofollow' title='"+r+"' target='_blank' href='"+l.articlePermalink+"'>"+r+"</a></li>"}var o="<ul>"+n+"</ul>";$("#externalRelevantArticles .text").append(o)}else $("#externalRelevantArticles").remove()}})}catch(e){$("#externalRelevantArticles").remove()}},goCmt:function(){$("html, body").animate({scrollTop:$(".comment-disabled").get(0).offsetTop})}};MetroHot.init(),$(".article-header").length>0&&MetroHot.share();