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 () { $(".bd_weixin_popup").hide(); $(".bd_weixin_popup_bg").hide(); $(".post-cover").fadeIn(); $("body").addClass("modal-open"); var title = $(this).siblings("h4").children("a").html(); var uid = $(this).parent().attr("uid"); $(".post-modal .modal-header h4").html(title); $("#btnFullMode").attr("href", "/" + uid); $(".sk-cube-grid").show(); $(".post-content div").hide(); var comments = $(this).parent().find(".cy_cmt_count").text(); $("#modal-comments").text(comments); $(".post-modal").css("right", 0); contentBegin = new Date(); $.ajax({ url: "/blog/getPreviewContent", type: "Post", data: {alias: uid}, success: function (data) { var end = new Date(); 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").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(); } function closeModal() { $(".post-modal").css("right", "-1200px"); $(".post-cover").fadeOut(); $("body").removeClass("modal-open"); resetModal(); } function resetModal() { $(".post-modal .modal-header h4").empty(); $(".post-content div").empty(); $("#label-foot").empty(); } function searchPost() { $(".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 = "" + " " + encodeHtml(value.Summary) + " <\/p>" + "<\/div>" + "
"; } else { itemHtml = "" + encodeHtml(value.Summary) + "