fix(gallery): 1.8.1 回退懒加载(1.8.0 让大量卡片永远停在「加载中…」),双击改事件委托
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 45s
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 45s
用户反馈 1.8.0 之后:图库加载不完、双击打不开、卡片被窗口裁掉。 - 懒加载撤销:IntersectionObserver 在停靠栏里不稳定 —— 部分卡片(尤其右列)永远收不到 intersecting, 一直停在「加载中…」,没有 <img> 也就没有点击/双击目标。改回同步取缩略图(同 1.7.5 行为)。 - 双击改为在 grid 上事件委托(按 data-name 处理),不再依赖某张 <img> 存活; 即使卡片被重绘替换,双击仍能打开预览。 - pick() 里补一次 measure():面板被拖窄后列数会停在旧值上,卡片被窗口裁掉(1.8.0 取消整格重绘后失去了这个副作用修复)。 - 保留 1.8.0 的两个改进:选中只改 class(不整格重绘、不跳顶)、重排前后恢复 scrollTop。
This commit is contained in:
1 parent
31ffde68ce
commit
6c598e3898
3 files changed
+22
-28
No files matched your search
+17
-23
@@ -340,7 +340,6 @@
|
||||
}
|
||||
|
||||
function renderGrid () {
|
||||
if (io) { try { io.disconnect() } catch (e) { /* ignore */ } }
|
||||
clear(grid)
|
||||
var gap = 6
|
||||
// 每次重排都重新量一次宽度:面板显隐/停靠栏展开时 gridW 可能是旧值,
|
||||
@@ -380,22 +379,6 @@
|
||||
}
|
||||
|
||||
// ── v1.8.0:懒加载观察器 / 滚动位置保持 / 选中态就地更新 ─────────────────
|
||||
var io = null
|
||||
function ensureIO () {
|
||||
if (io || typeof global.IntersectionObserver !== 'function') return io
|
||||
io = new global.IntersectionObserver(function (list) {
|
||||
for (var i = 0; i < list.length; i++) {
|
||||
var e = list[i]
|
||||
if (!e || !e.isIntersecting) continue
|
||||
var node = e.target
|
||||
try { io.unobserve(node) } catch (err) { /* ignore */ }
|
||||
var fn = node && node.__iwbBoot
|
||||
node.__iwbBoot = null
|
||||
if (typeof fn === 'function') fn()
|
||||
}
|
||||
}, { root: null, rootMargin: '300px 0px' })
|
||||
return io
|
||||
}
|
||||
// 找到真正滚动的祖先(grid 自己在 .iwb-history 里滚),用于重排后恢复位置
|
||||
function scrollerOf () {
|
||||
var p = grid && grid.parentNode
|
||||
@@ -467,7 +450,6 @@
|
||||
fail('缩略图加载失败(点击重试)')
|
||||
})
|
||||
img.addEventListener('click', function (e) { pick(it.name, !!(e && e.shiftKey)) })
|
||||
img.addEventListener('dblclick', function () { ctx.gallery.preview(it.name) })
|
||||
img.addEventListener('dragstart', function (e) {
|
||||
try {
|
||||
var names = (picked[it.name] && count() > 1) ? pickedNames() : [it.name]
|
||||
@@ -498,11 +480,8 @@
|
||||
}
|
||||
// v1.8.0:缩略图按可见性懒加载(IntersectionObserver,上下预取 300px)——
|
||||
// 原来一次性对全部条目发 IPC 取缩略图,列表一长首屏就慢。
|
||||
box.__iwbBoot = boot
|
||||
var io0 = ensureIO()
|
||||
// 前 30 张仍然同步取(首屏 / e2e 需要立刻可见),其余按可见性懒加载
|
||||
if (!io0 || Number(seq) < 30) boot()
|
||||
else io0.observe(box)
|
||||
// v1.8.1:撤销懒加载——IntersectionObserver 在停靠栏里不稳定,大量卡片停在「加载中…」
|
||||
boot()
|
||||
box.addEventListener('contextmenu', function (e) { openMenu(e, it) })
|
||||
var acts = el('div', { class: 'iwb-history-actions' })
|
||||
function act (label, title, fn) {
|
||||
@@ -546,12 +525,27 @@
|
||||
}).catch(function () { setStatus('下载失败,可再点一次重试') })
|
||||
}
|
||||
|
||||
// v1.8.1:双击打开改成在 grid 上做事件委托 —— 原来监听在 <img> 上,一旦卡片被重绘替换,
|
||||
// dblclick 就永远落不到同一个元素(用户反馈「双击打不开」)。委托到容器后按 data-name 处理。
|
||||
grid.addEventListener('dblclick', function (e) {
|
||||
var node = e.target
|
||||
while (node && node !== grid && !(node.getAttribute && node.getAttribute('data-name'))) node = node.parentNode
|
||||
if (!node || node === grid) return
|
||||
var nm = node.getAttribute('data-name')
|
||||
if (!nm) return
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
try { ctx.gallery.preview(nm) } catch (err) { /* ignore */ }
|
||||
})
|
||||
|
||||
function pick (name, shift) {
|
||||
if (shift) { if (picked[name]) delete picked[name]; else picked[name] = 1 } else { picked = {}; picked[name] = 1 }
|
||||
// v1.8.0:选中只就地改 class/勾选角标 —— 原来整个网格重建,滚动条被顶回顶部,
|
||||
// 而且正在双击的那张 <img> 被换掉,双击因此经常打不开。
|
||||
syncSelection()
|
||||
renderHead()
|
||||
// 顺手量一次宽度:面板被拖窄后如果没有其它触发条件,列数会停在旧值上(卡片被窗口裁掉)
|
||||
try { measure() } catch (e) { /* ignore */ }
|
||||
}
|
||||
function syncSelection () {
|
||||
var managed = !!count()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"id": "gallery",
|
||||
"name": "图库",
|
||||
"version": "1.8.0",
|
||||
"version": "1.8.1",
|
||||
"apiVersion": 1,
|
||||
"main": "main.js",
|
||||
"style": "styles.css",
|
||||
@@ -13,7 +13,7 @@
|
||||
"图库"
|
||||
],
|
||||
"files": {
|
||||
"main.js": "39a93d36a9294c183136e20f90c8c8885a67ada6adc1602b334836cfcba0e15d",
|
||||
"main.js": "6dd3bf43dce74236d4904c4e33639772ef03bd4cd80d6e5a4532ff7ca7ed085a",
|
||||
"styles.css": "14d374b5d0e1461cb1ca2b125865e9c27df7c3bd79c11caa0afc52152c7d0aef"
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -33,10 +33,10 @@
|
||||
"dir": "gallery",
|
||||
"main": "main.js",
|
||||
"style": "styles.css",
|
||||
"version": "1.8.0",
|
||||
"version": "1.8.1",
|
||||
"files": {
|
||||
"manifest.json": "3eabd6d707e2154a955049bda895d9c4f32afecaa00df1d9b3e92c92fd4930cd",
|
||||
"main.js": "39a93d36a9294c183136e20f90c8c8885a67ada6adc1602b334836cfcba0e15d",
|
||||
"manifest.json": "8e1235f0f0d89d81c9aafe8e4eac4a4dc3521c1b583c845b15595ddeecc7c0c2",
|
||||
"main.js": "6dd3bf43dce74236d4904c4e33639772ef03bd4cd80d6e5a4532ff7ca7ed085a",
|
||||
"styles.css": "14d374b5d0e1461cb1ca2b125865e9c27df7c3bd79c11caa0afc52152c7d0aef"
|
||||
}
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user