1
1
/*
2
- VueJS v0.7.5
2
+ VueJS v0.7.6
3
3
(c) 2014 Evan You
4
4
License: MIT
5
5
*/
@@ -603,13 +603,10 @@ var config = require('./config'),
603
603
console = window . console ,
604
604
ViewModel // late def
605
605
606
- // PhantomJS doesn't support rAF, yet it has the global
607
- // variable exposed. Use setTimeout so tests can work.
608
- var defer = navigator . userAgent . indexOf ( 'PhantomJS' ) > - 1
609
- ? window . setTimeout
610
- : ( window . webkitRequestAnimationFrame ||
611
- window . requestAnimationFrame ||
612
- window . setTimeout )
606
+ var defer =
607
+ window . requestAnimationFrame ||
608
+ window . webkitRequestAnimationFrame ||
609
+ window . setTimeout
613
610
614
611
/**
615
612
* Create a prototype-less object
@@ -1145,20 +1142,24 @@ CompilerProto.compileNode = function (node) {
1145
1142
* Compile a text node
1146
1143
*/
1147
1144
CompilerProto . compileTextNode = function ( node ) {
1145
+
1148
1146
var tokens = TextParser . parse ( node . nodeValue )
1149
1147
if ( ! tokens ) return
1150
- var el , token , directive
1148
+ var el , token , directive , partial , partialId , partialNodes
1149
+
1151
1150
for ( var i = 0 , l = tokens . length ; i < l ; i ++ ) {
1152
1151
token = tokens [ i ]
1153
1152
if ( token . key ) { // a binding
1154
1153
if ( token . key . charAt ( 0 ) === '>' ) { // a partial
1155
- var partialId = token . key . slice ( 1 ) . trim ( ) ,
1156
- partial = this . getOption ( 'partials' , partialId )
1154
+ partialId = token . key . slice ( 1 ) . trim ( )
1155
+ partial = this . getOption ( 'partials' , partialId )
1157
1156
if ( partial ) {
1158
1157
el = partial . cloneNode ( true )
1159
- this . compileNode ( el )
1158
+ // save an Array reference of the partial's nodes
1159
+ // so we can compile them AFTER appending the fragment
1160
+ partialNodes = slice . call ( el . childNodes )
1160
1161
}
1161
- } else { // a binding
1162
+ } else { // a real binding
1162
1163
el = document . createTextNode ( '' )
1163
1164
directive = Directive . parse ( 'text' , token . key , this , el )
1164
1165
if ( directive ) {
@@ -1168,7 +1169,20 @@ CompilerProto.compileTextNode = function (node) {
1168
1169
} else { // a plain string
1169
1170
el = document . createTextNode ( token )
1170
1171
}
1172
+
1173
+ // insert node
1171
1174
node . parentNode . insertBefore ( el , node )
1175
+
1176
+ // compile partial after appending, because its children's parentNode
1177
+ // will change from the fragment to the correct parentNode.
1178
+ // This could affect directives that need access to its element's parentNode.
1179
+ if ( partialNodes ) {
1180
+ for ( var j = 0 , k = partialNodes . length ; j < k ; j ++ ) {
1181
+ this . compile ( partialNodes [ j ] )
1182
+ }
1183
+ partialNodes = null
1184
+ }
1185
+
1172
1186
}
1173
1187
node . parentNode . removeChild ( node )
1174
1188
}
@@ -1332,9 +1346,7 @@ CompilerProto.markComputed = function (binding) {
1332
1346
vm = this . vm
1333
1347
binding . isComputed = true
1334
1348
// bind the accessors to the vm
1335
- if ( binding . isFn ) {
1336
- binding . value = utils . bind ( value , vm )
1337
- } else {
1349
+ if ( ! binding . isFn ) {
1338
1350
value . $get = utils . bind ( value . $get , vm )
1339
1351
if ( value . $set ) {
1340
1352
value . $set = utils . bind ( value . $set , vm )
@@ -3164,6 +3176,7 @@ module.exports = {
3164
3176
3165
3177
var compiler = this . compiler ,
3166
3178
event = this . arg ,
3179
+ isExp = this . binding . isExp ,
3167
3180
ownerVM = this . binding . compiler . vm
3168
3181
3169
3182
if ( compiler . repeat &&
@@ -3186,7 +3199,7 @@ module.exports = {
3186
3199
if ( target ) {
3187
3200
e . el = target
3188
3201
e . targetVM = target . vue_viewmodel
3189
- handler . call ( ownerVM , e )
3202
+ handler . call ( isExp ? e . targetVM : ownerVM , e )
3190
3203
}
3191
3204
}
3192
3205
dHandler . event = event
0 commit comments