feat(runtime): 全站前端脚本统一接入 AksrtFrontend 全局 DOM 生命周期
- rehydrate.js 新增 boot()/aksrt:ready 事件,支持 boot 后晚注册立即以 init 触发 - aksrt-runtime.js 初始加载改走 AksrtFrontend.boot,tooltip/倒计时注册为组件 - 约 30 个前端脚本(首页、评论、支付、路由、页面叶子、widgets) 从直接 DOMContentLoaded 迁移为 AksrtFrontend.register,并加幂等标记 - section-navs 依赖改为 aksrt-runtime,保证注册时序 - 清理死代码:删除孤儿 loader.js/main.js 及 runtime/page-navs 遗留副本 - loader.js 移除已迁移模块的 tbquire 路径映射,main.js 相应瘦身 - build-public-assets.mjs 增加 runtime/main.min.js 自动压缩步骤 - 新增 4 个契约测试(homepage-dom/rehydrate-runtime/global-dom-init/ public-bundle-parity),3 个既有 harness 适配注册表初始化方式
This commit is contained in:
@@ -59,17 +59,8 @@ tbquire.config({
|
||||
'translate' : 'libs/translate.min',
|
||||
'waterfall' : 'waterfall.min',
|
||||
'enlighterjs' : 'enlighter/enlighterjs.min',
|
||||
'section-navs' : 'section-navs.min',
|
||||
|
||||
'poster-share' : 'poster-share.min',
|
||||
'comment' : 'comment.min',
|
||||
'page-template' : 'page-template.min',
|
||||
'page-edit' : 'page-edit.min',
|
||||
'author' : 'author.min',
|
||||
'page-navs' : 'page-navs.min',
|
||||
'input-expand' : 'input-expand.min',
|
||||
'mini-touch' : 'mini-touch.min',
|
||||
'mini-upload' : 'mini-upload.min',
|
||||
'editextend' : 'editextend.min',
|
||||
'petite-vue' : 'libs/petite-vue.iife',
|
||||
'svg-icon' : 'svg-icon',
|
||||
|
||||
+16
-39
@@ -1872,7 +1872,7 @@ function post_ajax(_this, con, jcon, item, loader, pag, next, trigger, replace,
|
||||
}
|
||||
|
||||
swiper_tab_AutoHeight($con);
|
||||
auto_fun();
|
||||
window.AksrtFrontend.rehydrate($con[0], 'ajax');
|
||||
},
|
||||
});
|
||||
return !1;
|
||||
@@ -1884,7 +1884,7 @@ _win.bd.on('click', '[remote-box]', function () {
|
||||
if (remote) {
|
||||
jQuery.post(remote, null, function (data) {
|
||||
_this.html(data).removeAttr('remote-box');
|
||||
auto_fun();
|
||||
window.AksrtFrontend.rehydrate(_this[0], 'ajax');
|
||||
_this.trigger('aksrt:remote-loaded');
|
||||
});
|
||||
}
|
||||
@@ -2176,7 +2176,7 @@ _win.bd.on('show.bs.modal loaded.bs.modal', '.modal:not(.flex)', function () {
|
||||
});
|
||||
|
||||
_win.bd.on('show.bs.modal loaded.bs.modal', '.modal', function () {
|
||||
auto_fun();
|
||||
window.AksrtFrontend.rehydrate(this, 'modal');
|
||||
});
|
||||
|
||||
_win.modal_z_index = 1050;
|
||||
@@ -2420,7 +2420,9 @@ function z_auto() {
|
||||
}
|
||||
}
|
||||
|
||||
window.auto_fun = debounce(z_auto_fun, 100);
|
||||
window.auto_fun = debounce(function (root) {
|
||||
window.AksrtFrontend.rehydrate(root && root.nodeType ? root : document, 'ajax');
|
||||
}, 100);
|
||||
function z_auto_fun() {
|
||||
jQuery(document).trigger('auto_fun');
|
||||
|
||||
@@ -2433,9 +2435,6 @@ function z_auto_fun() {
|
||||
//可复制
|
||||
jQuery('.cloneable').cloneable();
|
||||
|
||||
//倒计时
|
||||
jQuery('[data-countdown]').countdown();
|
||||
|
||||
auto_maxHeight();
|
||||
//兼容性图片懒加载
|
||||
jQuery('img[data-src]:not(.lazyload,.lazyloaded,.lazyloading,.swiper-lazy)').addClass('lazyload');
|
||||
@@ -2446,13 +2445,6 @@ function z_auto_fun() {
|
||||
});
|
||||
*/
|
||||
|
||||
jQuery('.dropdown-code,.dropdown-image,.dropdown-quick-often').length && tbquire(['input-expand']);
|
||||
/**上传图片 */
|
||||
jQuery('[aksrtupload]').length && tbquire(['mini-upload']);
|
||||
|
||||
//海报分享
|
||||
jQuery('[poster-share]').length && tbquire(['poster-share']); //海报分享
|
||||
|
||||
/* 提示工具*/
|
||||
jQuery("[data-toggle='tooltip']").tooltip({
|
||||
container: 'body',
|
||||
@@ -3095,21 +3087,6 @@ _win.bd.on('input focus', 'textarea[autoHeight]', function () {
|
||||
_win.bd.on('click', '.rewards', function () {
|
||||
jQuery('#rewards-popover').modal('show');
|
||||
});
|
||||
//用户中心
|
||||
_win.bd.hasClass('author') && tbquire(['author']);
|
||||
|
||||
//文章导航
|
||||
_win.bd.hasClass('page-template-postsnavs') && _win.bd.hasClass('logged-admin') && tbquire(['page-navs']);
|
||||
//前台编辑
|
||||
jQuery('#modal_admin_set').length && tbquire(['page-edit']);
|
||||
//评论
|
||||
jQuery('#commentform,#postcomments').length && tbquire(['comment']);
|
||||
//通用模板js文件
|
||||
_win.bd.hasClass('page-template') && tbquire(['page-template']);
|
||||
|
||||
//微信分享
|
||||
window.WeChatShareDate && tbquire(['weixin-share']);
|
||||
|
||||
//搜索关键词高亮
|
||||
if (_win.bd.hasClass('search')) {
|
||||
var val = jQuery('.search-desc-text .search-key').text();
|
||||
@@ -3520,7 +3497,7 @@ jQuery.fn.AutoSearch = function () {
|
||||
_this.removeClass(loading);
|
||||
_remind.html(result.remind || '');
|
||||
_icon.html(_icon_html);
|
||||
auto_fun();
|
||||
window.AksrtFrontend.rehydrate(_container[0], 'ajax');
|
||||
},
|
||||
'json'
|
||||
);
|
||||
@@ -3969,12 +3946,6 @@ function posts_limit_height() {
|
||||
}
|
||||
}
|
||||
|
||||
auto_fun();
|
||||
thumb_dplayer(_wid > 640 ? '.posts-item .item-thumbnail,.forum-lists-cover' : '.posts-item,.forum-posts', '.video-thumb-box[video-url]');
|
||||
|
||||
//页面加载之后自动点击
|
||||
jQuery('[load-click]').attr('no-scroll', true).click();
|
||||
|
||||
//图片延迟懒加载-ias自动加载
|
||||
jQuery(document).on('lazybeforeunveil', function (e) {
|
||||
var _this = jQuery(e.target);
|
||||
@@ -4553,7 +4524,7 @@ _win.bd.on('click', '.customize-preview-widget-edit', function (e) {
|
||||
});
|
||||
|
||||
//页面加载完毕之后加载的函数
|
||||
jQuery(document).ready(function () {
|
||||
function initLegacyDocumentReady() {
|
||||
setTimeout(function () {
|
||||
//页面加载完毕之后再延迟两秒加载的函数
|
||||
|
||||
@@ -4700,8 +4671,6 @@ jQuery(document).ready(function () {
|
||||
});
|
||||
|
||||
/*文章目录*/
|
||||
jQuery('[data-nav] h1,[data-nav] h2,[data-nav] h3,[data-nav] h4').length > 2 && tbquire(['section-navs']);
|
||||
|
||||
//手势控制
|
||||
jQuery('[mini-touch]').each(function () {
|
||||
var _this = jQuery(this);
|
||||
@@ -4718,4 +4687,12 @@ jQuery(document).ready(function () {
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
window.AksrtFrontend.register('aksrt-legacy-main', function (root, reason) {
|
||||
z_auto_fun();
|
||||
if (reason !== 'init') return;
|
||||
initLegacyDocumentReady();
|
||||
thumb_dplayer(_wid > 640 ? '.posts-item .item-thumbnail,.forum-lists-cover' : '.posts-item,.forum-posts', '.video-thumb-box[video-url]');
|
||||
jQuery('[load-click]').attr('no-scroll', true).click();
|
||||
});
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -1,46 +0,0 @@
|
||||
//文章导航
|
||||
jQuery("button[evt='action']").on("click", function (t) {
|
||||
t = t || window.event;
|
||||
var a = t.target || t.srcElement,
|
||||
e = jQuery(a),
|
||||
n = e.parents("form"),
|
||||
r = n.serializeObject(),
|
||||
c = [];
|
||||
return jQuery("#cat-sortable-ok .sortable-cat-item").each(function () {
|
||||
c.push(jQuery(this).attr("data-id"));
|
||||
}), r.navs_show_cat_id = c, save_userdata(r, aksrt__("save_success"), "reload"), !1;
|
||||
});
|
||||
|
||||
function save_userdata(b, c, d) {
|
||||
notyf(aksrt__("processing_wait"), "load", "", "user_ajax"),
|
||||
c = c || aksrt__("done");
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: _win.uri + '/action/post_navs.php',
|
||||
data: b,
|
||||
dataType: "json",
|
||||
success: function (n) {
|
||||
if (n.error) {
|
||||
n.msg && notyf(n.msg, (n.error ? 'danger' : ""), "", "user_ajax");
|
||||
} else {
|
||||
notyf(n.msg || c, "", "", "user_ajax");
|
||||
"reload" == d && location.reload();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
jQuery(document).ready(function () {
|
||||
jQuery("#cat-sortable").length && tbquire(["sortablejs"], function () {
|
||||
var e = document.getElementById("cat-sortable"),
|
||||
t = document.getElementById("cat-sortable-ok"),
|
||||
a = {
|
||||
group: "cat_shared",
|
||||
multiDrag: !0,
|
||||
chosenClass: "chosen",
|
||||
fallbackClass: !0,
|
||||
animation: 400
|
||||
};
|
||||
Sortable.create(e, a), Sortable.create(t, a);
|
||||
});
|
||||
});
|
||||
Vendored
-1
@@ -1 +0,0 @@
|
||||
function save_userdata(a,t,e){notyf(aksrt__("processing_wait"),"load","","user_ajax"),t=t||aksrt__("done"),jQuery.ajax({type:"POST",url:_win.uri+"/action/post_navs.php",data:a,dataType:"json",success:function(a){a.error?a.msg&¬yf(a.msg,a.error?"danger":"","","user_ajax"):(notyf(a.msg||t,"","","user_ajax"),"reload"==e&&location.reload())}})}jQuery("button[evt='action']").on("click",function(a){a=a||window.event;var t=a.target||a.srcElement,e=jQuery(t),o=e.parents("form"),r=o.serializeObject(),s=[];return jQuery("#cat-sortable-ok .sortable-cat-item").each(function(){s.push(jQuery(this).attr("data-id"))}),r.navs_show_cat_id=s,save_userdata(r,aksrt__("save_success"),"reload"),!1}),jQuery(document).ready(function(){jQuery("#cat-sortable").length&&tbquire(["sortablejs"],function(){var a=document.getElementById("cat-sortable"),t=document.getElementById("cat-sortable-ok"),e={group:"cat_shared",multiDrag:!0,chosenClass:"chosen",fallbackClass:!0,animation:400};Sortable.create(a,e),Sortable.create(t,e)})});
|
||||
Reference in New Issue
Block a user