PageRenderTime 64ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/b3log-solo-skins/ease/js/ease.js

http://b3log-solo.googlecode.com/
JavaScript | 306 lines | 238 code | 40 blank | 28 comment | 44 complexity | 6910e52ef130b0a9aad930bd78841888 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.1
  1. /*
  2. * Copyright (c) 2009, 2010, 2011, 2012, B3log Team
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /**
  17. * @fileoverview ease js.
  18. *
  19. * @author <a href="mailto:LLY219@gmail.com">Liyuan Li</a>
  20. * @version 1.0.0.9, May 28, 2012
  21. */
  22. var goTranslate = function () {
  23. window.open("http://translate.google.com/translate?sl=auto&tl=auto&u=" + location.href);
  24. };
  25. var getNextPage = function () {
  26. var $more = $(".article-next");
  27. currentPage += 1;
  28. var path = "/articles/";
  29. if(location.pathname.indexOf("tags") > -1) {
  30. var tagsPathnaem = location.pathname.split("/tags/");
  31. var tags = tagsPathnaem[1].split("/");
  32. path = "/articles/tags/" + tags[0] + "/";
  33. } else if (location.pathname.indexOf("archives") > -1) {
  34. var archivesPathname = location.pathname.split("/archives/");
  35. var archives = archivesPathname[1].split("/");
  36. path = "/articles/archives/" + archives[0] + "/" + archives[1] + "/";
  37. }
  38. $.ajax({
  39. url: latkeConfig.staticServePath + path + currentPage,
  40. type: "GET",
  41. beforeSend: function () {
  42. $more.css("background",
  43. "url(" + latkeConfig.staticServePath + "/skins/ease/images/ajax-loader.gif) no-repeat scroll center center #fefefe");
  44. },
  45. success: function(result, textStatus){
  46. if (!result.sc) {
  47. return;
  48. }
  49. var articlesHTML = "",
  50. pagination = result.rslts.pagination;
  51. // append articles
  52. for (var i = 0; i < result.rslts.articles.length; i++) {
  53. var article = result.rslts.articles[i];
  54. articlesHTML += '<li class="article">' +
  55. '<div class="article-title">' +
  56. '<h2>' +
  57. '<a rel="bookmark" class="ft-gray" href="' + latkeConfig.servePath + article.articlePermalink + '">' +
  58. article.articleTitle +
  59. '</a>';
  60. if (article.hasUpdated) {
  61. articlesHTML += '<sup>' + Label.updatedLabel + '</sup>';
  62. }
  63. if (article.articlePutTop) {
  64. articlesHTML += '<sup>' + Label.topArticleLabel + '</sup>';
  65. }
  66. articlesHTML += '</h2>' +
  67. '<div class="right">' +
  68. '<a rel="nofollow" class="ft-gray" href="' + latkeConfig.servePath + article.articlePermalink + '#comments">' +
  69. + article.articleCommentCount + '&nbsp;&nbsp;' + Label.commentLabel +
  70. '</a>&nbsp;&nbsp;' +
  71. '<a rel="nofollow" class="ft-gray" href="' + latkeConfig.servePath + article.articlePermalink + '">' +
  72. article.articleViewCount + '&nbsp;&nbsp;' + Label.viewLabel +
  73. '</a>' +
  74. '</div>' +
  75. '<div class="clear"></div>' +
  76. '</div>' +
  77. '<div class="article-body">' +
  78. '<div id="abstract' + article.oId + '">' +
  79. article.articleAbstract +
  80. '</div>' +
  81. '<div id="content' + article.oId + '" class="none"></div>' +
  82. '</div>' +
  83. '<div class="article-info">' +
  84. '<div class="right ft-gray">';
  85. if (article.hasUpdated) {
  86. articlesHTML += Util.toDate(article.articleUpdateDate, 'yy-MM-dd HH:mm');
  87. } else {
  88. articlesHTML += Util.toDate(article.articleCreateDate, 'yy-MM-dd HH:mm');
  89. }
  90. articlesHTML += ' <a href="' + latkeConfig.servePath + '/authors/' + article.authorId + '">' + article.authorName + '</a>' +
  91. '</div>' +
  92. '<div class="left ft-gray">' +
  93. Label.tag1Label + " ";
  94. var articleTags = article.articleTags.split(",");
  95. for (var j = 0; j < articleTags.length; j++) {
  96. articlesHTML += '<a rel="tag" href="' + latkeConfig.servePath + '/tags/' + encodeURIComponent(articleTags[j]) + '">' +
  97. articleTags[j] + '</a>';
  98. if (j < articleTags.length - 1) {
  99. articlesHTML += ", ";
  100. }
  101. }
  102. articlesHTML += '</div>' +
  103. '<div class="clear"></div>' +
  104. '</div>' +
  105. '</li>';
  106. }
  107. $(".body>ul").append(articlesHTML);
  108. // ??????
  109. if (pagination.paginationPageCount === currentPage) {
  110. $more.remove();
  111. } else {
  112. $more.css("background", "none");
  113. }
  114. }
  115. });
  116. };
  117. var ease = {
  118. $header: $(".header"),
  119. $banner: $(".header").find(".banner"),
  120. headerH: $(".header").height(),
  121. $body: $(".body"),
  122. $nav: $(".nav"),
  123. getCurrentPage: function () {
  124. var $next = $(".article-next");
  125. if ($next.length > 0) {
  126. window.currentPage = $next.data("page");
  127. }
  128. },
  129. setNavCurrent: function () {
  130. $(".nav ul a").each(function () {
  131. var $this = $(this);
  132. if ($this.attr("href") === latkeConfig.servePath + location.pathname) {
  133. $this.addClass("current");
  134. } else if (/\/[0-9]+$/.test(location.pathname)) {
  135. $(".nav ul li")[0].className = "current";
  136. }
  137. });
  138. },
  139. initCommon: function () {
  140. Util.init();
  141. Util.replaceSideEm($(".recent-comments-content"));
  142. Util.buildTags("tagsSide");
  143. this.$body.css("paddingTop", this.headerH + "px");
  144. },
  145. initArchives: function () {
  146. var $archives = $(".archives");
  147. if ($archives.length < 1) {
  148. return;
  149. }
  150. var years = [],
  151. $archiveList = $archives.find("span").each(function () {
  152. var year = $(this).data("year"),
  153. tag = true;
  154. for (var i = 0; i < years.length; i++) {
  155. if (year === years[i]) {
  156. tag = false;
  157. break;
  158. }
  159. }
  160. if (tag) {
  161. years.push(year);
  162. }
  163. });
  164. var yearsHTML = "";
  165. for (var j = 0; j < years.length; j++) {
  166. var monthsHTML = "";
  167. for (var l = 0; l < $archiveList.length; l++) {
  168. var $month = $($archiveList[l]);
  169. if ($month.data("year") === years[j]) {
  170. monthsHTML += $month.html();
  171. }
  172. }
  173. yearsHTML += "<div><h3 class='ft-gray'>" + years[j] + "</h3>" + monthsHTML + "</div>";
  174. }
  175. $archives.html(yearsHTML);
  176. // position
  177. var $items = $(".archives>div"),
  178. line = 0,
  179. top = 0,
  180. heights = [];
  181. for (var m = 0; m < $items.length; m++) {
  182. for (var n = 0; n < 3; n++) {
  183. if (m >= $items.length) {
  184. break;
  185. }
  186. $items[m].style.left = (n * 318) + "px";
  187. if (line > 0) {
  188. if ($items[m - 3].style.top !== "") {
  189. top = parseInt($items[m - 3].style.top);
  190. }
  191. $items[m].style.top = $($items[m - 3]).height() + 60 + top + "px";
  192. heights[n] = parseInt($items[m].style.top) + $($items[m]).height() + 60;
  193. } else {
  194. heights[n] = $($items[m]).height() + 60;
  195. }
  196. if (n < 2) {
  197. m += 1;
  198. }
  199. }
  200. line += 1;
  201. }
  202. // archive height
  203. $archives.height(heights.sort()[2]);
  204. },
  205. scrollEvent: function () {
  206. var _it = this;
  207. $(window).scroll(function () {
  208. var y = $(window).scrollTop();
  209. // header event
  210. if (y >= _it.headerH && _it.$banner.css("display") === "block" &&
  211. $("body").height() - $(window).height() > _it.headerH * 2) {
  212. _it.$header.css("top", "0");
  213. _it.$banner.css("display", "none");
  214. _it.$body.css("paddingTop", _it.$nav.height() + "px");
  215. }
  216. if (y < _it.headerH && _it.$banner.css("display") === "none") {
  217. _it.$header.css("top", "auto");
  218. _it.$banner.css("display", "block");
  219. _it.$body.css("paddingTop", _it.headerH + "px");
  220. }
  221. // go top icon show or hide
  222. if (y > _it.headerH) {
  223. var bodyH = $(window).height();
  224. var top = y + bodyH - 21;
  225. if ($("body").height() - 58 <= y + bodyH) {
  226. top = $(".footer").offset().top - 21;
  227. }
  228. $("#goTop").fadeIn("slow").css("top", top);
  229. } else {
  230. $("#goTop").hide();
  231. }
  232. });
  233. },
  234. setDynamic: function () {
  235. var $dynamic = $(".dynamic");
  236. if ($(".dynamic").length < 1) {
  237. return;
  238. }
  239. var $comments = $dynamic.find(".side-comments"),
  240. $tags = $dynamic.find(".side-tags"),
  241. $mostComment = $dynamic.find(".side-most-comment"),
  242. $mostView = $dynamic.find(".side-most-view");
  243. if ($comments.height() > $tags.height()) {
  244. $tags.height($comments.height());
  245. } else {
  246. $comments.height($tags.height());
  247. }
  248. if ($mostComment.height() > $mostView.height()) {
  249. $mostView.height($mostComment.height());
  250. } else {
  251. $mostComment.height($mostView.height());
  252. }
  253. // emotions
  254. $(".article-body").each(function () {
  255. this.innerHTML = Util.replaceEmString($(this).html());
  256. });
  257. }
  258. };
  259. (function () {
  260. ease.getCurrentPage();
  261. ease.initCommon();
  262. ease.scrollEvent();
  263. ease.setNavCurrent();
  264. ease.initArchives();
  265. ease.setDynamic();
  266. })();