Skip to content

Commit

Permalink
fix parseHTML bug
Browse files Browse the repository at this point in the history
  • Loading branch information
RubyLouvre committed Jan 17, 2013
1 parent 728f989 commit 424caec
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 21 deletions.
29 changes: 29 additions & 0 deletions app/public/scripts/attr.js
Expand Up @@ -358,6 +358,35 @@ define("attr", !! top.getComputedStyle ? ["$node"] : ["$attr_fix"], function($)
2012.6.23 attr在value为false, null, undefined时进行删除特性操作
2012.11.6 升级v2
2012.12.24 升级到v3 添加对defaultSelected defaultChecked的处理
addClass: function(item) {
if(typeof item == "string") {
for(var i = 0, el; el = this[i++];) {
if(el.nodeType === 1) {
item.replace(rnospaces, function(clazz) {
el.classList.add(clazz);
})
}
}
}
return this;
},
//如果不传入类名,则清空所有类名,允许同时删除多个类名
removeClass: function(item) {
var removeSome = item && typeof item === "string",
removeAll = item === void 0;
for(var i = 0, node; node = this[i++];) {
if(node.nodeType === 1) {
if(removeSome && node.className) {
item.replace(rnospaces, function(clazz) {
node.classList.remove(clazz);
})
} else if(removeAll) {
node.className = "";
}
}
}
return this;
},
http://nanto.asablo.jp/blog/2005/10/29/123294
http://perl.no-tubo.net/2010/07/01/ie-%E3%81%AB%E3%81%8A%E3%81%91%E3%82%8B-setattribute-%E3%82%84-getattribute-%E3%82%84-removeattribute-%E3%81%8C%E3%81%A0%E3%82%81%E3%81%A0%E3%82%81%E3%81%AA%E4%BB%B6/
Expand Down
4 changes: 3 additions & 1 deletion app/public/scripts/event.js
Expand Up @@ -403,7 +403,7 @@ define("event", top.dispatchEvent ? ["$node"] : ["$event_fix"], function($) {
matches = [];
for(var i = 0; i < delegateCount; i++) {
handleObj = handlers[i];
sel = handleObj.selector;
sel = handleObj.selector + " ";//避免与Ovject.prototype的属性冲突,比如toString, valueOf等
//判定目标元素(this)的孩子(cur)是否匹配(sel)
if(selMatch[sel] === void 0) {
selMatch[sel] = $(sel, this).index(cur) >= 0
Expand Down Expand Up @@ -542,6 +542,8 @@ define("event", top.dispatchEvent ? ["$node"] : ["$event_fix"], function($) {
hash.times = el;
} else if(typeof el == "function") {
hash.handler = el
} else if(typeof el == "object") {
$.mix(hash, el, false);
}
if(typeof el === "string") {
if(hash.type != null) {
Expand Down
2 changes: 1 addition & 1 deletion app/public/scripts/lang.js
Expand Up @@ -152,7 +152,7 @@ define("lang", Array.isArray ? ["mass"] : ["$lang_fix"], function($) {
*/
filter: function(obj, fn, scope) {
for(var i = 0, n = obj.length, ret = []; i < n; i++) {
var val = fn.call(scope, obj[i], i);
var val = fn.call(scope||obj[i], obj[i], i);
if(val === true) {
ret[ret.length] = obj[i]
}
Expand Down
14 changes: 7 additions & 7 deletions app/public/scripts/mass_merge.js
Expand Up @@ -861,7 +861,7 @@ define("lang", Array.isArray ? ["mass"] : ["$lang_fix"], function($) {

filter: function(obj, fn, scope) {
for(var i = 0, n = obj.length, ret = []; i < n; i++) {
var val = fn.call(scope, obj[i], i);
var val = fn.call(scope||obj[i], obj[i], i);
if(val === true) {
ret[ret.length] = obj[i]
}
Expand Down Expand Up @@ -3170,7 +3170,7 @@ define("node",["$support","$class","$query","$data"].concat(top.dispatchEvent ?
rcreate = $.support.createAll ? /<(?:script)/ig : /(<(?:script|link|style))/ig,
types = $.oneObject("text/javascript", "text/ecmascript", "application/ecmascript", "application/javascript", "text/vbscript"),
//需要处理套嵌关系的标签
rnest = /<(?:td|th|tf|tr|col|opt|leg|cap|area)/,
rnest = /<(?:tb|td|tf|th|tr|col|opt|leg|cap|area)/,
adjacent = "insertAdjacentHTML",
TAGS = "getElementsByTagName"
function getDoc() {
Expand Down Expand Up @@ -3381,7 +3381,7 @@ define("node",["$support","$class","$query","$data"].concat(top.dispatchEvent ?
$.fn[method] = function(item) {
return manipulate(this, method, item, this.ownerDocument);
}
$.fn[method + "To"] = function() {
$.fn[method + "To"] = function(item) {
$(item, this.ownerDocument)[method](this);
return this;
}
Expand Down Expand Up @@ -3426,7 +3426,7 @@ define("node",["$support","$class","$query","$data"].concat(top.dispatchEvent ?
}
var matchesAPI = cssName("matchesSelector", $.html);
$.mix({
//http://www.cnblogs.com/rubylouvre/archive/2011/03/28/1998223.html
//判定元素是否支持此样式 http://www.cnblogs.com/rubylouvre/archive/2011/03/28/1998223.html
cssName: cssName,
//判定元素节点是否匹配CSS表达式
match: function(node, expr) {
Expand Down Expand Up @@ -3501,9 +3501,7 @@ define("node",["$support","$class","$query","$data"].concat(top.dispatchEvent ?
}
//移除我们为了符合套嵌关系而添加的标签
for(i = wrap[0]; i--; wrapper = wrapper.lastChild) {};

$.fixParseHTML(wrapper, html);

while(firstChild = wrapper.firstChild) { // 将wrapper上的节点转移到文档碎片上!
fragment.appendChild(firstChild);
}
Expand Down Expand Up @@ -5407,7 +5405,7 @@ define("event", top.dispatchEvent ? ["$node"] : ["$event_fix"], function($) {
matches = [];
for(var i = 0; i < delegateCount; i++) {
handleObj = handlers[i];
sel = handleObj.selector;
sel = handleObj.selector + " ";//避免与Ovject.prototype的属性冲突,比如toString, valueOf等
//判定目标元素(this)的孩子(cur)是否匹配(sel)
if(selMatch[sel] === void 0) {
selMatch[sel] = $(sel, this).index(cur) >= 0
Expand Down Expand Up @@ -5546,6 +5544,8 @@ define("event", top.dispatchEvent ? ["$node"] : ["$event_fix"], function($) {
hash.times = el;
} else if(typeof el == "function") {
hash.handler = el
} else if(typeof el == "object") {
$.mix(hash, el, false);
}
if(typeof el === "string") {
if(hash.type != null) {
Expand Down
9 changes: 4 additions & 5 deletions app/public/scripts/node.js
Expand Up @@ -9,7 +9,7 @@ define("node",["$support","$class","$query","$data"].concat(top.dispatchEvent ?
rcreate = $.support.createAll ? /<(?:script)/ig : /(<(?:script|link|style))/ig,
types = $.oneObject("text/javascript", "text/ecmascript", "application/ecmascript", "application/javascript", "text/vbscript"),
//需要处理套嵌关系的标签
rnest = /<(?:td|th|tf|tr|col|opt|leg|cap|area)/,
rnest = /<(?:tb|td|tf|th|tr|col|opt|leg|cap|area)/,
adjacent = "insertAdjacentHTML",
TAGS = "getElementsByTagName"
function getDoc() {
Expand Down Expand Up @@ -220,7 +220,7 @@ define("node",["$support","$class","$query","$data"].concat(top.dispatchEvent ?
$.fn[method] = function(item) {
return manipulate(this, method, item, this.ownerDocument);
}
$.fn[method + "To"] = function() {
$.fn[method + "To"] = function(item) {
$(item, this.ownerDocument)[method](this);
return this;
}
Expand Down Expand Up @@ -265,7 +265,7 @@ define("node",["$support","$class","$query","$data"].concat(top.dispatchEvent ?
}
var matchesAPI = cssName("matchesSelector", $.html);
$.mix({
//http://www.cnblogs.com/rubylouvre/archive/2011/03/28/1998223.html
//判定元素是否支持此样式 http://www.cnblogs.com/rubylouvre/archive/2011/03/28/1998223.html
cssName: cssName,
//判定元素节点是否匹配CSS表达式
match: function(node, expr) {
Expand Down Expand Up @@ -348,9 +348,7 @@ define("node",["$support","$class","$query","$data"].concat(top.dispatchEvent ?
}
//移除我们为了符合套嵌关系而添加的标签
for(i = wrap[0]; i--; wrapper = wrapper.lastChild) {};

$.fixParseHTML(wrapper, html);

while(firstChild = wrapper.firstChild) { // 将wrapper上的节点转移到文档碎片上!
fragment.appendChild(firstChild);
}
Expand Down Expand Up @@ -741,4 +739,5 @@ doc = this.ownerDocument = scope.ownerDocument || scope ;
2012.5.21 Remove $("body") case; $(document.body) is 2x faster.
2012.5.28 cssName支持检测mozMatchesSelector, Fix $.match BUG
2012.7.31 使用$.Array.merge代替不可靠的[].push,对cloneNode进行重构,只对元素节点进行修复
2013.1.17 修正rnest正则,防止遗漏tbody
*/
29 changes: 29 additions & 0 deletions system/mass/attr.js
Expand Up @@ -358,6 +358,35 @@ define("attr", !! top.getComputedStyle ? ["$node"] : ["$attr_fix"], function($)
2012.6.23 attr在value为false, null, undefined时进行删除特性操作
2012.11.6 升级v2
2012.12.24 升级到v3 添加对defaultSelected defaultChecked的处理
addClass: function(item) {
if(typeof item == "string") {
for(var i = 0, el; el = this[i++];) {
if(el.nodeType === 1) {
item.replace(rnospaces, function(clazz) {
el.classList.add(clazz);
})
}
}
}
return this;
},
//如果不传入类名,则清空所有类名,允许同时删除多个类名
removeClass: function(item) {
var removeSome = item && typeof item === "string",
removeAll = item === void 0;
for(var i = 0, node; node = this[i++];) {
if(node.nodeType === 1) {
if(removeSome && node.className) {
item.replace(rnospaces, function(clazz) {
node.classList.remove(clazz);
})
} else if(removeAll) {
node.className = "";
}
}
}
return this;
},
http://nanto.asablo.jp/blog/2005/10/29/123294
http://perl.no-tubo.net/2010/07/01/ie-%E3%81%AB%E3%81%8A%E3%81%91%E3%82%8B-setattribute-%E3%82%84-getattribute-%E3%82%84-removeattribute-%E3%81%8C%E3%81%A0%E3%82%81%E3%81%A0%E3%82%81%E3%81%AA%E4%BB%B6/
Expand Down
4 changes: 3 additions & 1 deletion system/mass/event.js
Expand Up @@ -403,7 +403,7 @@ define("event", top.dispatchEvent ? ["$node"] : ["$event_fix"], function($) {
matches = [];
for(var i = 0; i < delegateCount; i++) {
handleObj = handlers[i];
sel = handleObj.selector;
sel = handleObj.selector + " ";//避免与Ovject.prototype的属性冲突,比如toString, valueOf等
//判定目标元素(this)的孩子(cur)是否匹配(sel)
if(selMatch[sel] === void 0) {
selMatch[sel] = $(sel, this).index(cur) >= 0
Expand Down Expand Up @@ -542,6 +542,8 @@ define("event", top.dispatchEvent ? ["$node"] : ["$event_fix"], function($) {
hash.times = el;
} else if(typeof el == "function") {
hash.handler = el
} else if(typeof el == "object") {
$.mix(hash, el, false);
}
if(typeof el === "string") {
if(hash.type != null) {
Expand Down
2 changes: 1 addition & 1 deletion system/mass/lang.js
Expand Up @@ -152,7 +152,7 @@ define("lang", Array.isArray ? ["mass"] : ["$lang_fix"], function($) {
*/
filter: function(obj, fn, scope) {
for(var i = 0, n = obj.length, ret = []; i < n; i++) {
var val = fn.call(scope, obj[i], i);
var val = fn.call(scope||obj[i], obj[i], i);
if(val === true) {
ret[ret.length] = obj[i]
}
Expand Down
9 changes: 4 additions & 5 deletions system/mass/node.js
Expand Up @@ -9,7 +9,7 @@ define("node",["$support","$class","$query","$data"].concat(top.dispatchEvent ?
rcreate = $.support.createAll ? /<(?:script)/ig : /(<(?:script|link|style))/ig,
types = $.oneObject("text/javascript", "text/ecmascript", "application/ecmascript", "application/javascript", "text/vbscript"),
//需要处理套嵌关系的标签
rnest = /<(?:td|th|tf|tr|col|opt|leg|cap|area)/,
rnest = /<(?:tb|td|tf|th|tr|col|opt|leg|cap|area)/,
adjacent = "insertAdjacentHTML",
TAGS = "getElementsByTagName"
function getDoc() {
Expand Down Expand Up @@ -220,7 +220,7 @@ define("node",["$support","$class","$query","$data"].concat(top.dispatchEvent ?
$.fn[method] = function(item) {
return manipulate(this, method, item, this.ownerDocument);
}
$.fn[method + "To"] = function() {
$.fn[method + "To"] = function(item) {
$(item, this.ownerDocument)[method](this);
return this;
}
Expand Down Expand Up @@ -265,7 +265,7 @@ define("node",["$support","$class","$query","$data"].concat(top.dispatchEvent ?
}
var matchesAPI = cssName("matchesSelector", $.html);
$.mix({
//http://www.cnblogs.com/rubylouvre/archive/2011/03/28/1998223.html
//判定元素是否支持此样式 http://www.cnblogs.com/rubylouvre/archive/2011/03/28/1998223.html
cssName: cssName,
//判定元素节点是否匹配CSS表达式
match: function(node, expr) {
Expand Down Expand Up @@ -348,9 +348,7 @@ define("node",["$support","$class","$query","$data"].concat(top.dispatchEvent ?
}
//移除我们为了符合套嵌关系而添加的标签
for(i = wrap[0]; i--; wrapper = wrapper.lastChild) {};

$.fixParseHTML(wrapper, html);

while(firstChild = wrapper.firstChild) { // 将wrapper上的节点转移到文档碎片上!
fragment.appendChild(firstChild);
}
Expand Down Expand Up @@ -741,4 +739,5 @@ doc = this.ownerDocument = scope.ownerDocument || scope ;
2012.5.21 Remove $("body") case; $(document.body) is 2x faster.
2012.5.28 cssName支持检测mozMatchesSelector, Fix $.match BUG
2012.7.31 使用$.Array.merge代替不可靠的[].push,对cloneNode进行重构,只对元素节点进行修复
2013.1.17 修正rnest正则,防止遗漏tbody
*/

0 comments on commit 424caec

Please sign in to comment.