/** * 统一「查看 XX」模态框(参照 IntelliRschAsst/paper_writing.html「查看论文」) * - IARViewEntityModal:打开/关闭、标题、Bootstrap 实例 * - 配合 templates/macros/view_entity_modal.html */ (function (global) { 'use strict'; var _registry = {}; function _cfg(modalId) { return _registry[modalId] || {}; } function _modalEl(modalId) { return document.getElementById(modalId); } function _titleEl(modalId) { var el = _modalEl(modalId); var id = el && el.getAttribute('data-iar-title-id'); if (!id) { var cfg = _cfg(modalId); id = cfg.titleId || (modalId + 'Title'); } return id ? document.getElementById(id) : null; } function register(modalId, options) { if (!modalId) return; _registry[modalId] = Object.assign({}, _registry[modalId] || {}, options || {}); } function getInstance(modalId) { var el = _modalEl(modalId); if (!el || typeof bootstrap === 'undefined' || !bootstrap.Modal) return null; return bootstrap.Modal.getOrCreateInstance(el); } function show(modalId) { var inst = getInstance(modalId); if (inst) inst.show(); return inst; } function hide(modalId) { var el = _modalEl(modalId); if (!el || typeof bootstrap === 'undefined' || !bootstrap.Modal) return null; var inst = bootstrap.Modal.getInstance(el); if (inst) inst.hide(); return inst; } function setTitle(modalId, titleHtml) { var title = _titleEl(modalId); if (!title) return; var cfg = _cfg(modalId); var el = _modalEl(modalId); var icon = (cfg.icon || (el && el.getAttribute('data-iar-entity-icon')) || '').replace(/^fa-/, ''); var iconClass = icon ? ('fa-' + icon) : ((el && el.getAttribute('data-iar-entity-icon')) || ''); if (iconClass && String(titleHtml || '').indexOf(' ' + String(titleHtml || ''); } else { title.innerHTML = String(titleHtml || ''); } } function setText(id, text) { var el = document.getElementById(id); if (!el) return; var v = text == null || text === '' ? '-' : String(text); if (el.tagName === 'INPUT' || el.tagName === 'TEXTAREA') { el.value = v === '-' ? '' : v; } else { el.textContent = v; } } function setHtml(id, html) { var el = document.getElementById(id); if (!el) return; el.innerHTML = html == null || html === '' ? '-' : String(html); } function fillMap(map) { if (!map) return; Object.keys(map).forEach(function (id) { setText(id, map[id]); }); } global.IARViewEntityModal = { register: register, show: show, hide: hide, getInstance: getInstance, setTitle: setTitle, setText: setText, setHtml: setHtml, fillMap: fillMap, }; })(typeof window !== 'undefined' ? window : this);