52 lines
2.1 KiB
JavaScript
52 lines
2.1 KiB
JavaScript
/* ui-minimap-fit.js —— 小地图与底部工具栏的避让(v3.26.18)
|
|
*
|
|
* 小地图与悬浮工具栏同一排(都在底部)。右栏拉宽会压缩画布可用宽度,
|
|
* 当两者横向重叠时,把小地图淡出隐藏(而不是硬挤或改布局)。
|
|
* 触发:窗口 resize / 工具栏或小地图尺寸变化 / 停靠栏拖宽(iwb:dock-resizing)。
|
|
*/
|
|
;(function (global) {
|
|
'use strict'
|
|
var GAP = 8
|
|
function install () {
|
|
try {
|
|
var doc = global.document
|
|
if (!doc || global.IWBMiniMapFitInstalled) return
|
|
global.IWBMiniMapFitInstalled = true
|
|
var raf = 0
|
|
function fit () {
|
|
raf = 0
|
|
try {
|
|
var bar = doc.querySelector('.iwb-toolbar-wrap .iwb-toolbar')
|
|
var mm = doc.querySelector('.iwb-minimap')
|
|
if (!bar || !mm) return
|
|
var a = bar.getBoundingClientRect()
|
|
var b = mm.getBoundingClientRect()
|
|
var tight = b.left < a.right + GAP
|
|
if (mm.classList.contains('iwb-minimap-tight') !== tight) mm.classList.toggle('iwb-minimap-tight', tight)
|
|
} catch (e) { /* ignore */ }
|
|
}
|
|
function schedule () { if (!raf) raf = global.requestAnimationFrame(fit) }
|
|
var ro = null
|
|
try {
|
|
if (typeof global.ResizeObserver === 'function') {
|
|
ro = new global.ResizeObserver(schedule)
|
|
var observe = function () {
|
|
try {
|
|
var nodes = doc.querySelectorAll('.iwb-toolbar-wrap, .iwb-toolbar, .iwb-minimap')
|
|
for (var i = 0; i < nodes.length; i++) ro.observe(nodes[i])
|
|
} catch (e) { /* ignore */ }
|
|
}
|
|
observe()
|
|
try {
|
|
new global.MutationObserver(function () { observe(); schedule() }).observe(doc.body, { childList: true, subtree: true })
|
|
} catch (e) { /* ignore */ }
|
|
}
|
|
} catch (e) { /* ignore */ }
|
|
global.addEventListener('resize', schedule)
|
|
global.addEventListener('iwb:dock-resizing', schedule)
|
|
schedule()
|
|
} catch (e) { /* ignore */ }
|
|
}
|
|
global.IWBMiniMapFit = { install: install }
|
|
})(typeof window !== 'undefined' ? window : globalThis)
|