Skip to content

Commit

Permalink
commonRange改名为更语义化的cachedRange
Browse files Browse the repository at this point in the history
  • Loading branch information
RubyLouvre committed Mar 6, 2013
1 parent 5a72545 commit a866946
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 45 deletions.
84 changes: 45 additions & 39 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,60 @@
<html>
<head>
<title></title>
<link href="aa" type="text/css" rel="stylesheet" charset="utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>测试</title>
<style>

</style>
<script src="mass.js"></script>
<script src="mass.js"></script>
<script>
require("class,node", function($) {

var Animal = $.factory({
init: function(name) {
this.name = name
},
getName: function() {
return this.name;
},
setName: function(name) {
this.name = name;
}
});

var a = new Animal("zzz");
var Dog = $.factory(Animal, {
init: function(name, age) {
this.age = age;
},
getAge: function() {
return this.age;
},
setAge: function(age) {
this.age = age;
}
});

var dog = new Dog("dog",222);

console.log(a);
console.log(dog)

})
window.onload = function() {
var div = document.createElement("div");
  div.innerHTML = '<table><tbody><tr></tr></tbody></table>';
//  alert(div.getElementsByTagName("tr").length); 
// div.innerHTML = '<table><tbody><tr></tr>'; 
// alert(div.getElementsByTagName("tr").length);
var a = document.body.insertAdjacentHTML("afterBegin", "<div>6666666</div>");
console.log(a)
}
</script>
</head>

<body>

<button onclick="">Test</button>
<a href="aaa">司徒正美</a>
<div class="aaa bbb" >
1111111
</div>
<div>
2222222222
</div >
<div>
33333333
</div>
<div>
4444444444
</div>
<div>
555555555
</div>
<div>
6666666666666
</div>
<div>
77777777
</div>
<div>
888888888
</div>
<div>
999999
</div>
<div>
10
</div>
<div>
11
</div>
</body>


</html>
6 changes: 3 additions & 3 deletions node.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ define("node", ["support", "class", "query", "data"].concat(top.dispatchEvent ?
html = html.replace(rxhtml, "<$1></$2>").trim();
//尝试使用createContextualFragment获取更高的效率
//http://www.cnblogs.com/rubylouvre/archive/2011/04/15/2016800.html
if($.commonRange && doc === document && !rcreate.test(html) && !rnest.test(html)) {
return $.commonRange.createContextualFragment(html);
if($.cachedRange && doc === document && !rcreate.test(html) && !rnest.test(html)) {
return $.cachedRange.createContextualFragment(html);
}
if($.support.noscope) { //fix IE
html = html.replace(rcreate, "<br class='fix_create_all'/>$1"); //在link style script等标签之前添加一个补丁
Expand Down Expand Up @@ -359,7 +359,7 @@ define("node", ["support", "class", "query", "data"].concat(top.dispatchEvent ?
thead: [1, "<table>", "</table>"],
tr: [2, "<table><tbody>"],
td: [3, "<table><tbody><tr>"],
//IE678在用innerHTML生成节点时存在BUG,不能直接创建script,link,meta,style与HTML5的新标签
//IE6-8在用innerHTML生成节点时,不能直接创建no-scope元素与HTML5的新标签
_default: $.support.noscope? [1, "X<div>"] :[0, ""] //div可以不用闭合
},
insertHooks = {
Expand Down
4 changes: 2 additions & 2 deletions node_neo.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ define("node", ["support", "class", "query", "data"], function($) {
html = html.replace(rxhtml, "<$1></$2>").trim();
//尝试使用createContextualFragment获取更高的效率
//http://www.cnblogs.com/rubylouvre/archive/2011/04/15/2016800.html
if ($.commonRange && doc === document && !rnest.test(html)) {
return $.commonRange.createContextualFragment(html);
if ($.cachedRange && doc === document && !rnest.test(html)) {
return $.cachedRange.createContextualFragment(html);
}

var tag = (rtagName.exec(html) || ["", ""])[1].toLowerCase(),
Expand Down
2 changes: 1 addition & 1 deletion support.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ define("support", ["mass"], function($) {
var range = DOC.createRange();
range.selectNodeContents(body); //fix opera(9.2~11.51) bug,必须对文档进行选取
support.fastFragment = !! range.createContextualFragment("<a>");
$.commonRange = range;
$.cachedRange = range;
} catch(e) {};
div.style.cssText = "position:absolute;top:-1000px;left:-1000px;"
body.insertBefore(div, body.firstChild);
Expand Down

0 comments on commit a866946

Please sign in to comment.