$(function () { window.isMobile = !!("ontouchstart" in window); function AddFavorite(sURL, sTitle) { if (/firefox/i.test(navigator.userAgent)) { return false; } else if (window.external && window.external.addFavorite) { window.external.addFavorite(sURL, sTitle); return true; } else if (window.sidebar && window.sidebar.addPanel) { window.sidebar.addPanel(sTitle, sURL, ""); return true; } else { var touch = (navigator.userAgent.toLowerCase().indexOf('mac') != -1 ? 'Command' : 'CTRL'); layer.msg('璇蜂娇鐢 ' + touch + ' + D 娣诲姞鍒版敹钘忓す.'); return false; } } var len = function (str) { if (!str) return 0; var length = 0; for (var i = 0; i < str.length; i++) { if (str.charCodeAt(i) >= 0x4e00 && str.charCodeAt(i) <= 0x9fa5) { length += 2; } else { length++; } } return length; }; //new LazyLoad({elements_selector: ".lazy"}); //鏍忕洰楂樹寒 var nav = $("header.header .navbar-nav"); if ($("li.active", nav).size() === 0) { var current = nav.data("current"); var currentNav = $("a[href='" + location.href + "']", nav)[0] || $("a[href='" + location.pathname + "']", nav)[0] || $("li[value='" + current + "'] > a", nav)[0]; currentNav && $(currentNav, nav).parents("li").addClass("active"); } //绉诲姩绔彍鍗曠偣鍑 $(document).on("click", ".navbar-collapse.collapse.in .navbar-nav .dropdown-submenu > a", function () { $(this).parents("li.dropdown").addClass("open"); return false; }); // 鐐瑰嚮鏀惰棌 $(".addbookbark").attr("rel", "sidebar").click(function () { return !AddFavorite(window.location.href, $(this).attr("title")); }); // 鐐硅禐 $(document).on("click", ".btn-like", function () { var that = this; var id = $(this).data("id"); var type = $(this).data("type"); if (CMS.api.storage(type + "vote." + id)) { layer.msg("浣犲凡缁忕偣杩囪禐浜?); return false; } CMS.api.ajax({ data: $(this).data() }, function (data, ret) { $("span", that).text(type === 'like' ? ret.data.likes : ret.data.dislikes); CMS.api.storage(type + "vote." + id, true); return false; }, function () { return false; }); }); // 鍔犺浇鏇村 $(document).on("click", ".btn-loadmore", function () { var that = this; var page = parseInt($(this).data("page")); page++; $(that).prop("disabled", true); CMS.api.ajax({ url: $(that).attr("href"), }, function (data, ret) { $(data).insertBefore($(that).parent()); $(that).remove(); return false; }, function (data) { }); return false; }); //婊氬姩鍔犺浇鏇村 $(window).scroll(function () { var loadmore = $(".btn-loadmore"); if (loadmore.size() > 0 && !loadmore.prop("disabled") && (loadmore.data("autoload") === undefined || loadmore.data("autoload"))) { if ($(window).scrollTop() - loadmore.height() > loadmore.offset().top - $(window).height()) { loadmore.trigger("click"); } } }); setTimeout(function () { if ($(window).scrollTop() > 0) { $(window).trigger("scroll"); } }, 500); //璇勮鍒楄〃 if ($("#comment-container").size() > 0) { var ci, si; $("#commentlist dl dd div,#commentlist dl dd dl dd").on({ mouseenter: function () { clearTimeout(ci); var _this = this; ci = setTimeout(function () { $(_this).find("small:first").find("a").stop(true, true).fadeIn(); }, 100); }, mouseleave: function () { clearTimeout(ci); $(this).find("small:first").find("a").stop(true, true).fadeOut(); } }); $(".reply").on("click", function () { $("#pid").val($(this).data("id")); $(this).parent().parent().append($("div#postcomment").detach()); $("#postcomment h3 a").show(); $("#commentcontent").focus().val($(this).attr("title")); }); $("#postcomment h3 a").bind("click", function () { $("#comment-container").append($("div#postcomment").detach()); $(this).hide(); }); $(".expandall a").on("click", function () { $(this).parent().parent().find("dl.hide").fadeIn(); $(this).fadeOut(); }); $(document).on("click", "#submit", function () { var btn = $(this); var tips = $("#actiontips"); tips.removeClass(); var content = $("#commentcontent").val(); if (len(content) < 3) { tips.addClass("text-danger").html("璇勮鍐呭闀垮害涓嶆纭紒鏈€灏?涓瓧绗?).fadeIn().change(); return false; } var form = $("#postform"); btn.attr("disabled", "disabled"); tips.html('姝e湪鎻愪氦...'); $.ajax({ url: form.prop("action"), type: 'POST', data: form.serialize(), dataType: 'json', success: function (json) { btn.removeAttr("disabled"); if (json.code == 1) { $("#pid").val(0); tips.addClass("text-success").html(json.msg || "璇勮鎴愬姛锛?).fadeIn(300).change(); $("#commentcontent").val(''); $("#commentcount").text(parseInt($("#commentcount").text()) + 1); setTimeout(function () { location.reload(); }, 1000); } else { tips.addClass("text-danger").html(json.msg).fadeIn().change(); } if (json.data && json.data.token) { $("#postform input[name='__token__']").val(json.data.token); } }, error: function () { btn.removeAttr("disabled"); tips.addClass("text-danger").html("璇勮澶辫触锛佽鍒锋柊椤甸潰閲嶈瘯锛?).fadeIn(); } }); return false; }); $("#commentcontent").on("keydown", function (e) { if ((e.metaKey || e.ctrlKey) && (e.keyCode == 13 || e.keyCode == 10)) { $("#submit").trigger('click'); } }); $("#actiontips").on("change", function () { clearTimeout(si); si = setTimeout(function () { $("#actiontips").fadeOut(); }, 8000); }); $(document).on("keyup change", "#commentcontent", function () { var max = 1000; var c = $(this).val(); var length = len(c); var t = $("#actiontips"); if (max >= length) { t.removeClass().show().addClass("loading").html("浣犺繕鍙互杈撳叆 " + (Math.floor((max - length) / 2)) + " 瀛?); $("#submit").removeAttr("disabled"); } else { t.removeClass().show().addClass("loading").html("浣犲凡缁忚秴鍑 " + (Math.ceil((length - max) / 2)) + " 瀛?); $("#submit").attr("disabled", "disabled"); } }); } // 浣欓鏀粯鎻愮ず $(document).on('click', '.btn-balance', function (e) { var that = this; layer.confirm("纭鏀粯锟? + $(this).data("price") + "鍏冪敤浜庤喘涔帮紵", function () { CMS.api.ajax({ url: $(that).attr("href") }, function (data, ret) { CMS.api.msg(ret.msg, ret.url); }); }); return false; }); // 鍥炲埌椤堕儴 $('#back-to-top').on('click', function (e) { e.preventDefault(); $('html,body').animate({ scrollTop: 0 }, 700); }); //濡傛灉鏄疨C鍒欑Щ闄avbar鐨刣ropdown鐐瑰嚮浜嬩欢 if (!/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini|Mobi/i.test(navigator.userAgent)) { $("#navbar-collapse [data-toggle='dropdown']").removeAttr("data-toggle"); } else { $(".navbar-nav ul li:not(.dropdown-submenu):not(.dropdown) a").removeAttr("data-toggle"); } if (!isMobile) { var search = $("#searchinput"); var form = search.closest("form"); search.autoComplete({ minChars: 1, cache: false, menuClass: 'autocomplete-searchmenu', header: '', footer: '', source: function (term, response) { try { xhr.abort(); } catch (e) { } xhr = $.getJSON(search.data("suggestion-url"), {q: term}, function (data) { response(data); }); }, onSelect: function (e, term, item) { if (typeof callback === 'function') { callback.call(elem, term, item); } else { form.trigger("submit"); } } }); } // 鎵撹祻 $(".btn-donate").popover({ trigger: 'hover', placement: 'top', html: true, content: function () { return ""; } }); $(document).on("click", ".btn-paynow", function () { var paytype = $(this).data("paytype"); var price = $(this).data("price"); var nameArr = {wechat: "寰俊", alipay: "鏀粯瀹?, balance: "浣欓"}; var that = this; var tips = function () { layer.confirm("璇锋牴鎹敮浠樼姸鎬侀€夋嫨涓嬮潰鐨勬搷浣滄寜閽?, {title: "娓╅Θ鎻愮ず", icon: 0, btn: ["鏀粯鎴愬姛", "鏀粯澶辫触"]}, function () { location.reload(); }); }; if (paytype) { layer.confirm("纭浣跨敤" + (typeof nameArr[paytype] !== 'undefined' ? nameArr[paytype] : "鏈煡") + "杩涜鏀粯?
鏀粯閲戦锛氾骏" + price + "鍏?, {title: "娓╅Θ鎻愮ず", icon: 3, focusBtn: false, btn: ["绔嬪嵆鏀粯", "鍙栨秷鏀粯"]}, function (index, layero) { $(".layui-layer-btn0", layero).attr("href", $(that).attr("href")).attr("target", "_blank"); tips(); }); return false; } else { tips(); } }); // 瀵艰埅涓嬫媺椤垫偓娴晥鏋 $("ul.navbar-nav > li.dropdown").hover(function(e){ $(this).find('a.nav-dropdown > i.fa').removeClass('fa-angle-up').addClass('fa-angle-down'); }, function(e){ $(this).find('a.nav-dropdown > i.fa').removeClass('fa-angle-down').addClass('fa-angle-up'); }); // 瀵艰埅鑿滃崟鎮诞鏁堟灉 $(".dropdown .dropdown-menu li").hover(function(e){ let img = $(this).find('span img'); img.attr('src', img.data('srcactive')); $(this).find('> a').css('color', '#000'); $(this).find('> a i.fa').removeClass('fa-angle-right').addClass('fa-caret-right'); }, function(e){ let img = $(this).find('span img'); img.attr('src', img.data('src')); $(this).find('> a').css('color', '#004FE8'); $(this).find('> a i.fa').removeClass('fa-caret-right').addClass('fa-angle-right'); }); function addScrollClass(nav){ let logo = nav.find('.navbar-brand img'); logo.attr('src', logo.data('src')) let headerphone = nav.find('.contactus img'); headerphone.attr('src', headerphone.data('srcw')); } function rmScrollClass(nav){ let logo = nav.find('.navbar-brand img'); logo.attr('src', logo.data('srcw')) let headerphone = nav.find('.contactus img'); headerphone.attr('src', headerphone.data('srcb')); } // 瀵艰埅鎮诞鏁堟灉 $("nav.navbar-inverse").hover(function(e){ if ($(window).scrollTop() > 0) {return false;} addScrollClass($(this)); $(this).removeClass('navbar-scroll') .addClass('navbar-scroll animate__animated animate__fadeIn'); }, function(e){ if ($(window).scrollTop() > 0) {return false;} rmScrollClass($(this)); $(this).removeClass('navbar-scroll animate__fadeIn'); }); // 椤甸潰婊氬姩锛屽鑸彉鑹 $(window).scroll(function () { let scrollTop = $(window).scrollTop(); let height = $(window).height(); let nav = $("nav.navbar-inverse"); let scrollHeight = height*0.2; if (scrollTop < scrollHeight) { rmScrollClass(nav); nav.removeClass('navbar-scroll animate__fadeIn'); } else if(!nav.hasClass('navbar-scroll')){ addScrollClass(nav); nav.addClass('navbar-scroll animate__animated animate__fadeIn'); } if (scrollTop > scrollHeight) { $("#floatbtn").show(); } else { $("#floatbtn").hide(); } }); });