16 lines
7.3 KiB
JavaScript
16 lines
7.3 KiB
JavaScript
/*
|
|
* Copyright (c) 2010-2017, b3log.org & hacpai.com
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
var timeline={_COLHA:0,_COLHB:20,_initArticleList:function(){var e=$(".articles");0===e.length||$(".articles > .fn-clear").length>0||($(window).resize(function(){if("auto"===$("#hideTop").css("top")){var t=[timeline._COLHA,timeline._COLHB];e.find("article").each(function(){var e=$(this),a=t[1]>t[0],i=a?t[0]:t[1];parseInt(e.css("top"))===i&&0!==i||(e.css({top:i+"px",position:"absolute"}),a?this.className="l":this.className="r"),t[a?"0":"1"]+=parseInt(e.outerHeight(!0))}),e.height(t[0]>t[1]?t[0]:t[1])}else e.find("article").each(function(){$(this).css({position:"inherit",top:"auto"}).removeClass("r l")}),e.css("height","auto")}),$(window).resize(),$(".module img").imagesLoaded(function(){$(window).resize()}))},_initIndexList:function(){var e=$(".articles > .fn-clear");if(0!==e.length){var t=0;$(".nav-abs li").each(function(e){var a=$(this);a.hide(),t!==a.data("year")&&(t=a.data("year"),a.before("<li class='close year' onclick='timeline.toggleArchives(this, "+t+")'>"+t+"</li>"))}),$(".article-more").parent().data("count")<=$(".article-more").parent().find("article").length&&$(".article-more").remove(),$(window).resize(function(){e.each(function(){if("auto"===$("#hideTop").css("top")){var e=[timeline._COLHA+60,4*timeline._COLHB],t=$(this).find("article");0===t.length?($(this).find("h2").remove(),$(this).css("margin-bottom",0)):(t.each(function(){var t=$(this),a=e[1]>e[0],i=a?e[0]:e[1];parseInt(t.css("top"))===i&&0!==i||(t.css({top:i+"px",position:"absolute"}),a?this.className="l":this.className="r"),e[a?"0":"1"]+=parseInt(t.outerHeight(!0))}),$(this).height(e[0]>e[1]?e[0]:e[1]))}else{var t=$(this).find("article");0===t.length?($(this).find("h2").remove(),$(this).css("margin-bottom",0)):(t.each(function(){$(this).css({position:"inherit",top:"auto"}).removeClass("r l")}),$(this).css("height","auto"))}})}),$(window).resize(),$(".module img").imagesLoaded(function(){$(window).resize()})}},_setNavCurrent:function(){$(".header li a").each(function(){$(this).prop("href")===location.href.split("#")[0]?this.className="current":this.className=""})},init:function(){$(window).scroll(function(){$(window).scrollTop()>60?$(".ico-top").show():$(".ico-top").hide()}),timeline._initIndexList(),timeline._initArticleList(),timeline._setNavCurrent(),$(".ico-list").click(function(){"0px"===$(".header > .container > form").css("height")?$(".header > .container > ul, .header > .container > form").css({height:"auto"}):$(".header > .container > ul, .header > .container > form").animate({height:"0px"})})},translate:function(){window.open("http://translate.google.com/translate?sl=auto&tl=auto&u="+location.href)},getArchive:function(e,t,a){var i=e+t,s=e+"/"+t;if(window.location.hash="#"+i,0===$("#"+i+" > article").length){var n=e+" "+Label.yearLabel+" "+t+" "+Label.monthLabel;"en"===Label.localeString.substring(0,2)&&(n=a+" "+e);var r='<h2><span class="article-archive">'+n+'</span></h2><div class="article-more" onclick="timeline.getNextPage(this, \''+s+'\')" data-page="0">'+Label.moreLabel+"</div>";$("#"+i).html(r).css("margin-bottom","50px"),timeline.getNextPage($("#"+i).find(".article-more")[0],s)}},getNextPage:function(e,t){var a=$(e),i=a.data("page")+1,s="/articles/";if(1===$("#tag").length){var n=location.pathname.split("/");s="/articles/tags/"+n[n.length-1]+"/"}else if(1===$("#author").length){var n=location.pathname.split("/");s="/articles/authors/"+n[n.length-1]+"/"}else t&&(s="/articles/archives/"+t+"/");$.ajax({url:latkeConfig.servePath+s+i,type:"GET",beforeSend:function(){a.css("background","url("+latkeConfig.staticServePath+"/skins/timeline/images/ajax-loader.gif) no-repeat scroll center center #60829F").text("")},success:function(e,t){if(!e.sc)return void a.css("background","none #60829F").text("Error");if(0===e.rslts.articles.length)return void a.remove();for(var s="",n=e.rslts.pagination,r=0;r<e.rslts.articles.length;r++){var o=e.rslts.articles[r];s+='<article><div class="module"><div class="dot"></div><div class="arrow"></div><time class="article-time"><span>'+Util.toDate(o.articleCreateTime,"yy-MM-dd HH:mm")+'</span></time><h3 class="article-title"><a rel="bookmark" href="'+latkeConfig.servePath+o.articlePermalink+'">'+o.articleTitle+"</a>",o.hasUpdated&&(s+="<sup>"+Label.updatedLabel+"</sup>"),o.articlePutTop&&(s+="<sup>"+Label.topArticleLabel+"</sup>"),s+="</h3><p>"+o.articleAbstract+'</p><span class="ico-tags ico" title="'+Label.tagLabel+'">';for(var l=o.articleTags.split(","),c=0;c<l.length;c++)s+='<a rel="category tag" href="'+latkeConfig.servePath+"/tags/"+encodeURIComponent(l[c])+'">'+l[c]+"</a>",c<l.length-1&&(s+=",");s+='</span> <span class="ico-author ico" title="'+Label.authorLabel+'"><a rel="author" href="'+latkeConfig.servePath+"/authors/"+o.authorId+'">'+o.authorName+'</a></span> <span class="ico-comment ico" title="'+Label.commentLabel+'"><a rel="nofollow" href="'+latkeConfig.servePath+o.articlePermalink+'#comments">'+(0===o.articleCommentCount?Label.noCommentLabel:o.articleCommentCount)+'</a></span> <span class="ico-view ico" title="'+Label.viewLabel+'"><a rel="nofollow" href="${servePath}${article.articlePermalink}">'+o.articleViewCount+"</a></span></div></article>"}a.before(s).data("page",i),n.paginationPageCount<=i?a.remove():a.css("background","none #60829F").text(Label.moreLabel),$(window).resize(),$(".module img").imagesLoaded(function(){$(window).resize()})}})},toggleArchives:function(e,t){$(".nav-abs li").each(function(a){var i=$(this);i.hasClass("year")||(i.hide(),t===i.data("year")&&$(e).hasClass("close")&&i.show())}),$(".nav-abs li.year").each(function(){parseInt($(this).text())===t?$(e).hasClass("close")?e.className="year open":e.className="year close":this.className="year close"})}};!function(e,t){"use strict";var a="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";e.fn.imagesLoaded=function(i){function s(){var t=e(m),a=e(u);l&&(u.length?l.reject(h,t,a):l.resolve(h)),e.isFunction(i)&&i.call(o,h,t,a)}function n(e){r(e.target,"error"===e.type)}function r(t,i){t.src!==a&&e.inArray(t,d)===-1&&(d.push(t),i?u.push(t):m.push(t),e.data(t,"imagesLoaded",{isBroken:i,src:t.src}),c&&l.notifyWith(e(t),[i,h,e(m),e(u)]),h.length===d.length&&(setTimeout(s),h.unbind(".imagesLoaded",n)))}var o=this,l=e.isFunction(e.Deferred)?e.Deferred():0,c=e.isFunction(l.notify),h=o.find("img").add(o.filter("img")),d=[],m=[],u=[];return e.isPlainObject(i)&&e.each(i,function(e,t){"callback"===e?i=t:l&&l[e](t)}),h.length?h.bind("load.imagesLoaded error.imagesLoaded",n).each(function(i,s){var n=s.src,o=e.data(s,"imagesLoaded");return o&&o.src===n?void r(s,o.isBroken):s.complete&&s.naturalWidth!==t?void r(s,0===s.naturalWidth||0===s.naturalHeight):void((s.readyState||s.complete)&&(s.src=a,s.src=n))}):s(),l?l.promise(o):o}}(jQuery),function(){Util.init(),Util.replaceSideEm($(".comments .article-body")),Util.buildTags("tagsSide"),timeline.init()}(); |