/*! #foot:js */ $(function () { var Ani = (function () { function Ani(opt) { this.$win = $(window); this.attr = "data-anim"; this.anis = []; this.opt = $.extend( { delay: 80, maxDelay: 800, once: false, inView: 0.1, outView: 100, }, opt, ); this.on = { init: function () { var that = this; that.anis.forEach(function (e, i) { var opt = e.opt || {}; if (opt.animDuration) { e.el.css("animation-duration", opt.animDuration + "s"); } }); }, }; } Ani.prototype = { init: function () { var that = this; that.anis = $("[" + that.attr + "]") .get() .map(function (e, i) { var $el = $(e); $el.addClass("ani-ready"); var dataAttrs = $el.data(); for (var key in dataAttrs) { if (!/^anim/.test(key)) { delete dataAttrs[key]; } } return { el: $el, ani: $el.attr(that.attr), opt: dataAttrs, }; }); that.on.init.call(that); that.handleScroll(); that.$win.off("scroll.ani").on("scroll.ani", that.handleScroll.bind(that)); }, handleScroll: function () { var that = this; var delayIndex = 0; for (var i = 0; i < that.anis.length; i++) { var aniEl = that.anis[i]; if (that.inView(aniEl.el, that.opt.inView)) { (function (aniEl, _i) { if (aniEl.playing || aniEl.el.hasClass("ani-played")) return; aniEl.playing = true; var delay = (that.opt.delay * delayIndex) % that.opt.maxDelay; delayIndex++; setTimeout(function () { aniEl.el.addClass("ani-played"); aniEl.playing = false; }, delay); if (that.opt.once) { aniEl.el.on("animationend.ani", function () { aniEl.el.removeAttr(that.attr).removeClass("ani-played ani-ready").off("animationend.ani"); }); that.anis.splice(_i, 1); i--; if (that.anis.length === 0) that.$win.off("scroll.ani"); } })(aniEl, i); } else if (that.outView(aniEl.el, that.opt.outView)) { aniEl.el.removeClass("ani-played"); } } }, inView: function (element, ratio) { ratio = typeof ratio === "number" ? ratio : 0; var $el = $(element); if (!$el.length) return false; var rect = $el[0].getBoundingClientRect(); var winH = window.innerHeight; var elH = rect.height || $el[0].offsetHeight; if (elH <= 0) return false; if (ratio >= 0) { var visibleTop = Math.max(rect.top, 0); var visibleBottom = Math.min(rect.bottom, winH); var visibleH = Math.max(0, visibleBottom - visibleTop); return visibleH / elH >= ratio; } else { var margin = -ratio * elH; return rect.top < winH + margin && rect.bottom > -margin; } }, outView: function (el, offset) { if (!offset) offset = 0; var rect = el[0].getBoundingClientRect(); return rect.bottom <= 0 - offset || rect.top >= window.innerHeight + offset; }, }; var ani = new Ani(); return Ani; })(); new Ani({ once: true, }).init(); }); ; function formSave(e) { hnSubmit(e, function (res) { if (res) { location.reload() } }) }; /** * 生成验证码 */ function changCaptcha(e) { $(e.target).attr('src', "/common/captcha/index?id=" + Date.parse(new Date()) / 1000 + (Math.floor(Math.random() * 100000 + 100))); } $(document).ready(function () { // 尾部 $(".md33838 .share_one").each(function () { if (!$(this).find('.share_sub').length) { $(this).addClass('no-sub') } }) $(".md33838 .share_one").mouseenter(function (e) { if ($(window).width() > 1200) { $(this).addClass("show") } }) $(".md33838 .share_one").mouseleave(function () { if ($(window).width() > 1200) { $(this).removeClass("show") } }) $(".md33838 .share_one").click(function (e) { if ($(window).width() <= 1200) { e.preventDefault(); if ($(this).hasClass("show")) { $(this).removeClass("show") } else { $(this).addClass("show").siblings().removeClass('show') } } }) $(".md33838 .share_sub, .md33838 .no-sub .share_link,.md33838 .share_one").click(function (e) { e.stopPropagation() }) $("body").click(function (e) { $(".md33838 .share_one").removeClass("show") }) }) $(function () { // 泛用弹框构造函数 var Dialog = (function createDialogConstructor() { var dialogSet = []; function Dialog(selector, options) { var self = this; // 默认配置 var defaults = { init: function () { }, openBtn: null, closeBtn: null, only: true, esc: true, focused: true, onOpenClick: function (event) { return true; }, onCloseClick: function (event) { return true; }, beforeOpen: function () { return true; }, afterOpen: function () { return true; }, beforeClose: function () { return true; }, afterClose: function () { return true; }, }; self.options = $.extend({}, defaults, options); self.$dialog = $(selector); // 验证元素存在且有 .dialog 类 if (!self.$dialog || !self.$dialog.length) { return console.warn("Dialog: 找不到元素:", selector); } if (!self.$dialog.hasClass("dialog")) { return console.warn('Dialog: 元素必须包含 "dialog" 类名'); } // 防止重复初始化 var existingInstance = self.$dialog.data("dialog-instance"); if (existingInstance) { console.warn("Dialog: 已跳过重复初始化,返回已有实例"); return existingInstance; } // 标记当前实例 self.$dialog.data("dialog-instance", self); // esc事件命名空间 self.escNamespace = "keydown.dialog-" + Math.random().toString(36).slice(2, 11); // 获取焦点元素 self.$focusEl = self.$dialog.find('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'); // 绑定打开按钮 if (self.options.openBtn) { self.$openBtn = $(self.options.openBtn); self.$openBtn.on("click", function (e) { e.preventDefault(); if (self.options.onOpenClick.call(self, e) === false) return; self.open(); }); } // 绑定关闭按钮 if (self.options.closeBtn) { self.$closeBtn = $(self.options.closeBtn); self.$closeBtn.on("click", function (e) { e.preventDefault(); if (self.options.onCloseClick.call(self, e) === false) return; self.close(); }); } // 点击背景关闭 self.$dialog.on("mousedown", function (e) { self._preClickEl = e.target === e.currentTarget ? e.target : null; }); self.$dialog.on("mouseup", function (e) { if (self._preClickEl === e.target) self.close(); self._preClickEl = null; }); // 加入dialogSet dialogSet.push(self); self.options.init.call(self); // 阻止tab键聚焦表单外的元素 if (self.options.focused) { self.firstFocusEl = self.$focusEl[0]; self.lastFocusEl = self.$focusEl[self.$focusEl.length - 1]; self.$dialog.on("keydown", (e) => { if (e.key !== "Tab") return; if (e.shiftKey) { if (document.activeElement === self.firstFocusEl) { e.preventDefault(); self.lastFocusEl.focus(); } } else { if (document.activeElement === self.lastFocusEl) { e.preventDefault(); self.firstFocusEl.focus(); } } }); } } // 打开Dialog Dialog.prototype.open = function () { var self = this; if (self.options.beforeOpen.call(self) === false) return self; // 只打开一个对话框 if (self.options.only) { $.each(dialogSet, function (i, dialog) { if (dialog !== self && dialog.$dialog.hasClass("dialog-show")) { dialog.close(); } }); } if (self.options.esc) { $(document).off(self.escNamespace); $(document).on(self.escNamespace, function (e) { if (e.key === "Escape" && self.$dialog.hasClass("dialog-show")) { self.close(); } }); } self.$dialog.addClass("dialog-show"); self.options.afterOpen.call(self); $("html,body").css("overflow", "hidden"); return self; }; // 关闭Dialog Dialog.prototype.close = function () { var self = this; if (self.options.beforeClose.call(self) === false) return self; // 暂停媒体 self.$dialog.find("video, audio").each(function () { this.pause(); }); self.$dialog.removeClass("dialog-show"); self.options.afterClose.call(self); // 解绑esc事件 $(document).off(self.escNamespace); $("html,body").css("overflow", ""); return self; }; // 销毁Dialog Dialog.prototype.destroy = function () { var self = this; if (self.$openBtn) self.$openBtn.off("click"); if (self.$closeBtn) self.$closeBtn.off("click"); self.$dialog.off("click"); // 解绑esc事件 $(document).off(self.escNamespace); var index = dialogSet.indexOf(self); if (index > -1) dialogSet.splice(index, 1); self.$dialog.removeData("dialog-instance"); return self; }; // 获取所有已创建的对话框实例 Dialog.dialogs = function () { return dialogSet; }; return Dialog; })(); // 泛用侧栏构造函数 var Expand = (function createExpandConstructor() { var expandSet = []; function Expand(selector, options) { var self = this; // 默认配置 var defaults = { openBtn: null, // 打开按钮 closeBtn: null, // 关闭按钮 only: false, // 是否只允许一个展开项打开 init: function () { }, beforeOpen: function () { return true; }, // 打开前回调 afterOpen: function () { return true; }, // 打开后回调 beforeClose: function () { return true; }, // 关闭前回调 afterClose: function () { return true; }, // 关闭后回调 }; // 合并配置 self.options = $.extend({}, defaults, options); // 查找展开元素 self.$expand = $(selector); // 验证元素 if (!self.$expand || !self.$expand.length) return console.warn("Expand: 找不到元素:" + selector); if (!self.$expand.hasClass("expand")) return console.warn("Expand: 必须包含expand类名"); // 处理打开按钮 if (self.options.openBtn) { self.$openBtn = $(self.options.openBtn); self.$openBtn.on("click", function (e) { e.preventDefault(); self.open(); }); } // 添加到展开项集合 expandSet.push(self); // 绑定关闭按钮事件 if (self.options.closeBtn) { self.$closeBtn = $(self.options.closeBtn); self.$closeBtn.on("click", function (e) { e.preventDefault(); self.close(); }); } // 点击背景关闭 self.$expand.on("click", function (e) { if ($(e.target).hasClass("expand")) self.close(); }); // 初始化项目 self.items = []; self.options.init.call(self); return self; } Expand.prototype.close = function () { if (this.options.beforeClose.call(this) === false) return; this.$expand.removeClass("expand-show"); // 关闭时移除所有项目的active状态 this.items.forEach(function ($itemGroup) { $itemGroup.removeClass("active"); $itemGroup.find(".active").removeClass("active"); }); this.options.afterClose.call(this); return this; }; Expand.prototype.open = function () { if (this.options.beforeOpen.call(this) === false) return; if (this.options.only) { $.each( expandSet, function (index, expand) { if (expand !== this && expand.$expand.hasClass("expand-show")) { expand.close(); } }.bind(this), ); } this.$expand.addClass("expand-show"); this.options.afterOpen.call(this); return this; }; Expand.prototype.destroy = function () { if (this.$openBtn) this.$openBtn.off("click"); if (this.$closeBtn) this.$closeBtn.off("click"); this.items.forEach(function ($itemGroup) { $itemGroup.off("click"); }); var index = expandSet.indexOf(this); if (index > -1) expandSet.splice(index, 1); }; Expand.expands = function () { return expandSet; }; return Expand; })(); $(".md33839.head").each(function () { var $md = $(this); if ($md.hasClass("initialized")) return; else $md.addClass("initialized"); $md.find(".lang-opt .lang-item").each(function (i) { $(this).css("transform", "translateY(-" + 100 * (i + 1) + "%)"); }); new Dialog($md.find(".search-dialog"), { openBtn: ".open-search", afterOpen: function () { this.$focusEl[0].focus(); }, }); new Expand(".menu-expand", { openBtn: ".open-menu", closeBtn: ".close-menu", init: function () { this.$expand.find(".exp-entry").each(function () { var $expEntry = $(this); var $item = $expEntry.parent(".exp-item"); var $orderItem = $item.siblings(".exp-item"); var $list = $expEntry.siblings(".exp-list"); $expEntry.on("click", function () { var isActive = $item.hasClass("active"); $item[isActive ? "removeClass" : "addClass"]("active"); $list[isActive ? "slideUp" : "slideDown"](); $orderItem.find(".exp-item")[isActive ? "addClass" : "removeClass"]("active"); $orderItem.find(".exp-list")[isActive ? "slideDown" : "slideUp"](); }); }); }, }); // quote弹框 new Dialog($md.find(".quote-dialog"), { openBtn: ".open-quote-dialog", closeBtn: ".dialog-close", init: function () { var $dl = this.$dialog; $dl.find(".ipt-item,.area-item").each(function () { handleInput.call(this); $(this).on("input", handleInput); }); $dl.find(".drop-entry").on("click", function () { var $ipt = $(this).closest(".form-item").find("input"); $ipt.val($(this).text()); handleInput.call($ipt); }); function handleInput() { var $ipt = $(this); if ($ipt.val()) $ipt.next(".form-cover").addClass("hide"); else $ipt.next(".form-cover").removeClass("hide"); } }, afterOpen: function () { this.$dialog.find("input")[0].focus(); // 每次打开弹框时,滚动条置顶 try { this.$dialog.find(".dialog-main")[0].scrollTop = 0; } catch (err) { console.warn(err); } }, }); var $win = $(window); $win.on("scroll", handleScroll); handleScroll(); function handleScroll() { var scrollTop = $win.scrollTop(); if (scrollTop > 100) { $md.addClass("is-flow"); } else { $md.removeClass("is-flow"); } } }); }); ; function formSave2(e) { hnSubmit(e, function (res) { if (res) { location.reload() } }) }; ;$(function() { $(".md33843.md-com-bread").each(function(i, e) { if ($(e).find('.swiper-container').length > 0) { var bn_swiper = {}; bn_swiper = new Swiper('.bn-swiper .swiper-container', { observer: true, observeParents: true, autoplay: false, freeMode: true, slidesPerView: 'auto', }); var ii = $('.md33843.md-com-bread .bn-swiper .bsa').index($('.md33843.md-com-bread .bn-swiper .bsa.on')) ? $('.md33843.md-com-bread .bn-swiper .bsa').index($('.md33843.md-com-bread .bn-swiper .bsa.on')) : 0; bn_swiper.slideTo(ii); } }) }); ;$(function() { $(".md33844.md-com-bread").each(function(i, e) { if ($(e).find('.swiper-container').length > 0) { var bn_swiper = {}; bn_swiper = new Swiper('.bn-swiper .swiper-container', { observer: true, observeParents: true, autoplay: false, freeMode: true, slidesPerView: 'auto', }); var ii = $('.md33844.md-com-bread .bn-swiper .bsa').index($('.md33844.md-com-bread .bn-swiper .bsa.on')) ? $('.md33844.md-com-bread .bn-swiper .bsa').index($('.md33844.md-com-bread .bn-swiper .bsa.on')) : 0; bn_swiper.slideTo(ii); } }) });