@@ -877,6 +877,23 @@ CompilerProto.setupElement = function (options) {
877
877
? document . querySelector ( options . el )
878
878
: options . el || document . createElement ( options . tagName || 'div' )
879
879
880
+ var template = options . template
881
+ if ( template ) {
882
+ // replace option: use the first node in
883
+ // the template directly
884
+ if ( options . replace && template . childNodes . length === 1 ) {
885
+ var replacer = template . childNodes [ 0 ] . cloneNode ( true )
886
+ if ( el . parentNode ) {
887
+ el . parentNode . insertBefore ( replacer , el )
888
+ el . parentNode . removeChild ( el )
889
+ }
890
+ el = replacer
891
+ } else {
892
+ el . innerHTML = ''
893
+ el . appendChild ( template . cloneNode ( true ) )
894
+ }
895
+ }
896
+
880
897
// apply element options
881
898
if ( options . id ) el . id = options . id
882
899
if ( options . className ) el . className = options . className
@@ -887,12 +904,6 @@ CompilerProto.setupElement = function (options) {
887
904
}
888
905
}
889
906
890
- // initialize template
891
- var template = options . template
892
- if ( template ) {
893
- el . innerHTML = ''
894
- el . appendChild ( template . cloneNode ( true ) )
895
- }
896
907
return el
897
908
}
898
909
@@ -2148,10 +2159,14 @@ module.exports = {
2148
2159
return makeGetter ( 'return ' + exp , exp )
2149
2160
}
2150
2161
vars = utils . unique ( vars )
2151
- var pathRE = new RegExp ( "\\b(" + vars . join ( '|' ) + ")[$\\w\\.]*\\b" , 'g' ) ,
2152
- body = 'return ' + exp . replace ( pathRE , function ( path ) {
2153
- return 'this.' + getRel ( path , compiler ) + path
2162
+ var accessors = '' ,
2163
+ pathRE = new RegExp ( "\\b(" + vars . join ( '|' ) + ")[$\\w\\.]*\\b" , 'g' ) ,
2164
+ body = 'return ' + exp . replace ( pathRE , function ( path ) {
2165
+ var val = 'this.' + getRel ( path , compiler ) + path
2166
+ accessors += val + ';'
2167
+ return val
2154
2168
} )
2169
+ body = accessors + body
2155
2170
return makeGetter ( body , exp )
2156
2171
}
2157
2172
}
@@ -2854,13 +2869,10 @@ module.exports = {
2854
2869
require . register ( "seed/src/directives/on.js" , function ( exports , require , module ) {
2855
2870
var utils = require ( '../utils' )
2856
2871
2857
- function delegateCheck ( current , top , identifier ) {
2858
- if ( current [ identifier ] ) {
2859
- return current
2860
- } else if ( current === top || ! current . parentNode ) {
2861
- return false
2862
- } else {
2863
- return delegateCheck ( current . parentNode , top , identifier )
2872
+ function delegateCheck ( el , root , identifier ) {
2873
+ while ( el && el !== root ) {
2874
+ if ( el [ identifier ] ) return el
2875
+ el = el . parentNode
2864
2876
}
2865
2877
}
2866
2878
@@ -2980,10 +2992,15 @@ module.exports = {
2980
2992
try {
2981
2993
cursorPos = el . selectionStart
2982
2994
} catch ( e ) { }
2983
- self . vm . $set ( self . key , el [ attr ] )
2984
- if ( cursorPos !== undefined ) {
2985
- el . setSelectionRange ( cursorPos , cursorPos )
2986
- }
2995
+ // `input` event has weird updating issue with
2996
+ // International (e.g. Chinese) input methods,
2997
+ // have to use a Timeout to hack around it...
2998
+ setTimeout ( function ( ) {
2999
+ self . vm . $set ( self . key , el [ attr ] )
3000
+ if ( cursorPos !== undefined ) {
3001
+ el . setSelectionRange ( cursorPos , cursorPos )
3002
+ }
3003
+ } , 0 )
2987
3004
}
2988
3005
: function ( ) {
2989
3006
// no filters, don't let it trigger update()
0 commit comments