1
1
/*
2
- Vue.js v0.8.2
2
+ Vue.js v0.8.3
3
3
(c) 2014 Evan You
4
4
License: MIT
5
5
*/
@@ -600,6 +600,8 @@ var config = require('./config'),
600
600
toString = Object . prototype . toString ,
601
601
join = Array . prototype . join ,
602
602
console = window . console ,
603
+
604
+ hasClassList = 'classList' in document . documentElement ,
603
605
ViewModel // late def
604
606
605
607
var defer =
@@ -792,6 +794,34 @@ var utils = module.exports = {
792
794
*/
793
795
nextTick : function ( cb ) {
794
796
defer ( cb , 0 )
797
+ } ,
798
+
799
+ /**
800
+ * add class for IE9
801
+ * uses classList if available
802
+ */
803
+ addClass : function ( el , cls ) {
804
+ if ( hasClassList ) {
805
+ el . classList . add ( cls )
806
+ } else {
807
+ var cur = ' ' + el . className + ' '
808
+ if ( cur . indexOf ( ' ' + cls + ' ' ) < 0 ) {
809
+ el . className = ( cur + cls ) . trim ( )
810
+ }
811
+ }
812
+ } ,
813
+
814
+ /**
815
+ * remove class for IE9
816
+ */
817
+ removeClass : function ( el , cls ) {
818
+ if ( hasClassList ) {
819
+ el . classList . remove ( cls )
820
+ } else {
821
+ el . className = ( ' ' + el . className + ' ' )
822
+ . replace ( ' ' + cls + ' ' , '' )
823
+ . trim ( )
824
+ }
795
825
}
796
826
}
797
827
} ) ;
@@ -1155,6 +1185,7 @@ CompilerProto.compileTextNode = function (node) {
1155
1185
1156
1186
for ( var i = 0 , l = tokens . length ; i < l ; i ++ ) {
1157
1187
token = tokens [ i ]
1188
+ directive = null
1158
1189
if ( token . key ) { // a binding
1159
1190
if ( token . key . charAt ( 0 ) === '>' ) { // a partial
1160
1191
partialId = token . key . slice ( 1 ) . trim ( )
@@ -1166,10 +1197,12 @@ CompilerProto.compileTextNode = function (node) {
1166
1197
partialNodes = slice . call ( el . childNodes )
1167
1198
}
1168
1199
} else { // a real binding
1169
- el = document . createTextNode ( '' )
1170
- directive = Directive . parse ( 'text' , token . key , this , el )
1171
- if ( directive ) {
1172
- this . bindDirective ( directive )
1200
+ if ( ! token . html ) { // text binding
1201
+ el = document . createTextNode ( '' )
1202
+ directive = Directive . parse ( 'text' , token . key , this , el )
1203
+ } else { // html binding
1204
+ el = document . createComment ( config . prefix + '-html' )
1205
+ directive = Directive . parse ( 'html' , token . key , this , el )
1173
1206
}
1174
1207
}
1175
1208
} else { // a plain string
@@ -1178,6 +1211,9 @@ CompilerProto.compileTextNode = function (node) {
1178
1211
1179
1212
// insert node
1180
1213
node . parentNode . insertBefore ( el , node )
1214
+ if ( directive ) {
1215
+ this . bindDirective ( directive )
1216
+ }
1181
1217
1182
1218
// compile partial after appending, because its children's parentNode
1183
1219
// will change from the fragment to the correct parentNode.
@@ -2440,19 +2476,22 @@ module.exports = {
2440
2476
}
2441
2477
} ) ;
2442
2478
require . register ( "vue/src/text-parser.js" , function ( exports , require , module ) {
2443
- var BINDING_RE = / \{ \{ ( .+ ?) \} \} /
2479
+ var BINDING_RE = / { { { ? ( [ ^ { } ] + ?) } ? } } / ,
2480
+ TRIPLE_RE = / { { { [ ^ { } ] + } } } /
2444
2481
2445
2482
/**
2446
2483
* Parse a piece of text, return an array of tokens
2447
2484
*/
2448
2485
function parse ( text ) {
2449
2486
if ( ! BINDING_RE . test ( text ) ) return null
2450
- var m , i , tokens = [ ]
2487
+ var m , i , token , tokens = [ ]
2451
2488
/* jshint boss: true */
2452
2489
while ( m = text . match ( BINDING_RE ) ) {
2453
2490
i = m . index
2454
2491
if ( i > 0 ) tokens . push ( text . slice ( 0 , i ) )
2455
- tokens . push ( { key : m [ 1 ] . trim ( ) } )
2492
+ token = { key : m [ 1 ] . trim ( ) }
2493
+ if ( TRIPLE_RE . test ( m [ 0 ] ) ) token . html = true
2494
+ tokens . push ( token )
2456
2495
text = text . slice ( i + m [ 0 ] . length )
2457
2496
}
2458
2497
if ( text . length ) tokens . push ( text )
@@ -2681,6 +2720,8 @@ function applyTransitionClass (el, stage, changeState) {
2681
2720
return codes . CSS_SKIP
2682
2721
}
2683
2722
2723
+ // if the browser supports transition,
2724
+ // it must have classList...
2684
2725
var classList = el . classList ,
2685
2726
lastLeaveCallback = el . vue_trans_cb
2686
2727
@@ -2816,6 +2857,7 @@ module.exports = {
2816
2857
model : require ( './model' ) ,
2817
2858
'if' : require ( './if' ) ,
2818
2859
'with' : require ( './with' ) ,
2860
+ html : require ( './html' ) ,
2819
2861
2820
2862
attr : function ( value ) {
2821
2863
this . el . setAttribute ( this . arg , value )
@@ -2825,10 +2867,6 @@ module.exports = {
2825
2867
this . el . textContent = utils . toText ( value )
2826
2868
} ,
2827
2869
2828
- html : function ( value ) {
2829
- this . el . innerHTML = utils . toText ( value )
2830
- } ,
2831
-
2832
2870
show : function ( value ) {
2833
2871
var el = this . el ,
2834
2872
target = value ? '' : 'none' ,
@@ -2840,13 +2878,13 @@ module.exports = {
2840
2878
2841
2879
'class' : function ( value ) {
2842
2880
if ( this . arg ) {
2843
- this . el . classList [ value ? 'add ' : 'remove ' ] ( this . arg )
2881
+ utils [ value ? 'addClass ' : 'removeClass ' ] ( this . el , this . arg )
2844
2882
} else {
2845
2883
if ( this . lastVal ) {
2846
- this . el . classList . remove ( this . lastVal )
2884
+ utils . removeClass ( this . el , this . lastVal )
2847
2885
}
2848
2886
if ( value ) {
2849
- this . el . classList . add ( value )
2887
+ utils . addClass ( this . el , value )
2850
2888
this . lastVal = value
2851
2889
}
2852
2890
}
@@ -3001,26 +3039,28 @@ module.exports = {
3001
3039
3002
3040
bind : function ( ) {
3003
3041
3004
- var self = this ,
3005
- el = self . el ,
3006
- ctn = self . container = el . parentNode
3042
+ var el = this . el ,
3043
+ ctn = this . container = el . parentNode
3007
3044
3008
3045
// extract child VM information, if any
3009
3046
ViewModel = ViewModel || require ( '../viewmodel' )
3010
- self . Ctor = self . Ctor || ViewModel
3011
-
3047
+ this . Ctor = this . Ctor || ViewModel
3012
3048
// extract transition information
3013
- self . hasTrans = el . hasAttribute ( config . attrs . transition )
3049
+ this . hasTrans = el . hasAttribute ( config . attrs . transition )
3050
+ // extract child Id, if any
3051
+ this . childId = utils . attr ( el , 'component-id' )
3014
3052
3015
3053
// create a comment node as a reference node for DOM insertions
3016
- self . ref = document . createComment ( config . prefix + '-repeat-' + self . key )
3017
- ctn . insertBefore ( self . ref , el )
3054
+ this . ref = document . createComment ( config . prefix + '-repeat-' + this . key )
3055
+ ctn . insertBefore ( this . ref , el )
3018
3056
ctn . removeChild ( el )
3019
3057
3020
- self . initiated = false
3021
- self . collection = null
3022
- self . vms = null
3023
- self . mutationListener = function ( path , arr , mutation ) {
3058
+ this . initiated = false
3059
+ this . collection = null
3060
+ this . vms = null
3061
+
3062
+ var self = this
3063
+ this . mutationListener = function ( path , arr , mutation ) {
3024
3064
var method = mutation . method
3025
3065
mutationHandlers [ method ] . call ( self , mutation )
3026
3066
if ( method !== 'push' && method !== 'pop' ) {
@@ -3035,31 +3075,33 @@ module.exports = {
3035
3075
3036
3076
update : function ( collection , init ) {
3037
3077
3038
- var self = this
3039
- self . unbind ( true )
3078
+ this . unbind ( true )
3040
3079
// attach an object to container to hold handlers
3041
- self . container . vue_dHandlers = utils . hash ( )
3080
+ this . container . vue_dHandlers = utils . hash ( )
3042
3081
// if initiating with an empty collection, we need to
3043
3082
// force a compile so that we get all the bindings for
3044
3083
// dependency extraction.
3045
- if ( ! self . initiated && ( ! collection || ! collection . length ) ) {
3046
- self . buildItem ( )
3047
- self . initiated = true
3084
+ if ( ! this . initiated && ( ! collection || ! collection . length ) ) {
3085
+ this . buildItem ( )
3086
+ this . initiated = true
3087
+ }
3088
+ collection = this . collection = collection || [ ]
3089
+ this . vms = [ ]
3090
+ if ( this . childId ) {
3091
+ this . vm . $ [ this . childId ] = this . vms
3048
3092
}
3049
- collection = self . collection = collection || [ ]
3050
- self . vms = [ ]
3051
3093
3052
3094
// listen for collection mutation events
3053
3095
// the collection has been augmented during Binding.set()
3054
3096
if ( ! collection . __observer__ ) Observer . watchArray ( collection , null , new Emitter ( ) )
3055
- collection . __observer__ . on ( 'mutate' , self . mutationListener )
3097
+ collection . __observer__ . on ( 'mutate' , this . mutationListener )
3056
3098
3057
3099
// create child-vms and append to DOM
3058
3100
if ( collection . length ) {
3059
3101
for ( var i = 0 , l = collection . length ; i < l ; i ++ ) {
3060
- self . buildItem ( collection [ i ] , i )
3102
+ this . buildItem ( collection [ i ] , i )
3061
3103
}
3062
- if ( ! init ) self . changed ( )
3104
+ if ( ! init ) this . changed ( )
3063
3105
}
3064
3106
} ,
3065
3107
@@ -3070,9 +3112,9 @@ module.exports = {
3070
3112
* Batched to ensure it's called only once every event loop.
3071
3113
*/
3072
3114
changed : function ( ) {
3115
+ if ( this . queued ) return
3116
+ this . queued = true
3073
3117
var self = this
3074
- if ( self . queued ) return
3075
- self . queued = true
3076
3118
setTimeout ( function ( ) {
3077
3119
self . compiler . parseDeps ( )
3078
3120
self . queued = false
@@ -3137,6 +3179,9 @@ module.exports = {
3137
3179
} ,
3138
3180
3139
3181
unbind : function ( ) {
3182
+ if ( this . childId ) {
3183
+ delete this . vm . $ [ this . childId ]
3184
+ }
3140
3185
if ( this . collection ) {
3141
3186
this . collection . __observer__ . off ( 'mutate' , this . mutationListener )
3142
3187
var i = this . vms . length
@@ -3403,6 +3448,47 @@ module.exports = {
3403
3448
3404
3449
}
3405
3450
} ) ;
3451
+ require . register ( "vue/src/directives/html.js" , function ( exports , require , module ) {
3452
+ var toText = require ( '../utils' ) . toText ,
3453
+ slice = Array . prototype . slice
3454
+
3455
+ module . exports = {
3456
+
3457
+ bind : function ( ) {
3458
+ // a comment node means this is a binding for
3459
+ // {{{ inline unescaped html }}}
3460
+ if ( this . el . nodeType === 8 ) {
3461
+ // hold nodes
3462
+ this . holder = document . createElement ( 'div' )
3463
+ this . nodes = [ ]
3464
+ }
3465
+ } ,
3466
+
3467
+ update : function ( value ) {
3468
+ value = toText ( value )
3469
+ if ( this . holder ) {
3470
+ this . swap ( value )
3471
+ } else {
3472
+ this . el . innerHTML = value
3473
+ }
3474
+ } ,
3475
+
3476
+ swap : function ( value ) {
3477
+ var parent = this . el . parentNode ,
3478
+ holder = this . holder ,
3479
+ nodes = this . nodes ,
3480
+ i = nodes . length , l
3481
+ while ( i -- ) {
3482
+ parent . removeChild ( nodes [ i ] )
3483
+ }
3484
+ holder . innerHTML = value
3485
+ nodes = this . nodes = slice . call ( holder . childNodes )
3486
+ for ( i = 0 , l = nodes . length ; i < l ; i ++ ) {
3487
+ parent . insertBefore ( nodes [ i ] , this . el )
3488
+ }
3489
+ }
3490
+ }
3491
+ } ) ;
3406
3492
require . alias ( "component-emitter/index.js" , "vue/deps/emitter/index.js" ) ;
3407
3493
require . alias ( "component-emitter/index.js" , "emitter/index.js" ) ;
3408
3494
0 commit comments