var GLOBAL = { isOpenSearch: false, timelineList: [], timelineIndex: 0, newTimelineList: {}, } var jQuery_1_12_4 = $.noConflict() jQuery_1_12_4(function () { jQuery_1_12_4(".js-index-news-list").mouseenter(function () { jQuery_1_12_4(".js-index-news-list").removeClass("active") var elem = jQuery_1_12_4(this)[0] var index = jQuery_1_12_4(elem).attr("data-index") console.log(index) var img = jQuery_1_12_4(elem).find("img:first") jQuery_1_12_4(elem).addClass("active") var content = jQuery_1_12_4(elem).find(".article-content:first") if (index == 1) { jQuery_1_12_4("#jsIndexNewShow").find("img").eq(0).show() jQuery_1_12_4("#jsIndexNewShow").find("img").eq(1).hide() } else { jQuery_1_12_4("#jsIndexNewShow").find("img").eq(0).hide() jQuery_1_12_4("#jsIndexNewShow").find("img").eq(1).attr("src", img.attr("src")).show() } jQuery_1_12_4("#jsIndexNewShow").find(".article-content:first").html(content.html()) jQuery_1_12_4("#jsIndexNewShow").attr("href", jQuery_1_12_4(elem).attr("href")) }) jQuery_1_12_4('[data-toggle="tooltip"]').tooltip() //搜索 jQuery_1_12_4("#jsSearchIcon").click(function () { GLOBAL.isOpenSearch = true changeSearchShow() }) jQuery_1_12_4("#jsSearchClose").click(function () { GLOBAL.isOpenSearch = false changeSearchShow() }) /* jQuery_1_12_4(".jsHeaderSearch") .focus(function () { jQuery_1_12_4(this).parent(".input-group").stop().animate({ width: "530px" }) }) .blur(function () { jQuery_1_12_4(this).parent(".input-group").stop().animate({ width: "120px" }) }) */ jQuery_1_12_4(".timeline-list .timeline-text").click(function (e) { e.preventDefault() jQuery_1_12_4(this).siblings(".timeline-text").removeClass("active") jQuery_1_12_4(this).addClass("active") createNewTimeline(jQuery_1_12_4(this).data("index")) }) createNewTimeline(jQuery_1_12_4(".timeline-list .timeline-text").eq(0).data("index")) //切换时间轴面板 jQuery_1_12_4("#jsTimelineToggle").click(function (e) { e.preventDefault() if (jQuery_1_12_4(this).data("type") == "close") { jQuery_1_12_4(this).data("type", "open").html("关闭时间轴") jQuery_1_12_4("#jsTimelineContent").stop().slideDown(80) } else { jQuery_1_12_4(this).data("type", "close").html("打开时间轴") jQuery_1_12_4("#jsTimelineContent").stop().slideUp(80) } }) initTimeline() }) function changeSearchShow() { if (GLOBAL.isOpenSearch) { jQuery_1_12_4("#jsSearchBox").addClass("active") jQuery_1_12_4(".header-nav").hide() jQuery_1_12_4(".header-right").css({ width: "65%" }) } else { jQuery_1_12_4("#jsSearchBox").removeClass("active") jQuery_1_12_4(".header-nav").show() jQuery_1_12_4(".header-right").css({ width: "360px" }) } } function initTimeline() { var list = GLOBAL.timelineList var chooseIndex = 0, distance = 0, today = new Date().getTime(), d if (list) { list.sort(function (a, b) { return new Date(a.time) - new Date(b.time) }).map(function (item, index) { var time = new Date(item.time) item.year = time.getFullYear() item.slug = time.getFullYear() + "-" + time.getMonth() d = today - time.getTime() if (distance == 0 && chooseIndex == 0) { distance = d } else if (distance > d) { distance = d chooseIndex = index } return item }) if (chooseIndex + 13 > GLOBAL.timelineList.length) { if (GLOBAL.timelineList.length - 12 <= 0) { chooseIndex = 0 } else { chooseIndex = GLOBAL.timelineList.length - 13 } } GLOBAL.timelineIndex = chooseIndex createTimeline(chooseIndex) } } function timelinePrev() { if (GLOBAL.timelineIndex > 0) { if (GLOBAL.timelineIndex > 12) { GLOBAL.timelineIndex = GLOBAL.timelineIndex - 12 } else { GLOBAL.timelineIndex = 0 } createTimeline(GLOBAL.timelineIndex) } } function timelineNext() { if (GLOBAL.timelineIndex + 13 < GLOBAL.timelineList.length) { GLOBAL.timelineIndex = GLOBAL.timelineIndex + 12 createTimeline(GLOBAL.timelineIndex) } } function createTimeline(index) { var html = "", max = index + 12, item = "", showMonth = {} if (index == 0) { jQuery_1_12_4("#jsTimelineContent .timeline-prev").addClass("disabled") } else { jQuery_1_12_4("#jsTimelineContent .timeline-prev").removeClass("disabled") } if (max >= GLOBAL.timelineList.length - 1) { max = GLOBAL.timelineList.length jQuery_1_12_4("#jsTimelineContent .timeline-next").addClass("disabled") } else { jQuery_1_12_4("#jsTimelineContent .timeline-next").removeClass("disabled") } for (var i = index; i < max; i++) { item = GLOBAL.timelineList[i] if (item) { html += '
' html += '
' if (!showMonth[item.slug]) { html += '' + item.month + '/ ' + item.year + "" showMonth[item.slug] = true } html += '' + item.date + "" html += '' + item.tag + "" html += '' + item.title + "" html += "
" html += "
" } } jQuery_1_12_4("#jsTimelineItems").html(html) } function createNewTimeline(index) { var html = "", item = "", items = GLOBAL.newTimelineList[index] if (!items) { return false } for (var i = 0; i < items.length; i++) { item = items[i] if (item) { html += '
' html += '
' html += '
' + item.date + "
" html += '
' html += '
' + item.title + "
" html += "
" html += "
" } } if (!html) { html = '
暂无内容
' } jQuery_1_12_4("#jsNewTimelineItems").html(html) }