jeawin-astro 5.0.13 → 5.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jeawin-astro",
3
- "version": "5.0.13",
3
+ "version": "5.0.14",
4
4
  "author": "chaegumi <chaegumi@qq.com>",
5
5
  "description": "Astro components for Jeawin CMS",
6
6
  "license": "MIT",
@@ -95,17 +95,13 @@ const categories: any[] = get_children_categories(
95
95
  </nav>
96
96
 
97
97
  <script is:inline>
98
- (function initSidebarMenu() {
98
+ registerRule('navbar-sidebar', () => {
99
99
  const nav = document.querySelector("#navbar-sidebar");
100
100
  if(nav && typeof SmartMenus !== 'undefined'){
101
- requestAnimationFrame(() => {
102
- new SmartMenus(nav, {
103
- dropdownsShowTrigger: "mouseover",
104
- dropdownsHideTrigger: "mouseout",
105
- });
106
- });
107
- }else if(!nav){
108
- setTimeout(initSidebarMenu, 50);
101
+ new SmartMenus(nav, {
102
+ dropdownsShowTrigger: "mouseover",
103
+ dropdownsHideTrigger: "mouseout",
104
+ });
109
105
  }
110
- })();
106
+ });
111
107
  </script>
@@ -148,17 +148,13 @@ const menus = await jeawinapi.get_menu_tree({ menu_id: 1 });
148
148
  </nav>
149
149
 
150
150
  <script is:inline>
151
- (function initMenu() {
151
+ registerRule('navbar-header', () => {
152
152
  const nav = document.querySelector("#navbar-header");
153
153
  if(nav && typeof SmartMenus !== 'undefined'){
154
- requestAnimationFrame(() => {
155
- new SmartMenus(nav, {
156
- dropdownsShowTrigger: "mouseover",
157
- dropdownsHideTrigger: "mouseout",
158
- });
154
+ new SmartMenus(nav, {
155
+ dropdownsShowTrigger: "mouseover",
156
+ dropdownsHideTrigger: "mouseout",
159
157
  });
160
- }else if(!nav){
161
- setTimeout(initMenu, 50);
162
158
  }
163
- })();
159
+ });
164
160
  </script>
@@ -96,17 +96,13 @@ const menus = await jeawinapi.get_menu_tree({ menu_id: 1 });
96
96
 
97
97
 
98
98
  <script is:inline>
99
- (function initMenu() {
99
+ registerRule('navbar-header', () => {
100
100
  const nav = document.querySelector("#navbar-header");
101
101
  if(nav && typeof SmartMenus !== 'undefined'){
102
- requestAnimationFrame(() => {
103
- new SmartMenus(nav, {
104
- dropdownsShowTrigger: "mouseover",
105
- dropdownsHideTrigger: "mouseout",
106
- });
102
+ new SmartMenus(nav, {
103
+ dropdownsShowTrigger: "mouseover",
104
+ dropdownsHideTrigger: "mouseout",
107
105
  });
108
- }else if(!nav){
109
- setTimeout(initMenu, 50);
110
106
  }
111
- })();
107
+ });
112
108
  </script>
@@ -8,7 +8,7 @@
8
8
  * @email chaegumi@jeawin.com
9
9
  * @filesource
10
10
  */
11
- import smartmenusLib from "smartmenus/dist/js/smartmenus.browser.min.js?raw";
11
+ // import smartmenusLib from "smartmenus/dist/js/smartmenus.browser.min.js?raw";
12
12
  import '../styles/global.css';
13
13
  import { Font } from "astro:assets";
14
14
  import _ from "lodash";
@@ -244,7 +244,29 @@ if (page_type == "category") {
244
244
 
245
245
  {font_css_variable ? (<Font cssVariable={font_css_variable} preload />) : null}
246
246
 
247
-
247
+ <script is:inline>
248
+ // 定义函数注册表
249
+ const ruleFunctions = {};
250
+
251
+ // 注册规则函数
252
+ function registerRule(ruleName, fn) {
253
+ ruleFunctions[ruleName] = fn;
254
+ }
255
+
256
+ // 统一调用所有规则
257
+ function executeAllRules() {
258
+ const results = {};
259
+ for (const [ruleName, fn] of Object.entries(ruleFunctions)) {
260
+ try {
261
+ results[ruleName] = fn();
262
+ } catch (error) {
263
+ console.error(`规则 ${ruleName} 执行失败:`, error);
264
+ results[ruleName] = { error: error.message };
265
+ }
266
+ }
267
+ return results;
268
+ }
269
+ </script>
248
270
  </Head>
249
271
  <body>
250
272
  <Fragment
@@ -323,34 +345,14 @@ if (page_type == "category") {
323
345
  color: #ff0000;
324
346
  }
325
347
  </style>
326
- <script is:inline set:html={smartmenusLib}></script>
327
- <script is:inline>
328
- (function initMenu() {
329
- const nav = document.querySelector("#navbar-header");
330
- if(nav && typeof SmartMenus !== 'undefined'){
331
- requestAnimationFrame(() => {
332
- new SmartMenus(nav, {
333
- dropdownsShowTrigger: "mouseover",
334
- dropdownsHideTrigger: "mouseout",
335
- });
336
- });
337
- }else if(!nav){
338
- setTimeout(initMenu, 50);
339
- }
340
- })();
341
- </script>
348
+ <script src="/smartmenus/dist/js/smartmenus.browser.min.js" is:inline async id="smartmenus-lib"></script>
342
349
  <script is:inline>
343
- (function initSidebarMenu() {
344
- const nav = document.querySelector("#navbar-sidebar");
345
- if(nav && typeof SmartMenus !== 'undefined'){
346
- requestAnimationFrame(() => {
347
- new SmartMenus(nav, {
348
- dropdownsShowTrigger: "mouseover",
349
- dropdownsHideTrigger: "mouseout",
350
- });
351
- });
352
- }else if(!nav){
353
- setTimeout(initSidebarMenu, 50);
350
+ (function(){
351
+ const script = document.getElementById('smartmenus-lib');
352
+ if(window.SmartMenus){
353
+ executeAllRules();
354
+ }else{
355
+ script.addEventListener('load', executeAllRules);
354
356
  }
355
357
  })();
356
358
  </script>