代码拉取完成,页面将自动刷新
同步操作将从 Yaohaixiao/outline.js 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
import isString from './utils/types/isString'
import isElement from './utils/types/isElement'
import createElement from './utils/dom/createElement'
import addClass from './utils/dom/addClass'
import later from './utils/lang/later'
import icon from './utils/icons/icon'
const _updateSiblingElements = (siblingElement, isPrev) => {
let tagName
let $sibling = siblingElement
while ($sibling) {
tagName = $sibling.tagName.toLowerCase()
if (tagName !== 'script' && tagName !== 'style') {
addClass($sibling, 'outline-print_sibling')
}
if (isPrev) {
$sibling = $sibling.previousElementSibling
} else {
$sibling = $sibling.nextElementSibling
}
}
}
const paintPrint = (el, title) => {
const $fragment = document.createDocumentFragment()
let text = title
let $el
let $wrapper
let $article
let $title
let $sibling
let $icon
let $children
if (isString(el)) {
$el = document.querySelector(el)
} else if (isElement(el)) {
$el = el
}
if (!$el) {
return false
}
$icon = icon('close', {
iconSet: 'outline',
size: 20,
attrs: {
className: 'outline-print__close'
}
})
$title = $el.querySelector('h1')
if (isElement(title)) {
$title = title
}
if (isElement($title)) {
text = $title.innerText
}
$title = createElement(
'h1',
{
className: 'outline-print__title'
},
text
)
$article = createElement('article', {
id: 'outline-print__article',
className: 'outline-print__article'
})
$wrapper = createElement(
'section',
{
id: 'outline-print',
className: 'outline-print'
},
[$icon, $title, $article]
)
document.body.appendChild($wrapper)
later(() => {
// 设置邻居节点的打印样式
$sibling = $wrapper.previousElementSibling
_updateSiblingElements($sibling, true)
$sibling = $wrapper.nextElementSibling
_updateSiblingElements($sibling)
// 克隆文章内容
$children = [...$el.cloneNode(true).children]
$children.forEach(($child) => {
$fragment.appendChild($child)
})
$article.appendChild($fragment)
})
}
export default paintPrint
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。