/*
* Solo - A small and beautiful blogging system written in Java.
* Copyright (c) 2010-2019, b3log.org & hacpai.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
/**
* @fileoverview ease js.
*
* @author Liyuan Li
* @version 1.0.1.3, Aug 6, 2012
*/
var goTranslate = function () {
window.open("http://translate.google.com/translate?sl=auto&tl=auto&u=" + location.href);
};
var getNextPage = function () {
var $more = $(".article-next");
currentPage += 1;
var path = "/articles/";
if(location.pathname.indexOf("tags") > -1) {
var tagsPathnaem = location.pathname.split("/tags/");
var tags = tagsPathnaem[1].split("/");
path = "/articles/tags/" + tags[0] + "/";
} else if (location.pathname.indexOf("archives") > -1) {
var archivesPathname = location.pathname.split("/archives/");
var archives = archivesPathname[1].split("/");
path = "/articles/archives/" + archives[0] + "/" + archives[1] + "/";
}
$.ajax({
url: latkeConfig.staticServePath + path + currentPage,
type: "GET",
beforeSend: function () {
$more.css("background",
"url(" + latkeConfig.staticServePath + "/skins/ease/images/ajax-loader.gif) no-repeat scroll center center #fefefe");
},
success: function(result, textStatus){
if (!result.sc) {
return;
}
var articlesHTML = "",
pagination = result.rslts.pagination;
// append articles
for (var i = 0; i < result.rslts.articles.length; i++) {
var article = result.rslts.articles[i],
lastClass = "";
if (result.rslts.articles.length - 1 === i) {
lastClass = " article-last";
}
articlesHTML += '
' +
'' +
'
' +
'' +
article.articleTitle +
'';
if (article.hasUpdated) {
articlesHTML += '' + Label.updatedLabel + '';
}
if (article.articlePutTop) {
articlesHTML += '' + Label.topArticleLabel + '';
}
articlesHTML += '
' +
'
' +
'
' +
'
' +
'' +
'
' +
article.articleAbstract +
'
' +
'
' +
'
' +
'';
if (article.hasUpdated) {
articlesHTML += Util.toDate(article.articleUpdateDate, 'yy-MM-dd HH:mm');
} else {
articlesHTML += Util.toDate(article.articleCreateDate, 'yy-MM-dd HH:mm');
}
articlesHTML += '
' + article.authorName + '' +
'
' +
'' +
Label.tag1Label + " ";
var articleTags = article.articleTags.split(",");
for (var j = 0; j < articleTags.length; j++) {
articlesHTML += '
' +
articleTags[j] + '';
if (j < articleTags.length - 1) {
articlesHTML += ", ";
}
}
articlesHTML += '
' +
'' +
'';
}
$(".article-last").removeClass("article-last");
$(".main>.wrapper>ul").append(articlesHTML);
// 最后一页处理
if (pagination.paginationPageCount === currentPage) {
$more.remove();
} else {
$more.css("background", "none");
}
}
});
};
var ease = {
$header: $(".header"),
headerH: 103,
$body: $(".main > .wrapper"),
$nav: $(".nav"),
getCurrentPage: function () {
var $next = $(".article-next");
if ($next.length > 0) {
window.currentPage = $next.data("page");
}
},
setNavCurrent: function () {
$(".nav ul a").each(function () {
var $this = $(this);
if ($this.attr("href") === latkeConfig.servePath + location.pathname) {
$this.addClass("current");
} else if (/\/[0-9]+$/.test(location.pathname)) {
$(".nav ul li")[0].className = "current";
}
});
},
initCommon: function () {
Util.replaceSideEm($(".recent-comments-content"));
Util.buildTags("tagsSide");
},
initArchives: function () {
var $archives = $(".archives");
if ($archives.length < 1) {
return;
}
$(".footer").css("marginTop", "30px");
var years = [],
$archiveList = $archives.find("span").each(function () {
var year = $(this).data("year"),
tag = true;
for (var i = 0; i < years.length; i++) {
if (year === years[i]) {
tag = false;
break;
}
}
if (tag) {
years.push(year);
}
});
var yearsHTML = "";
for (var j = 0; j < years.length; j++) {
var monthsHTML = "";
for (var l = 0; l < $archiveList.length; l++) {
var $month = $($archiveList[l]);
if ($month.data("year") === years[j]) {
monthsHTML += $month.html();
}
}
yearsHTML += "" + years[j] + "
" + monthsHTML + "";
}
$archives.html(yearsHTML);
// position
var $items = $(".archives>div"),
line = 0,
top = 0,
heights = [];
for (var m = 0; m < $items.length; m++) {
for (var n = 0; n < 3; n++) {
if (m >= $items.length) {
break;
}
$items[m].style.left = (n * 310) + "px";
if (line > 0) {
if ($items[m - 3].style.top !== "") {
top = parseInt($items[m - 3].style.top);
}
$items[m].style.top = $($items[m - 3]).height() + 60 + top + "px";
heights[n] = parseInt($items[m].style.top) + $($items[m]).height() + 60;
} else {
heights[n] = $($items[m]).height() + 60;
}
if (n < 2) {
m += 1;
}
}
line += 1;
}
// archive height
$archives.height(heights.sort()[heights.length - 1]);
},
scrollEvent: function () {
var _it = this;
$(window).scroll(function () {
var y = $(window).scrollTop(),
topH = 0;
if ($("#top").css("display") === "block") {
topH = $("#top").height();
}
// header event
if (y >= _it.headerH + topH) {
_it.$nav.css("position", "fixed");
_it.$body.css("marginTop", "55px");
} else {
_it.$nav.css("position" ,"inherit");
_it.$body.css("marginTop", "0");
}
// go top icon show or hide
if (y > _it.headerH) {
var bodyH = $(window).height();
var top = y + bodyH - 21;
if ($("body").height() - 58 <= y + bodyH) {
top = $(".footer").offset().top - 21;
}
$("#goTop").fadeIn("slow").css("top", top);
} else {
$("#goTop").hide();
}
});
},
setDynamic: function () {
var $dynamic = $(".dynamic");
if ($(".dynamic").length < 1) {
return;
}
var $comments = $dynamic.find(".side-comments"),
$tags = $dynamic.find(".side-tags"),
$mostComment = $dynamic.find(".side-most-comment"),
$mostView = $dynamic.find(".side-most-view");
if ($comments.height() > $tags.height()) {
$tags.height($comments.height());
} else {
$comments.height($tags.height());
}
if ($mostComment.height() > $mostView.height()) {
$mostView.height($mostComment.height());
} else {
$mostComment.height($mostView.height());
}
// emotions
$(".vditor-reset").each(function () {
this.innerHTML = Util.replaceEmString($(this).html());
});
}
};
(function () {
ease.getCurrentPage();
ease.initCommon();
ease.scrollEvent();
ease.setNavCurrent();
ease.initArchives();
ease.setDynamic();
})();