@@ -492,7 +492,7 @@ function toJsonArray(buf, obj, pretty, stack){
492
492
}
493
493
}
494
494
/**
495
- = * Template provides directions an how to bind to a given element.
495
+ * Template provides directions an how to bind to a given element.
496
496
* It contains a list of init functions which need to be called to
497
497
* bind to a new instance of elements. It also provides a list
498
498
* of child paths which contain child templates
@@ -1902,6 +1902,7 @@ JQLite.prototype = {
1902
1902
} ) ;
1903
1903
} ,
1904
1904
1905
+ //TODO: remove
1905
1906
trigger : function ( type ) {
1906
1907
var evnt = document . createEvent ( 'MouseEvent' ) ;
1907
1908
evnt . initMouseEvent ( type , true , true , window , 0 , 0 , 0 , 0 , 0 , false , false , false , false , 0 , null ) ;
@@ -3281,15 +3282,21 @@ angularWidget('NG:INCLUDE', function(element){
3281
3282
}
3282
3283
} ) ;
3283
3284
3284
- angularWidget ( 'NG:SWITCH' , function ( element ) {
3285
+ angularWidget ( 'NG:SWITCH' , function ngSwitch ( element ) {
3285
3286
var compiler = this ,
3286
3287
watchExpr = element . attr ( "on" ) ,
3288
+ whenFn = ngSwitch [ element . attr ( "using" ) || 'equals' ] ;
3289
+ changeExpr = element . attr ( 'change' ) || '' ,
3287
3290
cases = [ ] ;
3291
+ if ( ! whenFn ) throw "Using expression '" + usingExpr + "' unknown." ;
3288
3292
eachNode ( element , function ( caseElement ) {
3289
3293
var when = caseElement . attr ( 'ng-switch-when' ) ;
3290
3294
if ( when ) {
3291
3295
cases . push ( {
3292
- when : function ( value ) { return value == when ; } ,
3296
+ when : function ( scope , value ) {
3297
+ return whenFn . call ( scope , value , when ) ;
3298
+ } ,
3299
+ change : changeExpr ,
3293
3300
element : caseElement ,
3294
3301
template : compiler . compile ( caseElement )
3295
3302
} ) ;
@@ -3301,10 +3308,13 @@ angularWidget('NG:SWITCH', function(element){
3301
3308
this . $watch ( watchExpr , function ( value ) {
3302
3309
element . html ( '' ) ;
3303
3310
childScope = null ;
3311
+ var params = { } ;
3304
3312
foreach ( cases , function ( switchCase ) {
3305
- if ( switchCase . when ( value ) ) {
3313
+ if ( switchCase . when ( params , value ) ) {
3306
3314
element . append ( switchCase . element ) ;
3307
3315
childScope = createScope ( scope ) ;
3316
+ extend ( childScope , params ) ;
3317
+ childScope . $tryEval ( switchCase . change , element ) ;
3308
3318
switchCase . template ( switchCase . element , childScope ) ;
3309
3319
childScope . $init ( ) ;
3310
3320
}
@@ -3314,6 +3324,30 @@ angularWidget('NG:SWITCH', function(element){
3314
3324
if ( childScope ) childScope . $eval ( ) ;
3315
3325
} ) ;
3316
3326
} ;
3327
+ } , {
3328
+ equals : function ( on , when ) {
3329
+ return on == when ;
3330
+ } ,
3331
+ route : function ( on , when ) {
3332
+ var regex = '^' + when . replace ( / [ \. \\ \( \) \^ \$ ] / g, "\$1" ) + '$' , params = [ ] , self = this ;
3333
+ foreach ( when . split ( / \W / ) , function ( param ) {
3334
+ if ( param ) {
3335
+ var paramRegExp = new RegExp ( ":" + param + "([\\W])" ) ;
3336
+ if ( regex . match ( paramRegExp ) ) {
3337
+ regex = regex . replace ( paramRegExp , "(.*)$1" ) ;
3338
+ params . push ( param ) ;
3339
+ }
3340
+ }
3341
+ } ) ;
3342
+ console . log ( regex ) ;
3343
+ var match = on . match ( new RegExp ( regex ) ) ;
3344
+ if ( match ) {
3345
+ foreach ( params , function ( name , index ) {
3346
+ self [ name ] = match [ index + 1 ] ;
3347
+ } ) ;
3348
+ }
3349
+ return match ;
3350
+ }
3317
3351
} ) ;
3318
3352
angularService ( "$window" , bind ( window , identity , window ) ) ;
3319
3353
angularService ( "$document" , function ( window ) {
0 commit comments