Skip to content

Commit

Permalink
Merge branch 'master' of github.com:RubyLouvre/avalon
Browse files Browse the repository at this point in the history
  • Loading branch information
RubyLouvre committed Nov 18, 2014
2 parents 07a2644 + beec4b0 commit 0284b2b
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 13 deletions.
10 changes: 10 additions & 0 deletions avalon.js
Original file line number Diff line number Diff line change
Expand Up @@ -1697,13 +1697,23 @@
for (els = wrapper["getElementsByTagName"]("br"), i = 0; el = els[i++]; ) {
if (el.className && el.className === "msNoScope") {
el.parentNode.removeChild(el)
i--
}
}
for (els = wrapper.all, i = 0; el = els[i++]; ) { //fix VML
if (isVML(el)) {
fixVML(el)
}
}
if (tag === "tr") {
for (els = wrapper.children, i = 0; el = els[i++]; ) {
// IE6-8,如果动态生成tr元素,必须会在后面添加早已废弃caption的标签,其nodeName,innerHTML都为""
if (el.nodeName == "") {
el.parentNode.removeChild(el)
i--
}
}
}
}
while (firstChild = wrapper.firstChild) { // 将wrapper上的节点转移到文档碎片上!
fragment.appendChild(firstChild)
Expand Down
16 changes: 8 additions & 8 deletions avalon.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 33 additions & 4 deletions avalon.observe.js
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@
var node = this[0]
if (arguments.length === 0) {
if (node.setTimeout) { //取得窗口尺寸,IE9后可以用node.innerWidth /innerHeight代替
return node["inner" + name]
return node["inner" + name]
}
if (node.nodeType === 9) { //取得页面尺寸
var doc = node.documentElement
Expand Down Expand Up @@ -956,9 +956,38 @@
* HTML处理(parseHTML, innerHTML, clearHTML) *
****************************************************************************/
!function(t) {
var rtagName = /<([\w:]+)/
var rxhtml = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig

var tagHooks = {
col: [2, "<table><tbody></tbody><colgroup>", "</colgroup></table>"],
g: [1, '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1">', '</svg>'],
//IE6-8在用innerHTML生成节点时,不能直接创建no-scope元素与HTML5的新标签
_default: [0, "", ""] //div可以不用闭合
}


String("circle,defs,ellipse,image,line,path,polygon,polyline,rect,symbol,text,use").replace(rword, function(tag) {
tagHooks[tag] = tagHooks.g //处理SVG
})

avalon.parseHTML = function(html) {
t.innerHTML = html + ""
return t.content
html = html.replace(rxhtml, "<$1></$2>").trim()
var tag = (rtagName.exec(html) || ["", ""])[1].toLowerCase()
var wrap = tagHooks[tag] || tagHooks._default
t.innerHTML = wrap[1] + html + wrap[2]
var wrapper = t.content
if (wrap[0]) {
console.log(wrapper)
// var fragment = wrapper.cloneNode(false), firstChild
// for (var i = wrap[0]; i--; wrapper = wrapper.lastChild) {
// }
// while (firstChild = wrapper.firstChild) { // 将wrapper上的节点转移到文档碎片上!
// fragment.appendChild(firstChild)
// }
// return fragment
}
return wrapper
}
avalon.clearHTML = function(node) {
node.textContent = ""
Expand Down Expand Up @@ -1005,7 +1034,7 @@
}
return this
},
$fire: function(type) {
$fire: function(type) {
var special
if (/^(\w+)!(\S+)$/.test(type)) {
special = RegExp.$1
Expand Down
10 changes: 9 additions & 1 deletion examples/avalon.shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -1694,7 +1694,7 @@
for (i = wrap[0]; i--; wrapper = wrapper.lastChild) {
}
if (!W3C) { //fix IE
for (els = wrapper["getElementsByTagName"]("br"), i = 0; el = els[i++]; ) {
for (els = avalon.slice(wrapper["getElementsByTagName"]("br")), i = 0; el = els[i++]; ) {
if (el.className && el.className === "msNoScope") {
el.parentNode.removeChild(el)
}
Expand All @@ -1704,6 +1704,14 @@
fixVML(el)
}
}
if (tag === "tr") {
for (els = avalon.slice(wrapper.children), i = 0; el = els[i++]; ) {
// IE6-8,如果动态生成tr元素,必须会在后面添加早已废弃caption的标签,其nodeName,innerHTML都为""
if (el.nodeName == "") {
el.parentNode.removeChild(el)
}
}
}
}
while (firstChild = wrapper.firstChild) { // 将wrapper上的节点转移到文档碎片上!
fragment.appendChild(firstChild)
Expand Down
31 changes: 31 additions & 0 deletions newhtml1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<script src='avalon.observe.js'></script>
<script>
window.onload = function() {
var node = avalon.parseHTML("<script>alert(1)<\/script>")
document.body.appendChild(node)

var g = '<g stroke="green" fill="white" stroke-width="5">\
<circle cx="25" cy="25" r="15" />\
<circle cx="40" cy="25" r="15" />\
<circle cx="55" cy="25" r="15" />\
<circle cx="70" cy="25" r="15" />\
</g>'
var node = avalon.parseHTML(g)
console.log(node)
var el = avalon.parseHTML("<col width=120><tr><td></td></tr>")
console.log(el)
}

//console.log(wrapper)
</script>
</head>
<body>
<div>TODO write content</div>
</body>
</html>

0 comments on commit 0284b2b

Please sign in to comment.