11/*
2- Vue.js v0.8.2
2+ Vue.js v0.8.3
33 (c) 2014 Evan You
44 License: MIT
55*/
@@ -600,6 +600,8 @@ var config = require('./config'),
600600 toString = Object . prototype . toString ,
601601 join = Array . prototype . join ,
602602 console = window . console ,
603+
604+ hasClassList = 'classList' in document . documentElement ,
603605 ViewModel // late def
604606
605607var defer =
@@ -792,6 +794,34 @@ var utils = module.exports = {
792794 */
793795 nextTick : function ( cb ) {
794796 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+ }
795825 }
796826}
797827} ) ;
@@ -1155,6 +1185,7 @@ CompilerProto.compileTextNode = function (node) {
11551185
11561186 for ( var i = 0 , l = tokens . length ; i < l ; i ++ ) {
11571187 token = tokens [ i ]
1188+ directive = null
11581189 if ( token . key ) { // a binding
11591190 if ( token . key . charAt ( 0 ) === '>' ) { // a partial
11601191 partialId = token . key . slice ( 1 ) . trim ( )
@@ -1166,10 +1197,12 @@ CompilerProto.compileTextNode = function (node) {
11661197 partialNodes = slice . call ( el . childNodes )
11671198 }
11681199 } 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 )
11731206 }
11741207 }
11751208 } else { // a plain string
@@ -1178,6 +1211,9 @@ CompilerProto.compileTextNode = function (node) {
11781211
11791212 // insert node
11801213 node . parentNode . insertBefore ( el , node )
1214+ if ( directive ) {
1215+ this . bindDirective ( directive )
1216+ }
11811217
11821218 // compile partial after appending, because its children's parentNode
11831219 // will change from the fragment to the correct parentNode.
@@ -2440,19 +2476,22 @@ module.exports = {
24402476}
24412477} ) ;
24422478require . register ( "vue/src/text-parser.js" , function ( exports , require , module ) {
2443- var BINDING_RE = / \{ \{ ( .+ ?) \} \} /
2479+ var BINDING_RE = / { { { ? ( [ ^ { } ] + ?) } ? } } / ,
2480+ TRIPLE_RE = / { { { [ ^ { } ] + } } } /
24442481
24452482/**
24462483 * Parse a piece of text, return an array of tokens
24472484 */
24482485function parse ( text ) {
24492486 if ( ! BINDING_RE . test ( text ) ) return null
2450- var m , i , tokens = [ ]
2487+ var m , i , token , tokens = [ ]
24512488 /* jshint boss: true */
24522489 while ( m = text . match ( BINDING_RE ) ) {
24532490 i = m . index
24542491 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 )
24562495 text = text . slice ( i + m [ 0 ] . length )
24572496 }
24582497 if ( text . length ) tokens . push ( text )
@@ -2681,6 +2720,8 @@ function applyTransitionClass (el, stage, changeState) {
26812720 return codes . CSS_SKIP
26822721 }
26832722
2723+ // if the browser supports transition,
2724+ // it must have classList...
26842725 var classList = el . classList ,
26852726 lastLeaveCallback = el . vue_trans_cb
26862727
@@ -2816,6 +2857,7 @@ module.exports = {
28162857 model : require ( './model' ) ,
28172858 'if' : require ( './if' ) ,
28182859 'with' : require ( './with' ) ,
2860+ html : require ( './html' ) ,
28192861
28202862 attr : function ( value ) {
28212863 this . el . setAttribute ( this . arg , value )
@@ -2825,10 +2867,6 @@ module.exports = {
28252867 this . el . textContent = utils . toText ( value )
28262868 } ,
28272869
2828- html : function ( value ) {
2829- this . el . innerHTML = utils . toText ( value )
2830- } ,
2831-
28322870 show : function ( value ) {
28332871 var el = this . el ,
28342872 target = value ? '' : 'none' ,
@@ -2840,13 +2878,13 @@ module.exports = {
28402878
28412879 'class' : function ( value ) {
28422880 if ( this . arg ) {
2843- this . el . classList [ value ? 'add ' : 'remove ' ] ( this . arg )
2881+ utils [ value ? 'addClass ' : 'removeClass ' ] ( this . el , this . arg )
28442882 } else {
28452883 if ( this . lastVal ) {
2846- this . el . classList . remove ( this . lastVal )
2884+ utils . removeClass ( this . el , this . lastVal )
28472885 }
28482886 if ( value ) {
2849- this . el . classList . add ( value )
2887+ utils . addClass ( this . el , value )
28502888 this . lastVal = value
28512889 }
28522890 }
@@ -3001,26 +3039,28 @@ module.exports = {
30013039
30023040 bind : function ( ) {
30033041
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
30073044
30083045 // extract child VM information, if any
30093046 ViewModel = ViewModel || require ( '../viewmodel' )
3010- self . Ctor = self . Ctor || ViewModel
3011-
3047+ this . Ctor = this . Ctor || ViewModel
30123048 // 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' )
30143052
30153053 // 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 )
30183056 ctn . removeChild ( el )
30193057
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 ) {
30243064 var method = mutation . method
30253065 mutationHandlers [ method ] . call ( self , mutation )
30263066 if ( method !== 'push' && method !== 'pop' ) {
@@ -3035,31 +3075,33 @@ module.exports = {
30353075
30363076 update : function ( collection , init ) {
30373077
3038- var self = this
3039- self . unbind ( true )
3078+ this . unbind ( true )
30403079 // attach an object to container to hold handlers
3041- self . container . vue_dHandlers = utils . hash ( )
3080+ this . container . vue_dHandlers = utils . hash ( )
30423081 // if initiating with an empty collection, we need to
30433082 // force a compile so that we get all the bindings for
30443083 // 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
30483092 }
3049- collection = self . collection = collection || [ ]
3050- self . vms = [ ]
30513093
30523094 // listen for collection mutation events
30533095 // the collection has been augmented during Binding.set()
30543096 if ( ! collection . __observer__ ) Observer . watchArray ( collection , null , new Emitter ( ) )
3055- collection . __observer__ . on ( 'mutate' , self . mutationListener )
3097+ collection . __observer__ . on ( 'mutate' , this . mutationListener )
30563098
30573099 // create child-vms and append to DOM
30583100 if ( collection . length ) {
30593101 for ( var i = 0 , l = collection . length ; i < l ; i ++ ) {
3060- self . buildItem ( collection [ i ] , i )
3102+ this . buildItem ( collection [ i ] , i )
30613103 }
3062- if ( ! init ) self . changed ( )
3104+ if ( ! init ) this . changed ( )
30633105 }
30643106 } ,
30653107
@@ -3070,9 +3112,9 @@ module.exports = {
30703112 * Batched to ensure it's called only once every event loop.
30713113 */
30723114 changed : function ( ) {
3115+ if ( this . queued ) return
3116+ this . queued = true
30733117 var self = this
3074- if ( self . queued ) return
3075- self . queued = true
30763118 setTimeout ( function ( ) {
30773119 self . compiler . parseDeps ( )
30783120 self . queued = false
@@ -3137,6 +3179,9 @@ module.exports = {
31373179 } ,
31383180
31393181 unbind : function ( ) {
3182+ if ( this . childId ) {
3183+ delete this . vm . $ [ this . childId ]
3184+ }
31403185 if ( this . collection ) {
31413186 this . collection . __observer__ . off ( 'mutate' , this . mutationListener )
31423187 var i = this . vms . length
@@ -3403,6 +3448,47 @@ module.exports = {
34033448
34043449}
34053450} ) ;
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+ } ) ;
34063492require . alias ( "component-emitter/index.js" , "vue/deps/emitter/index.js" ) ;
34073493require . alias ( "component-emitter/index.js" , "emitter/index.js" ) ;
34083494
0 commit comments