1
1
/*
2
- Vue.js v0.10.5
2
+ Vue.js v0.10.6
3
3
(c) 2014 Evan You
4
4
License: MIT
5
5
*/
@@ -213,12 +213,14 @@ var config = require('./config'),
213
213
ViewModel = require ( './viewmodel' ) ,
214
214
utils = require ( './utils' ) ,
215
215
makeHash = utils . hash ,
216
- assetTypes = [ 'directive' , 'filter' , 'partial' , 'effect' , 'component' ]
217
-
218
- // require these so Browserify can catch them
219
- // so they can be used in Vue.require
220
- require ( './observer' )
221
- require ( './transition' )
216
+ assetTypes = [ 'directive' , 'filter' , 'partial' , 'effect' , 'component' ] ,
217
+ // Internal modules that are exposed for plugins
218
+ pluginAPI = {
219
+ utils : utils ,
220
+ config : config ,
221
+ transition : require ( './transition' ) ,
222
+ observer : require ( './observer' )
223
+ }
222
224
223
225
ViewModel . options = config . globalAssets = {
224
226
directives : require ( './directives' ) ,
@@ -239,7 +241,7 @@ assetTypes.forEach(function (type) {
239
241
}
240
242
if ( ! value ) return hash [ id ]
241
243
if ( type === 'partial' ) {
242
- value = utils . toFragment ( value )
244
+ value = utils . parseTemplateOption ( value )
243
245
} else if ( type === 'component' ) {
244
246
value = utils . toConstructor ( value )
245
247
} else if ( type === 'filter' ) {
@@ -294,8 +296,8 @@ ViewModel.use = function (plugin) {
294
296
/**
295
297
* Expose internal modules for plugins
296
298
*/
297
- ViewModel . require = function ( path ) {
298
- return require ( './' + path )
299
+ ViewModel . require = function ( module ) {
300
+ return pluginAPI [ module ]
299
301
}
300
302
301
303
ViewModel . extend = extend
@@ -551,6 +553,11 @@ var utils = module.exports = {
551
553
*/
552
554
toFragment : require ( './fragment' ) ,
553
555
556
+ /**
557
+ * Parse the various types of template options
558
+ */
559
+ parseTemplateOption : require ( './template-parser.js' ) ,
560
+
554
561
/**
555
562
* get a value from an object keypath
556
563
*/
@@ -745,7 +752,7 @@ var utils = module.exports = {
745
752
}
746
753
if ( partials ) {
747
754
for ( key in partials ) {
748
- partials [ key ] = utils . toFragment ( partials [ key ] )
755
+ partials [ key ] = utils . parseTemplateOption ( partials [ key ] )
749
756
}
750
757
}
751
758
if ( filters ) {
@@ -754,7 +761,7 @@ var utils = module.exports = {
754
761
}
755
762
}
756
763
if ( template ) {
757
- options . template = utils . toFragment ( template )
764
+ options . template = utils . parseTemplateOption ( template )
758
765
}
759
766
} ,
760
767
@@ -872,29 +879,12 @@ map.rect = [1, '<svg xmlns="http://www.w3.org/2000/svg" version="1.1">','</svg>'
872
879
873
880
var TAG_RE = / < ( [ \w : ] + ) /
874
881
875
- module . exports = function ( template ) {
876
-
877
- if ( typeof template !== 'string' ) {
878
- return template
879
- }
880
-
881
- // template by ID
882
- if ( template . charAt ( 0 ) === '#' ) {
883
- var templateNode = document . getElementById ( template . slice ( 1 ) )
884
- if ( ! templateNode ) return
885
- // if its a template tag and the browser supports it,
886
- // its content is already a document fragment!
887
- if ( templateNode . tagName === 'TEMPLATE' && templateNode . content ) {
888
- return templateNode . content
889
- }
890
- template = templateNode . innerHTML
891
- }
892
-
882
+ module . exports = function ( templateString ) {
893
883
var frag = document . createDocumentFragment ( ) ,
894
- m = TAG_RE . exec ( template )
884
+ m = TAG_RE . exec ( templateString )
895
885
// text only
896
886
if ( ! m ) {
897
- frag . appendChild ( document . createTextNode ( template ) )
887
+ frag . appendChild ( document . createTextNode ( templateString ) )
898
888
return frag
899
889
}
900
890
@@ -905,7 +895,7 @@ module.exports = function (template) {
905
895
suffix = wrap [ 2 ] ,
906
896
node = document . createElement ( 'div' )
907
897
908
- node . innerHTML = prefix + template . trim ( ) + suffix
898
+ node . innerHTML = prefix + templateString . trim ( ) + suffix
909
899
while ( depth -- ) node = node . lastChild
910
900
911
901
// one element
@@ -1983,14 +1973,24 @@ var Compiler = require('./compiler'),
1983
1973
* and a few reserved methods
1984
1974
*/
1985
1975
function ViewModel ( options ) {
1986
- // just compile. options are passed directly to compiler
1976
+ // compile if options passed, if false return. options are passed directly to compiler
1977
+ if ( options === false ) return
1987
1978
new Compiler ( this , options )
1988
1979
}
1989
1980
1990
1981
// All VM prototype methods are inenumerable
1991
1982
// so it can be stringified/looped through as raw data
1992
1983
var VMProto = ViewModel . prototype
1993
1984
1985
+ /**
1986
+ * init allows config compilation after instantiation:
1987
+ * var a = new Vue(false)
1988
+ * a.init(config)
1989
+ */
1990
+ def ( VMProto , '$init' , function ( options ) {
1991
+ new Compiler ( this , options )
1992
+ } )
1993
+
1994
1994
/**
1995
1995
* Convenience function to get a value from
1996
1996
* a keypath
@@ -2048,8 +2048,8 @@ def(VMProto, '$unwatch', function (key, callback) {
2048
2048
/**
2049
2049
* unbind everything, remove everything
2050
2050
*/
2051
- def ( VMProto , '$destroy' , function ( ) {
2052
- this . $compiler . destroy ( )
2051
+ def ( VMProto , '$destroy' , function ( noRemove ) {
2052
+ this . $compiler . destroy ( noRemove )
2053
2053
} )
2054
2054
2055
2055
/**
@@ -2145,6 +2145,7 @@ function query (el) {
2145
2145
}
2146
2146
2147
2147
module . exports = ViewModel
2148
+
2148
2149
} ) ;
2149
2150
require . register ( "vue/src/binding.js" , function ( exports , require , module ) {
2150
2151
var Batcher = require ( './batcher' ) ,
@@ -3150,6 +3151,55 @@ exports.eval = function (exp, compiler, data) {
3150
3151
}
3151
3152
return res
3152
3153
}
3154
+ } ) ;
3155
+ require . register ( "vue/src/template-parser.js" , function ( exports , require , module ) {
3156
+ var toFragment = require ( './fragment' ) ;
3157
+
3158
+ /**
3159
+ * Parses a template string or node and normalizes it into a
3160
+ * a node that can be used as a partial of a template option
3161
+ *
3162
+ * Possible values include
3163
+ * id selector: '#some-template-id'
3164
+ * template string: '<div><span>my template</span></div>'
3165
+ * DocumentFragment object
3166
+ * Node object of type Template
3167
+ */
3168
+ module . exports = function ( template ) {
3169
+ var templateNode ;
3170
+
3171
+ if ( template instanceof window . DocumentFragment ) {
3172
+ // if the template is already a document fragment -- do nothing
3173
+ return template
3174
+ }
3175
+
3176
+ if ( typeof template === 'string' ) {
3177
+ // template by ID
3178
+ if ( template . charAt ( 0 ) === '#' ) {
3179
+ templateNode = document . getElementById ( template . slice ( 1 ) )
3180
+ if ( ! templateNode ) return
3181
+ } else {
3182
+ return toFragment ( template )
3183
+ }
3184
+ } else if ( template . nodeType ) {
3185
+ templateNode = template
3186
+ } else {
3187
+ return
3188
+ }
3189
+
3190
+ // if its a template tag and the browser supports it,
3191
+ // its content is already a document fragment!
3192
+ if ( templateNode . tagName === 'TEMPLATE' && templateNode . content ) {
3193
+ return templateNode . content
3194
+ }
3195
+
3196
+ if ( templateNode . tagName === 'SCRIPT' ) {
3197
+ return toFragment ( templateNode . innerHTML )
3198
+ }
3199
+
3200
+ return toFragment ( templateNode . outerHTML ) ;
3201
+ }
3202
+
3153
3203
} ) ;
3154
3204
require . register ( "vue/src/text-parser.js" , function ( exports , require , module ) {
3155
3205
var openChar = '{' ,
@@ -3354,6 +3404,7 @@ filters.lowercase = function (value) {
3354
3404
* 12345 => $12,345.00
3355
3405
*/
3356
3406
filters . currency = function ( value , sign ) {
3407
+ value = parseFloat ( value )
3357
3408
if ( ! value && value !== 0 ) return ''
3358
3409
sign = sign || '$'
3359
3410
var s = Math . floor ( value ) . toString ( ) ,
@@ -4271,7 +4322,9 @@ module.exports = {
4271
4322
var el = this . iframeBind
4272
4323
? this . el . contentWindow
4273
4324
: this . el
4274
- el . removeEventListener ( this . arg , this . handler )
4325
+ if ( this . handler ) {
4326
+ el . removeEventListener ( this . arg , this . handler )
4327
+ }
4275
4328
} ,
4276
4329
4277
4330
unbind : function ( ) {
@@ -4571,13 +4624,19 @@ module.exports = {
4571
4624
} ,
4572
4625
4573
4626
update : function ( value ) {
4574
- var prop = this . prop
4627
+ var prop = this . prop ,
4628
+ isImportant
4629
+ /* jshint eqeqeq: true */
4630
+ // cast possible numbers/booleans into strings
4631
+ if ( value != null ) value += ''
4575
4632
if ( prop ) {
4576
- var isImportant = value . slice ( - 10 ) === '!important'
4577
- ? 'important'
4578
- : ''
4579
- if ( isImportant ) {
4580
- value = value . slice ( 0 , - 10 ) . trim ( )
4633
+ if ( value ) {
4634
+ isImportant = value . slice ( - 10 ) === '!important'
4635
+ ? 'important'
4636
+ : ''
4637
+ if ( isImportant ) {
4638
+ value = value . slice ( 0 , - 10 ) . trim ( )
4639
+ }
4581
4640
}
4582
4641
this . el . style . setProperty ( prop , value , isImportant )
4583
4642
if ( this . prefixed ) {
0 commit comments