3 Star 54 Fork 14

Yaohaixiao / dom.js

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
fragment.js 1.08 KB
一键复制 编辑 原始数据 按行查看 历史
import isHTML from './utils/types/isHTML'
import isCollection from './isCollection'
import isElement from './isElement'
import isText from './isText'
import html from './html'
/**
* 创建文档碎片
* ========================================================================
* @method fragment
* @since 1.7.0
* @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/createDocumentFragment
* @param {String|HTMLElement|HTMLCollection|Text} [innerContent]
* @returns {DocumentFragment}
*/
const fragment = (innerContent) => {
const $fragment = document.createDocumentFragment()
let $children = []
let collection = []
if (isHTML(innerContent)) {
$children = [html(innerContent)]
} else if (isElement(innerContent) || isText(innerContent)) {
$children = [innerContent]
} else if (isCollection(innerContent)) {
collection = [...innerContent]
collection.forEach((child) => {
$children.push(child)
})
}
if ($children.length > 0) {
$children.forEach((child) => {
$children.push(child)
})
}
return $fragment
}
export default fragment
JavaScript
1
https://gitee.com/yaohaixiao/dom.js.git
git@gitee.com:yaohaixiao/dom.js.git
yaohaixiao
dom.js
dom.js
main

搜索帮助