This repository has been archived on 2023-08-29. You can view files and clone it, but cannot push or open issues/pull-requests.
yutent
/
anot.js
Archived
1
0
Fork 0

微调组件slot机制

1.x 1.0.5
宇天 2018-10-23 11:45:34 +08:00
parent 19ccdff478
commit b5a9ef0695
3 changed files with 18 additions and 6 deletions

View File

@ -1,6 +1,6 @@
{
"name": "anot",
"version": "1.0.4",
"version": "1.0.5",
"description": "Anot - 迷你mvvm框架",
"main": "dist/anot.js",
"files": [

View File

@ -12,7 +12,7 @@ var DOC = window.document
var head = DOC.head //HEAD元素
head.insertAdjacentHTML(
'afterBegin',
'<anot skip class="anot-hide"><style id="anot-style">.anot-hide{ display: none!important }</style></anot>'
'<anot skip class="anot-hide"><style id="anot-style">.anot-hide{ display: none!important } slot{visibility:hidden;}</style></anot>'
)
var ifGroup = head.firstChild

View File

@ -17,12 +17,24 @@ function parseSlot(collections, vms) {
arr.forEach(function(elem) {
switch (elem.nodeType) {
case 1:
var slot = elem.getAttribute('slot')
var isSlotTag = elem.tagName === 'SLOT'
var slotKey = null
var isSlotAttr = elem.getAttribute('slot')
if (slot) {
obj[slot] = obj[slot] || []
if (isSlotTag) {
slotKey = elem.name || elem.getAttribute('name')
} else if (isSlotAttr) {
slotKey = isSlotAttr
}
if (slotKey) {
obj[slotKey] = obj[slotKey] || []
elem.removeAttribute('slot')
obj[slot].push(elem.outerHTML)
if (isSlotTag) {
obj[slotKey].push(elem.innerHTML)
} else {
obj[slotKey].push(elem.outerHTML)
}
} else {
var txt = elem.outerHTML
if (isWidget(elem) || /:[\w-]*=".*"/.test(txt)) {