1 Star 0 Fork 34

guopj2014/outline.js

forked from Yaohaixiao/outline.js 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
print.js 2.02 KB
一键复制 编辑 原始数据 按行查看 历史
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 print = (origins, title) => {
let text = title
let $origins
let $wrapper
let $article
let $title
let $sibling
let $icon
if (isString(origins)) {
$origins =
document.querySelector(origins) || document.getElementById(origins)
} else {
if (isElement(origins)) {
$origins = origins
}
}
$icon = icon('close', {
iconSet: 'outline',
size: 20
})
addClass($icon, 'outline-print__close')
$title = $origins.querySelector('h1')
if (isElement(title)) {
$title = title
}
if (isElement($title)) {
text = $title.innerText
}
$article = createElement('article', {
id: 'outline-print__article',
className: 'outline-print__article'
})
$article.innerHTML = $origins.innerHTML
$title = createElement(
'h1',
{
className: 'outline-print__title'
},
text
)
$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)
}, 350)
}
export default print
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/guopj/outline.js.git
git@gitee.com:guopj/outline.js.git
guopj
outline.js
outline.js
master

搜索帮助