/** * First we will load all of this project's JavaScript dependencies which * includes Vue and other libraries. It is a great starting point when * building robust, powerful web applications using Vue and Laravel. */ require('./bootstrap_learnku'); require('./vendor/search'); /** 返回对应位置 */ window.scrollToAnchor = function(id) { var e = $("*[id='" + id + "']"); $("html,body").animate({ scrollTop: e.offset().top }, "slow") }; // 七牛 images 镜像 window.assert_images = function (path) { return Config.routes.images_domain + path; }; // 全局公用函数 window.public = { axios_then: function (res) { Swal.fire({ type: 'success', title: res.msg, }); }, axios_catch: function(error) { let response = error.response, html = ''; if (response.data && response.data.errors) { for (let error in response.data.errors) { html += '
' + response.data.errors[error] + '
'; } Swal.fire({ type: 'error', html: html, showConfirmButton: false, showCancelButton: true }); } else if(response.data && response.data.message){ Swal.fire({ type: 'error', text: response.data.message, showConfirmButton: false, showCancelButton: true }); } }, }; class Learnku { init() { this.initFunc(); this.initSubmitBtn(); this.closeMessage(); this.initSematicUI(); this.initLazyload(); this.initDeleteForm(); this.initLightBox(); // this.axiosDeleteForm(); } initFunc() { // markdown 编辑的页面。非本站地址,以新窗口打开 $('.markdown-body').find('a').each(function () { let href = $(this).attr('href'); if (href.indexOf('learnku.net') === -1) { $(this).attr('target', '_black') } }); } /** 表单提交 */ initSubmitBtn(){ $('button.ui.button[type="submit"]:not(.no-loading)').click(function() { $(this).addClass("disabled"); if($(".clear-submit").length > 0) { var self = $(this); setTimeout(function() { self.after('清除加载状态') }, 3000) } }); $("body").on("click", "a.clear-submit", function() { $(this).siblings('button.ui.button[type="submit"]').removeClass("loading"), $(this).siblings('button.ui.button[type="submit"]').removeClass("disabled"), $(this).remove() }) } /** 关闭 message 提示消息 */ closeMessage() { $('.message .close').on('click', function () { $(this).closest('.message').transition('fade'); }); } /** SematicUI */ initSematicUI(){ $(".ui.dropdown").dropdown(); $(".ui.community-nav.dropdown").dropdown({ onChange: function(t, e, n) { window.location.href = n.attr("href") } }); $(".ui.checkbox").checkbox(); $(".ui.accordion").accordion(); $(".ui.popover").popup({ on: "hover", position: "top center" }); // 文章详情页 贴附效果 if ($('.js-computed-height-right ').outerHeight(true) >= $(".js-computed-height-left").outerHeight(true)) { $(".ui.toc.sticky").sticky({ silent: true, debug: false, context: ".article-content" }); } // 文章详情页 右边栏 贴附效果 $(".ui.topic-operation.sticky").sticky({ silent: true, context: ".main-column" }); $(".ui.translate-box.sticky").sticky({ silent: !0 }); $(".message .close").on("click", function() { $(".message-container").transition("fade") }); $(".ui.left.sidebar").sidebar({ transition: "overlay", mobileTransition: "uncover", observeChanges: !0, closable: !1, dimPage: !1, onVisible: function() { var e = 200 / screen.width * 100 , n = 100 - e + "%"; $(".pusher").width(n), $(".pusher").animate({ marginLeft: e + "%" }, 400) }, onShow: function() { $(".fixed.launch.button").css("left", 200), $(".fixed.launch.button").css("padding", "10px 6px"), $(".ui.toc.sticky").sticky("refresh") }, onHide: function() { $(".pusher").width("100%"), $(".pusher").css("margin-left", "inherit"), $(".ui.toc.sticky").each(function() { $(this).data("moduleSticky").refresh() }), $(".fixed.launch.button").css("padding", "0.78571429em 1.5em 0.78571429em"), $(".fixed.launch.button").css("left", 0) }, onHidden: function() { $(".ui.toc.sticky").sticky("refresh") } }).sidebar("attach events", ".launch.button, .chapter-title, .launch.item"); $(".ui.top.sidebar").sidebar({ transition: "overlay", mobileTransition: "uncover" }).sidebar("attach events", ".item.header.right.menu"); $(".ui.progress").progress(); // 选项页 $('.menu .item').tab() } /** 懒加载*/ initLazyload(){ //