1 line
7.1 KiB
JavaScript
1 line
7.1 KiB
JavaScript
"use strict";var pageCount,home_loading_timeout=2e3,isLoading=!1,timeout=1e3,contentTimeout=1500,begin=new Date,contentBegin=new Date,tooltip_timeout=1500;function requestData(){$.ajax({url:$("#filterForm")[0].action,type:$("#filterForm")[0].method,data:$("#filterForm").serialize(),success:function(t){var e=new Date,a=t.posts;(pageCount=t.pageCount,timeout<e-begin)?addPage($("#PageIndex").val(),a):setTimeout(function(){addPage($("#PageIndex").val(),a)},timeout-(e-begin))}})}function appendContent(a){$(".sk-cube-grid").hide(),$(".post-content div").removeClass("markdown-body normal-body").addClass("markdown"===a.ContentType?"markdown-body":"normal-body"),$(".post-content div").html(a.Content);var t=JSON.parse(a.Labels);$.each(t,function(t,e){$("#label-foot").append('<span title="'+e.text+'" class="post-label">'+e.text+"</span>")}),$(".post-modal .modal-body").mCustomScrollbar("scrollTo","top",{scrollInertia:0}),$(".post-content div").fadeIn(),$(".post-content pre").each(function(t,e){a.ContentType||$(e).html($("<code></code>").html($(e).html())),hljs.highlightBlock($(e).children("code")[0])})}function closeModal(){$(".post-modal").css("right","-1200px"),$(".post-cover").fadeOut(),$("body").removeClass("modal-open")}function resetModal(){$(".post-modal .modal-header h4").empty(),$(".post-content div").empty(),$("#label-foot").empty()}function searchPost(){var t=$("#Keyword");t.val()?($(".list-wrap ol").html(""),$("[data-toggle='tooltip']").tooltip("hide"),$("#page-nav").html(""),$("#btn-load").remove(),$("#no-more").remove(),begin=new Date,$("#load-list").show(),$("#PageIndex").val(1),requestData()):t.focus()}function addPage(o,t){if($("#load-list").hide(),0<t.length){$(".list-wrap ol").append('<li id="page'+o+'"></li>'),$.each(t,function(t,e){var a;a="1"==e.Source?'<div uid="'+e.Alias+'" class="blog-item '+(0<$(".home-loading").length?"":"animated fadeIn")+'"> <h4> <a title="'+e.Title+'" target="_blank" href="'+e.Url+'"><i class="fa fa-link"></i> '+e.Title+' </a> </h4> <span title="文章分类"> <i class="fa fa-map-signs"> </i> <a href="/blog/'+e.CategoryAlias+'" target="_blank">'+e.CateName+'</a> </span> <span title="发布时间" class="margin-left-20"> <i class="fa fa-clock-o"> </i> '+e.PublishDate+' </span> <a title="'+e.Host+'" target="_blank" href="'+e.Url.substring(0,e.Url.indexOf("://")+3)+e.Host+'" class="pull-right margin-left-20 hidden-xs"> <i class="fa fa-globe-americas"></i> '+e.Host+' </a> <div class="clearfix"> </div> <p> '+encodeHtml(e.Summary)+' </p></div><div class="hr-line-dashed"></div>':'<div class="blog-item '+(0<$(".home-loading").length?"":"animated fadeIn")+'" uid="'+e.Alias+'"><a class="preview-link" title="点击预览"></a><h4><a href="/blog/'+e.CategoryAlias+"/"+e.Alias+'" target="_blank" title="'+e.Title+'">'+e.Title+'</a></h4><span title="文章分类"><i class="fa fa-map-signs"></i> <a href="/blog/'+e.CategoryAlias+'" target="_blank">'+e.CateName+'</a></span> <span class="margin-left-20" title="发布时间"><i class="fa fa-clock-o"></i> '+e.PublishDate+'</span><div class="clearfix"></div><p>'+encodeHtml(e.Summary)+'</p></div><div class="hr-line-dashed"></div>',$("#page"+o).append(a)}),$("body").append('<script id="cy_cmt_num" src="http://changyan.sohu.com/upload/plugins/plugins.list.count.js?clientId=cyrUoGjWj"><\/script>');var e=$('<li><a href="javascript:void(0)" page="'+o+'" data-toggle="tooltip" data-placement="right" title="第'+o+'页"></a></li>');e.appendTo($("#page-nav"));var a=100/o;$("#page-nav li").css("height",a+"%"),$("[data-toggle='tooltip']:visible").tooltip({container:"body"}),e.find("a").tooltip("show"),setTimeout(function(){e.find("a").tooltip("hide")},tooltip_timeout),$("#PageIndex").val()==pageCount?1!=pageCount&&$(".list-wrap").append('<div id="no-more" class="text-muted text-center">没有更多数据</div>'):$(".list-wrap").append('<button id="btn-load" class="btn btn-white btn-block">下一页</button>')}else $(".list-wrap ol").append('<li id="page'+o+'"></li>'),$("#page"+o).append('<div class="text-center text-muted" style="line-height: 34px;">暂无数据</div>');if(isLoading=!1,0<$(".home-loading").length){var i=new Date;if($("[data-toggle='tooltip']").tooltip("hide"),i-home_loading_begin>home_loading_timeout)$(".home-loading").remove(),document.body.style.overflow="auto";else{var n=home_loading_timeout-(i-home_loading_begin);setTimeout(function(){$(".home-loading").remove(),document.body.style.overflow="auto"},n)}}}function encodeHtml(t){return"string"!=typeof t?t:t.replace(/"|&|'|<|>|[\x00-\x20]|[\x7F-\xFF]|[\u0100-\u2700]/g,function(t){var e=t.charCodeAt(0),a=["&#"];return e=32==e?160:e,a.push(e),a.push(";"),a.join("")})}$(function(){$(".my-nav-pills li:eq(0)").addClass("active").siblings().removeClass("active"),$("#load-list").show(),$("#PageIndex").val(1),requestData(),$(".category-list").mCustomScrollbar({axis:"y",theme:"dark-3"}),$(window).scroll(function(){$("[data-toggle='tooltip']").tooltip("hide")}),$("[data-toggle='tooltip']").tooltip({container:"body"}),$(document).on({click:function(){$(this).remove(),begin=new Date,$("#load-list").show(),isLoading=!0,$("#PageIndex").val(parseInt($("#PageIndex").val())+1),requestData()}},"#btn-load"),$(document).on({click:function(){var t=$(this).attr("page"),e=$("#page"+t);$("html,body").animate({scrollTop:$(e).offset().top-90},1e3)}},"#page-nav a"),$(document).on({click:function(){var a=$(this);$(".bd_weixin_popup").hide(),$(".bd_weixin_popup_bg").hide(),$(".post-cover").fadeIn(),$("body").addClass("modal-open"),$(".post-modal").css("right",0);var t=$(this).parent().attr("uid");if($("body").data("preview")!==t){resetModal();var e=$(this).siblings("h4").children("a").html();$(".post-modal .modal-header h4").html(e),$("#btnFullMode").attr("href",$(this).next("h4").children("a").attr("href")),$(".post-content div").hide();var o=a.data("preview-data");o?appendContent(o):($(".sk-cube-grid").show(),contentBegin=new Date,$.ajax({url:"/blog/getPreviewContent",type:"Post",data:{alias:t},success:function(t){var e=new Date;(a.data("preview-data",t),contentTimeout<e-contentBegin)?appendContent(t):setTimeout(function(){appendContent(t)},contentTimeout-(e-contentBegin))}}))}}},".preview-link"),$(".post-modal .modal-body").mCustomScrollbar({theme:"dark-3",scrollButtons:{enable:!0}}),$(".post-cover").on("click",function(){closeModal()}),$("#btnCloseModal").on("click",function(){closeModal()}),$("#btnFullMode").on("click",function(){setTimeout(closeModal,800)}),$(".list-top-left a").on("click",function(){$(this).hasClass("current")||($(this).addClass("current").siblings().removeClass("current"),$(".list-wrap ol").html(""),$("[data-toggle='tooltip']").tooltip("hide"),$("#page-nav").html(""),$("#btn-load").remove(),$("#no-more").remove(),begin=new Date,$("#load-list").show(),$("#SortBy").val($(this).attr("sort")),$("#PageIndex").val(1),requestData())}),$("#Keyword").on("keypress",function(t){13!=t.which&&10!=t.which||searchPost()}),$("#btnFilter").on("click",function(){searchPost()}),$(".selectlist").on("changed.fu.selectlist",function(t,e){$(this).find("li").removeClass("active"),$(this).find("li[data-value="+e.value+"]").addClass("active")})}); |