11/*
2- VueJS v0.7.5
2+ VueJS v0.7.6
33 (c) 2014 Evan You
44 License: MIT
55*/
@@ -603,13 +603,10 @@ var config = require('./config'),
603603 console = window . console ,
604604 ViewModel // late def
605605
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
613610
614611/**
615612 * Create a prototype-less object
@@ -1145,20 +1142,24 @@ CompilerProto.compileNode = function (node) {
11451142 * Compile a text node
11461143 */
11471144CompilerProto . compileTextNode = function ( node ) {
1145+
11481146 var tokens = TextParser . parse ( node . nodeValue )
11491147 if ( ! tokens ) return
1150- var el , token , directive
1148+ var el , token , directive , partial , partialId , partialNodes
1149+
11511150 for ( var i = 0 , l = tokens . length ; i < l ; i ++ ) {
11521151 token = tokens [ i ]
11531152 if ( token . key ) { // a binding
11541153 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 )
11571156 if ( partial ) {
11581157 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 )
11601161 }
1161- } else { // a binding
1162+ } else { // a real binding
11621163 el = document . createTextNode ( '' )
11631164 directive = Directive . parse ( 'text' , token . key , this , el )
11641165 if ( directive ) {
@@ -1168,7 +1169,20 @@ CompilerProto.compileTextNode = function (node) {
11681169 } else { // a plain string
11691170 el = document . createTextNode ( token )
11701171 }
1172+
1173+ // insert node
11711174 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+
11721186 }
11731187 node . parentNode . removeChild ( node )
11741188}
@@ -1332,9 +1346,7 @@ CompilerProto.markComputed = function (binding) {
13321346 vm = this . vm
13331347 binding . isComputed = true
13341348 // bind the accessors to the vm
1335- if ( binding . isFn ) {
1336- binding . value = utils . bind ( value , vm )
1337- } else {
1349+ if ( ! binding . isFn ) {
13381350 value . $get = utils . bind ( value . $get , vm )
13391351 if ( value . $set ) {
13401352 value . $set = utils . bind ( value . $set , vm )
@@ -3164,6 +3176,7 @@ module.exports = {
31643176
31653177 var compiler = this . compiler ,
31663178 event = this . arg ,
3179+ isExp = this . binding . isExp ,
31673180 ownerVM = this . binding . compiler . vm
31683181
31693182 if ( compiler . repeat &&
@@ -3186,7 +3199,7 @@ module.exports = {
31863199 if ( target ) {
31873200 e . el = target
31883201 e . targetVM = target . vue_viewmodel
3189- handler . call ( ownerVM , e )
3202+ handler . call ( isExp ? e . targetVM : ownerVM , e )
31903203 }
31913204 }
31923205 dHandler . event = event
0 commit comments