MCPcopy
hub / github.com/iChochy/NCE / updateActiveUnit

Method updateActiveUnit

js/ReadingSystem.js:372–389  ·  view source on GitHub ↗

* 更新活跃单元 * @param {number} unitIndex - 单元索引 * @param {Object} [options={}] - 选项

(unitIndex, options = {})

Source from the content-addressed store, hash-verified

370 * @param {Object} [options={}] - 选项
371 */
372 updateActiveUnit(unitIndex, options = {}) {
373 const { shouldScrollUnitIntoView = false } = options;
374
375 if (this.dom.unitList) {
376 qsa('.unit-item', this.dom.unitList).forEach((item, index) => {
377 toggleClass(item, 'active', index === unitIndex);
378 });
379
380 const activeItem = qs(`.unit-item[data-unit-index="${unitIndex}"]`, this.dom.unitList);
381 if (activeItem && shouldScrollUnitIntoView) {
382 activeItem.scrollIntoView({ block: 'center', inline: 'nearest' });
383 }
384 }
385
386 if (this.dom.unitSelect) {
387 this.dom.unitSelect.value = unitIndex;
388 }
389 }
390
391 // =========================================================================
392 // 歌词管理

Callers 1

loadUnitByIndexMethod · 0.95

Calls 3

qsaFunction · 0.90
toggleClassFunction · 0.90
qsFunction · 0.90

Tested by

no test coverage detected