hexo-theme-volantis 5.7.9 → 5.7.10

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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [5.7.10](https://github.com/volantis-x/hexo-theme-volantis/compare/5.7.9...5.7.10) (2023-04-28)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * 修复移动端菜单栏按钮点击没有收起二级子菜单的问题 ([#880](https://github.com/volantis-x/hexo-theme-volantis/issues/880)) ([bb7738b](https://github.com/volantis-x/hexo-theme-volantis/commit/bb7738b9dcfa375e263ee4ca648d437703b15182))
9
+
3
10
  ## [5.7.9](https://github.com/volantis-x/hexo-theme-volantis/compare/5.7.8...5.7.9) (2023-04-26)
4
11
 
5
12
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hexo-theme-volantis",
3
- "version": "5.7.9",
3
+ "version": "5.7.10",
4
4
  "description": "Elegant and powerful theme for Hexo.",
5
5
  "main": "package.json",
6
6
  "scripts": {
package/source/js/app.js CHANGED
@@ -285,49 +285,73 @@ const VolantisApp = (() => {
285
285
  fn.setGlobalHeaderMenuEvent = () => {
286
286
  if (volantis.isMobile) {
287
287
  // 【移动端】 关闭已经展开的子菜单 点击展开子菜单
288
- document.querySelectorAll('#l_header .m-phone li').forEach(function (e) {
289
- if (e.querySelector(".list-v")) {
288
+ document.querySelectorAll('#l_header .m-phone li').forEach(function (_e) {
289
+ if (_e.querySelector(".list-v")) {
290
290
  // 点击菜单
291
- volantis.dom.$(e).click(function (e) {
291
+ volantis.dom.$(_e).click(function (e) {
292
292
  e.stopPropagation();
293
- // 关闭已经展开的子菜单
294
- // e.currentTarget.parentElement.childNodes.forEach(function (e) {
295
- // if (Object.prototype.toString.call(e) == '[object HTMLLIElement]') {
296
- // e.childNodes.forEach(function (e) {
297
- // if (Object.prototype.toString.call(e) == '[object HTMLUListElement]') {
298
- // volantis.dom.$(e).hide()
299
- // }
300
- // })
301
- // }
302
- // })
303
- // 点击展开子菜单
304
- /*
305
- jasonhuang: 这里出现两个错误
306
- 第一个: 本来以上代码下拉菜单再次点击又被隐藏了,下面的代码又把它打开了。当第一次点击.s-menu fa-solid fa-bars fa-fw这个元素时,下拉菜单要打开。再点的时候应该把下拉菜单关闭,不应该再执行以下代码.需要先判断
307
- ul.menu-phone list-v navigation white-box打开没有。但是不能凭借style.display是否为none不严谨, 应该是window.getComputedStyle
308
- 这一题,如果是用jquery,寻找e.currentTarget也就是被点击的li标签, 其中的子元素.menu-phone很简单$(e.currentTarget).children('.menu-phone')
309
- 直接找e.currentTarget的子元素中类名为menu-phone的(找className或classList),判断他是否处于打开的状态。那这里不一定有jquery,只能原生
310
-
311
- 其实上面那串代码用不到了,直接判断是否打开,取反就好了,应该和 下面写一起,否则也太混乱了
312
- 第二个:volantis.dom.$(element).display这种设置样式是无效的,class,id可以这么用,但是这是样式。得volantis.dom.$(element).style.display
313
- 我看了volantis.dom.$(element)返回的dom对象,而jquery(element)返回的是jquery对象。这是不一样的
314
- 我看了下结构, volantis.dom.$(element)和element引用是一样的,区别是增加了show,hide,click, toggleClass等方法
315
- */
316
- let array = e.currentTarget.children
317
- for (let index = 0; index < array.length; index++) {
318
- const element = array[index];
319
- if (volantis.dom.$(element).title === 'menu') { // 移动端菜单栏异常
320
- volantis.dom.$(element).style.display = "flex" // https://github.com/volantis-x/hexo-theme-volantis/issues/706
321
- } else {
322
- // 判断.menu-phone元素style.display是否为none
323
- let is_hiding = window.getComputedStyle(element).display === 'none'
324
- if(is_hiding) {
325
- volantis.dom.$(element).show()
293
+ let menuType = ''
294
+ // 关闭.menu-phone
295
+ Array.from(e.currentTarget.children).some(val => {
296
+ if(val.classList.contains('s-menu')) {
297
+ menuType = 'menu' // 代表点击的是一级菜单外层的icon
298
+ return
299
+ }
300
+ if(val.classList.contains('menuitem')) {
301
+ menuType = 'item' // 点击的是下拉一级菜单
302
+ return
303
+ }
304
+ })
305
+ if(menuType === 'item') {
306
+ // 关闭已经展开的子菜单, 这一步是针对点击多个拥有二级子菜单的一级菜单,关闭其他所有一级菜单的二级菜单
307
+ //
308
+ e.currentTarget.parentElement.childNodes.forEach(function (e2) {
309
+ if (Object.prototype.toString.call(e2) == '[object HTMLLIElement]') {
310
+ e2.childNodes.forEach(function (e1) {
311
+ if (Object.prototype.toString.call(e1) == '[object HTMLUListElement]') {
312
+ volantis.dom.$(e1).hide()
313
+ }
314
+ })
315
+ }
316
+ })
317
+ // 点击展开二级子菜单
318
+
319
+ /*
320
+ 由于采用事件委托,因此此处点击, 两种情况,currentTarget指向菜单按钮a.s-menu和ul的共同父元素li, 第二,指向ul中的li元素,也就是子菜单
321
+ 区分:情况一的第一个子元素a的类名是s-menu;情况二的子元素a的类名为menuitem
322
+ 我们要点击外部的menu icon时要关闭的是.menu-phone而不是.menuitem
323
+ */
324
+ let array = e.currentTarget.children
325
+ for (let index = 0; index < array.length; index++) {
326
+ const element = array[index];
327
+ if (volantis.dom.$(element).title === 'menu') { // 移动端菜单栏异常
328
+ volantis.dom.$(element).style.display = "flex" // https://github.com/volantis-x/hexo-theme-volantis/issues/706
326
329
  } else {
327
- volantis.dom.$(element).hide()
330
+ volantis.dom.$(element).show()
328
331
  }
329
332
  }
333
+ } else {
334
+ let menuPhone = document.querySelector('.switcher .menu-phone')
335
+ let isHiding = window.getComputedStyle(menuPhone).display === 'none'
336
+ if(isHiding) {
337
+ volantis.dom.$(menuPhone).show()
338
+ } else {
339
+ volantis.dom.$(menuPhone).hide()
340
+ // 别忘了再执行①
341
+ // 准备关闭所有二级菜单, 注意此时的e和点击一级菜单时候的e层级不同
342
+ // 此处好像不能使用变量存储的menuPhone?要重新查询
343
+ document.querySelector('.switcher .menu-phone').childNodes.forEach(function (e2) {
344
+ if (Object.prototype.toString.call(e2) == '[object HTMLLIElement]') {
345
+ e2.childNodes.forEach(function (e1) {
346
+ if (Object.prototype.toString.call(e1) == '[object HTMLUListElement]') {
347
+ volantis.dom.$(e1).hide()
348
+ }
349
+ })
350
+ }
351
+ })
352
+ }
330
353
  }
354
+
331
355
  }, 0);
332
356
  }
333
357
  })
@@ -346,7 +370,7 @@ const VolantisApp = (() => {
346
370
  }
347
371
  fn.setPageHeaderMenuEvent();
348
372
  }
349
-
373
+
350
374
  // 【移动端】隐藏子菜单
351
375
  fn.setPageHeaderMenuEvent = () => {
352
376
  if (!volantis.isMobile) return