From b375083d9628c6af7b07eb66116e54d358ed68d7 Mon Sep 17 00:00:00 2001 From: qincheng Date: Tue, 18 Nov 2014 02:05:43 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8DIE6-8=E4=B8=8B=E5=8A=A8?= =?UTF-8?q?=E6=80=81=E7=94=9F=E6=88=90tr=E5=85=83=E7=B4=A0=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E6=B5=8F=E8=A7=88=E5=99=A8=E7=A7=81=E8=87=AA=E6=8F=92?= =?UTF-8?q?=E5=85=A5caption=E5=85=83=E7=B4=A0=EF=BC=8C=E5=AF=BC=E8=87=B4lo?= =?UTF-8?q?cateFragment=E6=96=B9=E6=B3=95=E8=AE=A1=E7=AE=97=E5=87=BA?= =?UTF-8?q?=E9=94=99=E7=9A=84BUG=20fix=20https://github.com/RubyLouvre/ava?= =?UTF-8?q?lon/issues/572?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- avalon.js | 10 +++++++++- avalon.min.js | 23 ++++++++++++----------- examples/avalon.shim.js | 10 +++++++++- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/avalon.js b/avalon.js index a71360294..85a1a07ea 100644 --- a/avalon.js +++ b/avalon.js @@ -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) } @@ -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) diff --git a/avalon.min.js b/avalon.min.js index e03bf4959..133256655 100644 --- a/avalon.min.js +++ b/avalon.min.js @@ -60,17 +60,18 @@ b]=function(b){return x[c+":get"](this[0],void 0,!0===b?2:0)}});avalon.fn.offset return{top:c.top+h-b,left:c.left+e-g}};var Pc=/^]+))?)*\s+value[\s=]/i,Ka={"option:get":r.VBArray?function(b){return Pc.test(b.outerHTML)?b.value:b.text.trim()}:function(b){return b.value},"select:get":function(b,c){for(var d,e=b.options,f=b.selectedIndex,g=Ka["option:get"],h="select-one"===b.type||0>f,k=h?null:[],l=h?f+1:e.length,m=0>f?l:h?f:0;m"],param:[1,""],col:[2,"","
"],legend:[1,"
"],option:[1,""],thead:[1,"","
"],tr:[2,""],td:[3,"
"],g:[1,'',""],_default:w? [0,""]:[1,"X
"]};E.optgroup=E.option;E.tbody=E.tfoot=E.colgroup=E.caption=E.thead;E.th=E.td;"circle,defs,ellipse,image,line,path,polygon,polyline,rect,symbol,text,use".replace(z,function(b){E[b]=E.g});var Qc=/<([\w:]+)/,Rc=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,Pb=w?/[^\d\D]/:/(<(?:script|link|style|meta|noscript))/ig,Sc=M(["","text/javascript","text/ecmascript","application/ecmascript","application/javascript"]),Tc=/<(?:tb|td|tf|th|tr|col|opt|leg|cap|area)/, Uc=p.createElement("script");avalon.parseHTML=function(b){"string"!==typeof b&&(b+="");b=b.replace(Rc,"<$1>").trim();var c=(Qc.exec(b)||["",""])[1].toLowerCase(),d=E[c]||E._default,e=I.cloneNode(!1),f=ea,g;w||(b=b.replace(Pb,"
$1"));f.innerHTML=d[1]+b+(d[2]||"");b=f.getElementsByTagName("script");if(b.length)for(var h=0,k;k=b[h++];)Sc[k.type]&&(g=Uc.cloneNode(!1),L.forEach.call(k.attributes,function(b){b&&b.specified&&(g[b.name]=b.value,g.setAttribute(b.name,b.value))}),g.text= -k.text,k.parentNode.replaceChild(g,k));for(h=d[0];h--;f=f.lastChild);if(!w){b=avalon.slice(f.getElementsByTagName("br"));for(h=0;k=b[h++];)k.className&&"msNoScope"===k.className&&k.parentNode.removeChild(k);b=f.all;for(h=0;k=b[h++];)fb(k)&&ac(k);if("tr"===c){b=avalon.slice(f.children);for(h=0;k=b[h++];)""==k.nodeName&&k.parentNode.removeChild(k)}}for(;c=f.firstChild;)e.appendChild(c);return e};avalon.innerHTML=function(b,c){if(!w&&!Pb.test(c)&&!Tc.test(c))try{b.innerHTML=c;return}catch(d){}var e= -this.parseHTML(c);this.clearHTML(b).appendChild(e)};avalon.clearHTML=function(b){for(b.textContent="";b.firstChild;)b.removeChild(b.firstChild);return b};var R={$watch:function(b,c){if("function"===typeof c){var d=this.$events[b];d?d.push(c):this.$events[b]=[c]}else this.$events=this.$watch.backup;return this},$unwatch:function(b,c){var d=arguments.length;if(0===d)this.$watch.backup=this.$events,this.$events={};else if(1===d)this.$events[b]=[];else for(var d=this.$events[b]||[],e=d.length;0>~--e;)if(d[e]=== -c)return d.splice(e,1);return this},$fire:function(b){var c;/^(\w+)!(\S+)$/.test(b)&&(c=RegExp.$1,b=RegExp.$2);var d=this.$events,e=$.call(arguments,1),f=[b].concat(e);if("all"===c)for(var g in avalon.vmodels)e=avalon.vmodels[g],e!==this&&e.$fire.apply(e,f);else if("up"===c||"down"===c){if(d=d.expr&&Qb(d.expr)){for(g in avalon.vmodels)if(e=avalon.vmodels[g],e!==this&&e.$events.expr){var h=Qb(e.$events.expr);if(h&&("down"===c?d.contains(h):h.contains(d)))h._avalon=e}g=p.getElementsByTagName("*");var k= -[];Array.prototype.forEach.call(g,function(b){b._avalon&&(k.push(b._avalon),b._avalon="",b.removeAttribute("_avalon"))});"up"===c&&k.reverse();for(g=0;(c=k[g++])&&!1!==c.$fire.apply(c,f););}}else{f=d[b]||[];c=d.$all||[];for(g=0;d=f[g++];)V(d)&&d.apply(this,e);for(g=0;d=c[g++];)V(d)&&d.apply(this,arguments)}}},Vc=/(\w+)\[(avalonctrl)="(\S+)"\]/,Qb=p.querySelector?function(b){return p.querySelector(b)}:function(b){b=b.match(Vc);for(var c=p.getElementsByTagName(b[1]),d=0,e;e=c[d++];)if(e.getAttribute(b[2])=== -b[3])return e},bc=/^(duplex|on)$/,S=[],ya=0,cc=200,ib=new Date,jb,Na={};avalon.scanCallback=function(b,c){c=c||"$all";(Na[c]||(Na[c]=[])).push(b)};avalon.scan=function(b,c,d){b=b||B;var e=Na[d||"$all"]||[];c=c?[].concat(c):[];var f=0,g=!1,h,k=!1;c.cb=function(b){f+=b;k=!0;setTimeout(function(){if(0>=f&&!g)for(g=!0;h=e.shift();)h()})};kb(b,c);if(!k)for(;h=e.shift();)h()};var gc=M("AREA,BASE,BASEFONT,BR,COL,COMMAND,EMBED,HR,IMG,INPUT,LINK,META,PARAM,SOURCE,TRACK,WBR,NOSCRIPT,SCRIPT,STYLE,TEXTAREA"), -sb=/ms-(\w+)-?(.*)/,tb={"if":10,repeat:90,data:100,widget:110,each:1400,"with":1500,duplex:2E3,on:3E3},ec=M("animationend,blur,change,input,click,dblclick,focus,keydown,keypress,keyup,mousedown,mouseenter,mouseleave,mousemove,mouseout,mouseover,mouseup,scan,scroll,submit"),fc=M("value,title,alt,checked,selected,disabled,readonly,enabled");if(!"1"[0])var Oa=Ca(512),Wc=/\s+(ms-[^=\s]+)(?:=("[^"]*"|'[^']*'|[^\s>]+))?/g,Xc=/^['"]/,Yc=/<\w+\b(?:(["'])[^"]*?(\1)|[^>])*>/i,Zc=/&/g,rb=function(b){b=b.outerHTML; -if(".avalonHide{ display: none!important }"; -var fd=/(?:[\s\S]+?)<\/noscript>/img,gd=/([\s\S]+?)<\/noscript>/im,Ra=function(){return new (r.XMLHttpRequest||ActiveXObject)("Microsoft.XMLHTTP")},fa=function(b,c,d){if(b=b.getAttribute(c)){c=0;for(var e;e=d[c++];)if(e.hasOwnProperty(b)&&"function"===typeof e[b])return e[b]}},Sa=avalon.templateCache={};avalon.contains=Ya;var Ta={};"autofocus,autoplay,async,allowTransparency,checked,controls,declare,disabled,defer,defaultChecked,defaultSelectedcontentEditable,isMap,loop,multiple,noHref,noResize,noShade,open,readOnly,selected".replace(z, +k.text,k.parentNode.replaceChild(g,k));for(h=d[0];h--;f=f.lastChild);if(!w){b=f.getElementsByTagName("br");for(h=0;k=b[h++];)k.className&&"msNoScope"===k.className&&(k.parentNode.removeChild(k),h--);b=f.all;for(h=0;k=b[h++];)fb(k)&&ac(k);if("tr"===c){b=f.children;for(h=0;k=b[h++];)""==k.nodeName&&(k.parentNode.removeChild(k),h--)}}for(;c=f.firstChild;)e.appendChild(c);return e};avalon.innerHTML=function(b,c){if(!w&&!Pb.test(c)&&!Tc.test(c))try{b.innerHTML=c;return}catch(d){}var e=this.parseHTML(c); +this.clearHTML(b).appendChild(e)};avalon.clearHTML=function(b){for(b.textContent="";b.firstChild;)b.removeChild(b.firstChild);return b};var R={$watch:function(b,c){if("function"===typeof c){var d=this.$events[b];d?d.push(c):this.$events[b]=[c]}else this.$events=this.$watch.backup;return this},$unwatch:function(b,c){var d=arguments.length;if(0===d)this.$watch.backup=this.$events,this.$events={};else if(1===d)this.$events[b]=[];else for(var d=this.$events[b]||[],e=d.length;0>~--e;)if(d[e]===c)return d.splice(e, +1);return this},$fire:function(b){var c;/^(\w+)!(\S+)$/.test(b)&&(c=RegExp.$1,b=RegExp.$2);var d=this.$events,e=$.call(arguments,1),f=[b].concat(e);if("all"===c)for(var g in avalon.vmodels)e=avalon.vmodels[g],e!==this&&e.$fire.apply(e,f);else if("up"===c||"down"===c){if(d=d.expr&&Qb(d.expr)){for(g in avalon.vmodels)if(e=avalon.vmodels[g],e!==this&&e.$events.expr){var h=Qb(e.$events.expr);if(h&&("down"===c?d.contains(h):h.contains(d)))h._avalon=e}g=p.getElementsByTagName("*");var k=[];Array.prototype.forEach.call(g, +function(b){b._avalon&&(k.push(b._avalon),b._avalon="",b.removeAttribute("_avalon"))});"up"===c&&k.reverse();for(g=0;(c=k[g++])&&!1!==c.$fire.apply(c,f););}}else{f=d[b]||[];c=d.$all||[];for(g=0;d=f[g++];)V(d)&&d.apply(this,e);for(g=0;d=c[g++];)V(d)&&d.apply(this,arguments)}}},Vc=/(\w+)\[(avalonctrl)="(\S+)"\]/,Qb=p.querySelector?function(b){return p.querySelector(b)}:function(b){b=b.match(Vc);for(var c=p.getElementsByTagName(b[1]),d=0,e;e=c[d++];)if(e.getAttribute(b[2])===b[3])return e},bc=/^(duplex|on)$/, +S=[],ya=0,cc=200,ib=new Date,jb,Na={};avalon.scanCallback=function(b,c){c=c||"$all";(Na[c]||(Na[c]=[])).push(b)};avalon.scan=function(b,c,d){b=b||B;var e=Na[d||"$all"]||[];c=c?[].concat(c):[];var f=0,g=!1,h,k=!1;c.cb=function(b){f+=b;k=!0;setTimeout(function(){if(0>=f&&!g)for(g=!0;h=e.shift();)h()})};kb(b,c);if(!k)for(;h=e.shift();)h()};var gc=M("AREA,BASE,BASEFONT,BR,COL,COMMAND,EMBED,HR,IMG,INPUT,LINK,META,PARAM,SOURCE,TRACK,WBR,NOSCRIPT,SCRIPT,STYLE,TEXTAREA"),sb=/ms-(\w+)-?(.*)/,tb={"if":10,repeat:90, +data:100,widget:110,each:1400,"with":1500,duplex:2E3,on:3E3},ec=M("animationend,blur,change,input,click,dblclick,focus,keydown,keypress,keyup,mousedown,mouseenter,mouseleave,mousemove,mouseout,mouseover,mouseup,scan,scroll,submit"),fc=M("value,title,alt,checked,selected,disabled,readonly,enabled");if(!"1"[0])var Oa=Ca(512),Wc=/\s+(ms-[^=\s]+)(?:=("[^"]*"|'[^']*'|[^\s>]+))?/g,Xc=/^['"]/,Yc=/<\w+\b(?:(["'])[^"]*?(\1)|[^>])*>/i,Zc=/&/g,rb=function(b){b=b.outerHTML;if(".avalonHide{ display: none!important }";var fd=/(?:[\s\S]+?)<\/noscript>/img,gd=/([\s\S]+?)<\/noscript>/im,Ra=function(){return new (r.XMLHttpRequest||ActiveXObject)("Microsoft.XMLHTTP")},fa=function(b,c,d){if(b=b.getAttribute(c)){c=0;for(var e;e=d[c++];)if(e.hasOwnProperty(b)&&"function"===typeof e[b])return e[b]}},Sa=avalon.templateCache={};avalon.contains=Ya;var Ta={};"autofocus,autoplay,async,allowTransparency,checked,controls,declare,disabled,defer,defaultChecked,defaultSelectedcontentEditable,isMap,loop,multiple,noHref,noResize,noShade,open,readOnly,selected".replace(z, function(b){Ta[b.toLowerCase()]=b});var Ea=avalon.bindingExecutors={attr:function(b,c,d){var e=d.type,f=d.param;if("css"===e)avalon(c).css(f,b);else if("attr"===e){if(Ta[f]&&(e=Ta[f],"boolean"===typeof c[e]))return c[e]=!!b;!w&&Qa[f]&&(f=Qa[f]);if(!1===b||null===b||void 0===b)return c.removeAttribute(f);(Hb.test(c)?0:p.namespaces&&fb(c)||f in c.cloneNode(!1))?c[f]=b:c.setAttribute(f,b)}else if("include"===e&&b){var g=d.vmodels,h=d.includeRendered,k=d.includeLoaded,l=d.includeReplaced?c.parentNode: c;g.cb(1);var m=function(b){k&&(b=k.apply(l,[b].concat(g)));h&&avalon.scanCallback(function(){h.call(l)});for(avalon.scan(l);;){var c=d.startInclude.nextSibling;if(c&&c!==d.endInclude)l.removeChild(c);else break}b=avalon.parseHTML(b);c=avalon.slice(b.childNodes);l.insertBefore(b,d.endInclude);za(c,g);g.cb(-1)};if("src"===d.param)if(Sa[b])avalon.nextTick(function(){m(Sa[b])});else{var n=Ra();n.onreadystatechange=function(){if(4===n.readyState){var c=n.status;if(200<=c&&300>c||304===c||1223===c)m(Sa[b]= n.responseText)}};n.open("GET",b,!0);"withCredentials"in n&&(n.withCredentials=!0);n.setRequestHeader("X-Requested-With","XMLHttpRequest");n.send(null)}else{var q=b&&1===b.nodeType?b:p.getElementById(b);if(q){if("NOSCRIPT"===q.tagName&&!q.innerHTML&&!q.fixIE78){n=Ra();n.open("GET",location,!1);n.send(null);c=p.getElementsByTagName("noscript");for(var f=(n.responseText||"").match(fd)||[],e=f.length,t=0;t Date: Tue, 18 Nov 2014 09:53:35 +0800 Subject: [PATCH 3/3] update avalon.observe --- avalon.observe.js | 37 +++++++++++++++++++++++++++++++++---- newhtml1.html | 31 +++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 newhtml1.html diff --git a/avalon.observe.js b/avalon.observe.js index 1cff29105..d639cd18e 100644 --- a/avalon.observe.js +++ b/avalon.observe.js @@ -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 @@ -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, "
", "
"], + g: [1, '', ''], + //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>").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 = "" @@ -1005,7 +1034,7 @@ } return this }, - $fire: function(type) { + $fire: function(type) { var special if (/^(\w+)!(\S+)$/.test(type)) { special = RegExp.$1 diff --git a/newhtml1.html b/newhtml1.html new file mode 100644 index 000000000..e394a0563 --- /dev/null +++ b/newhtml1.html @@ -0,0 +1,31 @@ + + + + TODO supply a title + + + + + + +
TODO write content
+ +