var home_loading_timeout = 2000; var isLoading = false; var timeout = 1000; var contentTimeout = 1500; var begin = new Date(); var contentBegin = new Date(); var pageCount; var tooltip_timeout = 1500; $(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 = true; $("#PageIndex").val(parseInt($("#PageIndex").val()) + 1); requestData(); } }, "#btn-load"); $(document).on({ click: function () { var index = $(this).attr("page"); var pageItem = $("#page" + index); $("html,body").animate({ scrollTop: $(pageItem).offset().top - 90 }, 1000); } }, "#page-nav a"); $(document).on({ click: function () { var $this = $(this); $(".bd_weixin_popup").hide(); $(".bd_weixin_popup_bg").hide(); $(".post-cover").fadeIn(); $("body").addClass("modal-open"); $(".post-modal").css("right", 0); var alias = $(this).parent().attr("uid"); if ($('body').data('preview') === alias) { return; } resetModal(); var title = $(this).siblings("h4").children("a").html(); $(".post-modal .modal-header h4").html(title); $("#btnFullMode").attr("href", $(this).next('h4').children('a').attr('href')); $(".post-content div").hide(); var previewData = $this.data('preview-data'); if (previewData) { appendContent(previewData); return; } $(".sk-cube-grid").show(); contentBegin = new Date(); $.ajax({ url: "/blog/getPreviewContent", type: "Post", data: { alias: alias }, success: function (data) { var end = new Date(); $this.data('preview-data', data); if (end - contentBegin > contentTimeout) { appendContent(data); } else { var timespan = contentTimeout - (end - contentBegin); setTimeout(function () { appendContent(data); }, timespan); } } }); } }, ".preview-link"); $(".post-modal .modal-body").mCustomScrollbar({ theme: "dark-3", scrollButtons: { enable: true } }); $(".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 () { if (!$(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 (e) { if (e.which == 13 || e.which == 10) { searchPost(); } }); $("#btnFilter").on("click", function () { searchPost(); }); $(".selectlist").on("changed.fu.selectlist", function (e, data) { $(this).find("li").removeClass("active"); $(this).find("li[data-value=" + data.value + "]").addClass("active"); }); }); function requestData() { $.ajax({ url: $('#filterForm')[0].action, type: $('#filterForm')[0].method, data: $('#filterForm').serialize(), success: function (result) { var end = new Date(); var data = result.posts; pageCount = result.pageCount; if (end - begin > timeout) { addPage($("#PageIndex").val(), data); } else { var timespan = timeout - (end - begin); setTimeout(function () { addPage($("#PageIndex").val(), data); }, timespan); } } }); } function appendContent(data) { $(".sk-cube-grid").hide(); $(".post-content div").removeClass('markdown-body normal-body').addClass(data.ContentType === 'markdown' ? 'markdown-body' : 'normal-body'); $(".post-content div").html(data.Content); var labels = JSON.parse(data.Labels); $.each(labels, function (key, value) { $("#label-foot").append("" + value.text + ""); }); $(".post-modal .modal-body").mCustomScrollbar("scrollTo", "top", { scrollInertia: 0 }); $(".post-content div").fadeIn(); var pres = $('.post-content pre'); pres.each(function (i, pre) { if (!data.ContentType) { $(pre).html($('').html($(pre).html())); } hljs.highlightBlock($(pre).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 inputEl = $('#Keyword'); if (!inputEl.val()) { inputEl.focus(); return; } $(".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(); } function addPage(index, data) { $("#load-list").hide(); if (data.length > 0) { $(".list-wrap ol").append("
  • "); $.each(data, function (key, value) { var itemHtml; if (value.Source == "1") { itemHtml = "
    0 ? "" : "animated fadeIn") + "\">" + "

    " + " " + " " + value.Title + " <\/a>" + " <\/h4>" + " " + " " + " <\/i>" + " " + "" + value.CateName + "" + " <\/span>" + " " + " " + " <\/i>" + " " + value.PublishDate + " <\/span>" + " " + " " + " " + value.Host + " <\/a>" + "
    " + " <\/div>" + "

    " + " " + encodeHtml(value.Summary) + " <\/p>" + "<\/div>" + "

    "; } else { itemHtml = "
    0 ? "" : "animated fadeIn") + "\" uid=\"" + value.Alias + "\">

    " + value.Title + "

    " + "" + value.CateName + "" + " " + value.PublishDate + "

    " + encodeHtml(value.Summary) + "

    "; } $("#page" + index).append(itemHtml); }); $("body").append("