Skip to content

Commit

Permalink
111
Browse files Browse the repository at this point in the history
  • Loading branch information
RubyLouvre committed Jun 15, 2013
1 parent a6d9e54 commit 2da64d3
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 16 deletions.
2 changes: 1 addition & 1 deletion doc/scripts/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ define("api", ["mass"], function() {
data: ["data", "parseData", "removeData", "mergeData"],
css: "fn.css, fn.width, fn.height, fn.innerWidth, fn.innerHeight, fn.outerWidth, fn.outerHeight, fn.offset, fn.position, fn.offsetParent, fn.scrollParent, fn.scrollTop, fn.scrollLeft, css".match($.rword).sort(),
attr: "fn.addClass, fn.hasClass, fn.removeClass, fn.toggleClass, fn.replaceClass, fn.val, fn.removeAttr, fn.removeProp, fn.attr, fn.prop, attr, prop".match($.rword).sort(),
event: ("fn.on,fn.bind,fn.off,fn.unbind,fn.delegate,fn.live,Event,eventSupport" +
event: ("fn.on,fn.bind,fn.off,fn.unbind,/Users/cheng/avalon/bug.htmlfn.delegate,fn.live,Event,eventSupport" +
"fn.one,fn.undelegate,fn.die,fn.fire,fn.contextmenu,fn.click,fn.dblclick," +
"fn.mouseout,fn.mouseover,fn.mouseenter,fn.mouseleave,fn.mousemove," +
"fn.mousedown,fn.mouseup,fn.mousewheel,fn.abort,fn.error,fn.load,fn.unload," +
Expand Down
56 changes: 49 additions & 7 deletions mvvm/avalon.html.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@
avalon.define("content", function(vm) {
vm.content = "<em>这是斜体</em>这是正常"
});
var a = avalon.define("a", function(vm) {
vm.monument = [{title: "aaa", descriptions: "111", ishowDetail: true}];

})
setTimeout(function() {
a.monument = [{title: "bbb", descriptions: "222", ishowDetail: true}];
}, 2000)
avalon.scan()
})

Expand All @@ -53,7 +60,7 @@ <h1>ms-html与{{}}</h1>
<p><a href="http://rubylouvre.github.io/mvvm/">返回首页</a></p>
<p>avalon拥有三种填空数据的功能。</p>
<p>我们看下面的例子:</p>
<div ms-skip>
<filedset ms-skip><legend>例子1</legend>
<h3>HTML结构</h3>
<pre class="brush:html;gutter:false;toolbar:false">
&lt;div ms-controller="content"&gt;
Expand All @@ -71,12 +78,47 @@ <h3>JS</h3>
avalon.scan()
})
</pre>
</div>
<div ms-controller="content">
<p ms-html="content"></p>
<p>{{content}}</p>
<div><b>不影响其他节点</b>{{content|html}}</div>
</div>
<div ms-controller="content">
<p ms-html="content"></p>
<p>{{content}}</p>
<div><b>不影响其他节点</b>{{content|html}}</div>
</div>
</filedset>
<filedset ms-skip><legend>例子2</legend>
<h3>HTML结构</h3>
<pre class="brush:html;gutter:false;toolbar:false">
&lt;div ms-controller="a"&gt;
&lt;div ms-each-md="monument" &gt;
&lt;div &gt;
&lt;h2&gt;{{md.title}}&lt;/h2&gt;

&lt;p ms-visible="md.ishowDetail" ms-html="md.descriptions"&gt;&lt;/p&gt;&lt;!-- 使用ms-html --&gt;
&lt;p ms-visible="md.ishowDetail"&gt;{{md.descriptions|html}}&lt;/p&gt; &lt;!-- 直接插入 --&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</pre>
<h3>JS</h3>
<pre class="brush:js;gutter:false;toolbar:false">
var a = avalon.define("a", function(vm) {
vm.monument = [{title: "aaa", descriptions: "111", ishowDetail: true}];

})
setTimeout(function() {
a.monument = [{title: "bbb", descriptions: "222", ishowDetail: true}];
}, 2000)
</pre>
<div ms-controller="a">
<div ms-each-md="monument" >
<div>
<h2>{{md.title}}</h2>

<p ms-visible="md.ishowDetail" ms-html="md.descriptions"></p><!-- 使用ms-html -->
<p ms-visible="md.ishowDetail">{{md.descriptions|html}}</p> <!-- 直接插入 -->
</div>
</div>
</div>
</filedset>
<br/>
<br/>
<br/>
Expand Down
23 changes: 15 additions & 8 deletions mvvm/javascripts/avalon2.js
Original file line number Diff line number Diff line change
Expand Up @@ -566,8 +566,8 @@
// 把滚动距离加到left,top中去。
// IE一些版本中会自动为HTML元素加上2px的border,我们需要去掉它
// http://msdn.microsoft.com/en-us/library/ms533564(VS.85).aspx
pos.top = box.top + scrollTop - clientTop,
pos.left = box.left + scrollLeft - clientLeft
pos.top = box.top + scrollTop - clientTop
pos.left = box.left + scrollLeft - clientLeft
return pos
}
//=============================val相关=======================
Expand Down Expand Up @@ -1196,7 +1196,7 @@
elem.removeAttribute(prefix + "controller")
}
scanAttr(elem, scopes) //扫描特点节点
if ( !stopScan[elem.tagName] && regbind.test(elem.innerHTML)) {
if (!stopScan[elem.tagName] && regbind.test(elem.innerHTML)) {
var textNodes = []
var nodes = elem.childNodes
for (var i = 0, node; node = nodes[i++]; ) {
Expand Down Expand Up @@ -1331,7 +1331,7 @@
if (filters && filters.indexOf("html") !== -1) {
avalon.Array.remove(filters, "html")
binding.type = "html"
binding.replace = true
binding.replaceNodes = [node]
}
bindings.push(binding) //收集带有插值表达式的文本
}
Expand Down Expand Up @@ -1691,13 +1691,20 @@
"html": function(data, vmodels) {
watchView(data.value, vmodels, data, function(val, elem) {
val = val == null ? "" : val + ""
if (data.replace) {
if (data.replaceNodes) {
domParser.innerHTML = val
var replaceNodes = []
while (domParser.firstChild) {
documentFragment.appendChild(domParser.firstChild)
replaceNodes.push(domParser.firstChild)
documentFragment.appendChild(domParser.firstChild)
}
elem.replaceChild(documentFragment, data.node)
} else {
elem.insertBefore(documentFragment, data.replaceNodes[0]);
for(var i = 0, node ; node = data.replaceNodes[i++];){
elem.removeChild(node)
}
data.replaceNodes = replaceNodes

}else{
elem.innerHTML = val
}
})
Expand Down

0 comments on commit 2da64d3

Please sign in to comment.