@@ -7265,6 +7265,296 @@ describe('$compile', function() {
7265
7265
} ) ;
7266
7266
7267
7267
7268
+ describe ( 'multi-slot transclude' , function ( ) {
7269
+ it ( 'should only include elements without a matching transclusion element in default transclusion slot' , function ( ) {
7270
+ module ( function ( ) {
7271
+ directive ( 'minionComponent' , function ( ) {
7272
+ return {
7273
+ restrict : 'E' ,
7274
+ scope : { } ,
7275
+ transclude : {
7276
+ boss : 'bossSlot'
7277
+ } ,
7278
+ template :
7279
+ '<div class="other" ng-transclude></div>'
7280
+ } ;
7281
+ } ) ;
7282
+ } ) ;
7283
+ inject ( function ( $rootScope , $compile ) {
7284
+ element = $compile (
7285
+ '<minion-component>' +
7286
+ '<span>stuart</span>' +
7287
+ '<span>bob</span>' +
7288
+ '<boss>gru</boss>' +
7289
+ '<span>kevin</span>' +
7290
+ '</minion-component>' ) ( $rootScope ) ;
7291
+ $rootScope . $apply ( ) ;
7292
+ expect ( element . text ( ) ) . toEqual ( 'stuartbobkevin' ) ;
7293
+ } ) ;
7294
+ } ) ;
7295
+
7296
+ it ( 'should transclude elements to an `ng-transclude` with a matching transclusion slot name' , function ( ) {
7297
+ module ( function ( ) {
7298
+ directive ( 'minionComponent' , function ( ) {
7299
+ return {
7300
+ restrict : 'E' ,
7301
+ scope : { } ,
7302
+ transclude : {
7303
+ minion : 'minionSlot' ,
7304
+ boss : 'bossSlot'
7305
+ } ,
7306
+ template :
7307
+ '<div class="boss" ng-transclude="bossSlot"></div>' +
7308
+ '<div class="minion" ng-transclude="minionSlot"></div>' +
7309
+ '<div class="other" ng-transclude></div>'
7310
+ } ;
7311
+ } ) ;
7312
+ } ) ;
7313
+ inject ( function ( $rootScope , $compile ) {
7314
+ element = $compile (
7315
+ '<minion-component>' +
7316
+ '<minion>stuart</minion>' +
7317
+ '<span>dorothy</span>' +
7318
+ '<boss>gru</boss>' +
7319
+ '<minion>kevin</minion>' +
7320
+ '</minion-component>' ) ( $rootScope ) ;
7321
+ $rootScope . $apply ( ) ;
7322
+ expect ( element . children ( ) . eq ( 0 ) . text ( ) ) . toEqual ( 'gru' ) ;
7323
+ expect ( element . children ( ) . eq ( 1 ) . text ( ) ) . toEqual ( 'stuartkevin' ) ;
7324
+ expect ( element . children ( ) . eq ( 2 ) . text ( ) ) . toEqual ( 'dorothy' ) ;
7325
+ } ) ;
7326
+ } ) ;
7327
+
7328
+
7329
+ it ( 'should use the `ng-transclude-slot` attribute if ng-transclude is used as an element' , function ( ) {
7330
+ module ( function ( ) {
7331
+ directive ( 'minionComponent' , function ( ) {
7332
+ return {
7333
+ restrict : 'E' ,
7334
+ scope : { } ,
7335
+ transclude : {
7336
+ minion : 'minionSlot' ,
7337
+ boss : 'bossSlot'
7338
+ } ,
7339
+ template :
7340
+ '<ng-transclude class="boss" ng-transclude-slot="bossSlot"></ng-transclude>' +
7341
+ '<ng-transclude class="minion" ng-transclude-slot="minionSlot"></ng-transclude>' +
7342
+ '<ng-transclude class="other"></ng-transclude>'
7343
+ } ;
7344
+ } ) ;
7345
+ } ) ;
7346
+ inject ( function ( $rootScope , $compile ) {
7347
+ element = $compile (
7348
+ '<minion-component>' +
7349
+ '<minion>stuart</minion>' +
7350
+ '<span>dorothy</span>' +
7351
+ '<boss>gru</boss>' +
7352
+ '<minion>kevin</minion>' +
7353
+ '</minion-component>' ) ( $rootScope ) ;
7354
+ $rootScope . $apply ( ) ;
7355
+ expect ( element . children ( ) . eq ( 0 ) . text ( ) ) . toEqual ( 'gru' ) ;
7356
+ expect ( element . children ( ) . eq ( 1 ) . text ( ) ) . toEqual ( 'stuartkevin' ) ;
7357
+ expect ( element . children ( ) . eq ( 2 ) . text ( ) ) . toEqual ( 'dorothy' ) ;
7358
+ } ) ;
7359
+ } ) ;
7360
+
7361
+ it ( 'should error if a required transclude slot is not filled' , function ( ) {
7362
+ module ( function ( ) {
7363
+ directive ( 'minionComponent' , function ( ) {
7364
+ return {
7365
+ restrict : 'E' ,
7366
+ scope : { } ,
7367
+ transclude : {
7368
+ minion : 'minionSlot' ,
7369
+ boss : 'bossSlot'
7370
+ } ,
7371
+ template :
7372
+ '<div class="boss" ng-transclude="bossSlot"></div>' +
7373
+ '<div class="minion" ng-transclude="minionSlot"></div>' +
7374
+ '<div class="other" ng-transclude></div>'
7375
+ } ;
7376
+ } ) ;
7377
+ } ) ;
7378
+ inject ( function ( $rootScope , $compile ) {
7379
+ expect ( function ( ) {
7380
+ element = $compile (
7381
+ '<minion-component>' +
7382
+ '<minion>stuart</minion>' +
7383
+ '<span>dorothy</span>' +
7384
+ '</minion-component>' ) ( $rootScope ) ;
7385
+ } ) . toThrowMinErr ( '$compile' , 'reqslot' , 'Required transclusion slot `bossSlot` was not filled.' ) ;
7386
+ } ) ;
7387
+ } ) ;
7388
+
7389
+
7390
+ it ( 'should not error if an optional transclude slot is not filled' , function ( ) {
7391
+ module ( function ( ) {
7392
+ directive ( 'minionComponent' , function ( ) {
7393
+ return {
7394
+ restrict : 'E' ,
7395
+ scope : { } ,
7396
+ transclude : {
7397
+ minion : 'minionSlot' ,
7398
+ boss : '?bossSlot'
7399
+ } ,
7400
+ template :
7401
+ '<div class="boss" ng-transclude="bossSlot"></div>' +
7402
+ '<div class="minion" ng-transclude="minionSlot"></div>' +
7403
+ '<div class="other" ng-transclude></div>'
7404
+ } ;
7405
+ } ) ;
7406
+ } ) ;
7407
+ inject ( function ( $rootScope , $compile ) {
7408
+ element = $compile (
7409
+ '<minion-component>' +
7410
+ '<minion>stuart</minion>' +
7411
+ '<span>dorothy</span>' +
7412
+ '</minion-component>' ) ( $rootScope ) ;
7413
+ $rootScope . $apply ( ) ;
7414
+ expect ( element . children ( ) . eq ( 1 ) . text ( ) ) . toEqual ( 'stuart' ) ;
7415
+ expect ( element . children ( ) . eq ( 2 ) . text ( ) ) . toEqual ( 'dorothy' ) ;
7416
+ } ) ;
7417
+ } ) ;
7418
+
7419
+
7420
+ it ( 'should error if we try to transclude a slot that was not declared by the directive' , function ( ) {
7421
+ module ( function ( ) {
7422
+ directive ( 'minionComponent' , function ( ) {
7423
+ return {
7424
+ restrict : 'E' ,
7425
+ scope : { } ,
7426
+ transclude : {
7427
+ minion : 'minionSlot'
7428
+ } ,
7429
+ template :
7430
+ '<div class="boss" ng-transclude="bossSlot"></div>' +
7431
+ '<div class="minion" ng-transclude="minionSlot"></div>' +
7432
+ '<div class="other" ng-transclude></div>'
7433
+ } ;
7434
+ } ) ;
7435
+ } ) ;
7436
+ inject ( function ( $rootScope , $compile ) {
7437
+ expect ( function ( ) {
7438
+ element = $compile (
7439
+ '<minion-component>' +
7440
+ '<minion>stuart</minion>' +
7441
+ '<span>dorothy</span>' +
7442
+ '</minion-component>' ) ( $rootScope ) ;
7443
+ } ) . toThrowMinErr ( 'ngTransclude' , 'orphan' ,
7444
+ 'Illegal use of ngTransclude directive in the template! ' +
7445
+ 'No parent directive that requires a transclusion with slot name "bossSlot". ' +
7446
+ 'Element: <div class="boss" ng-transclude="bossSlot">' ) ;
7447
+ } ) ;
7448
+ } ) ;
7449
+
7450
+ it ( 'should allow the slot name to equal the element name' , function ( ) {
7451
+
7452
+ module ( function ( ) {
7453
+ directive ( 'foo' , function ( ) {
7454
+ return {
7455
+ restrict : 'E' ,
7456
+ scope : { } ,
7457
+ transclude : {
7458
+ bar : 'bar'
7459
+ } ,
7460
+ template :
7461
+ '<div class="other" ng-transclude="bar"></div>'
7462
+ } ;
7463
+ } ) ;
7464
+ } ) ;
7465
+ inject ( function ( $rootScope , $compile ) {
7466
+ element = $compile (
7467
+ '<foo>' +
7468
+ '<bar>baz</bar>' +
7469
+ '</foo>' ) ( $rootScope ) ;
7470
+ $rootScope . $apply ( ) ;
7471
+ expect ( element . text ( ) ) . toEqual ( 'baz' ) ;
7472
+ } ) ;
7473
+ } ) ;
7474
+
7475
+
7476
+ it ( 'should match against the normalized form of the element' , function ( ) {
7477
+ module ( function ( ) {
7478
+ directive ( 'foo' , function ( ) {
7479
+ return {
7480
+ restrict : 'E' ,
7481
+ scope : { } ,
7482
+ transclude : {
7483
+ fooBar : 'fooBarSlot'
7484
+ } ,
7485
+ template :
7486
+ '<div class="other" ng-transclude="fooBarSlot"></div>'
7487
+ } ;
7488
+ } ) ;
7489
+ } ) ;
7490
+ inject ( function ( $rootScope , $compile ) {
7491
+ element = $compile (
7492
+ '<foo>' +
7493
+ '<foo-bar>baz</foo-bar>' +
7494
+ '</foo>' ) ( $rootScope ) ;
7495
+ $rootScope . $apply ( ) ;
7496
+ expect ( element . text ( ) ) . toEqual ( 'baz' ) ;
7497
+ } ) ;
7498
+ } ) ;
7499
+
7500
+
7501
+ it ( 'should provide the elements marked with matching transclude elements as additional transclude functions on the $$slots property' , function ( ) {
7502
+ var capturedTranscludeFn ;
7503
+ module ( function ( ) {
7504
+ directive ( 'minionComponent' , function ( ) {
7505
+ return {
7506
+ restrict : 'E' ,
7507
+ scope : { } ,
7508
+ transclude : {
7509
+ minion : 'minionSlot' ,
7510
+ boss : 'bossSlot'
7511
+ } ,
7512
+ template :
7513
+ '<div class="boss" ng-transclude="bossSlot"></div>' +
7514
+ '<div class="minion" ng-transclude="minionSlot"></div>' +
7515
+ '<div class="other" ng-transclude></div>' ,
7516
+ link : function ( s , e , a , c , transcludeFn ) {
7517
+ capturedTranscludeFn = transcludeFn ;
7518
+ }
7519
+ } ;
7520
+ } ) ;
7521
+ } ) ;
7522
+ inject ( function ( $rootScope , $compile , log ) {
7523
+ element = $compile (
7524
+ '<minion-component>' +
7525
+ ' <minion>stuart</minion>' +
7526
+ ' <minion>bob</minion>' +
7527
+ ' <span>dorothy</span>' +
7528
+ ' <boss>gru</boss>' +
7529
+ '</minion-component>' ) ( $rootScope ) ;
7530
+ $rootScope . $apply ( ) ;
7531
+
7532
+ var minionTranscludeFn = capturedTranscludeFn . $$boundTransclude . $$slots [ 'minionSlot' ] ;
7533
+ var minions = minionTranscludeFn ( ) ;
7534
+ expect ( minions [ 0 ] . outerHTML ) . toEqual ( '<minion class="ng-scope">stuart</minion>' ) ;
7535
+ expect ( minions [ 1 ] . outerHTML ) . toEqual ( '<minion class="ng-scope">bob</minion>' ) ;
7536
+
7537
+ var scope = element . scope ( ) ;
7538
+
7539
+ var minionScope = jqLite ( minions [ 0 ] ) . scope ( ) ;
7540
+ expect ( minionScope . $parent ) . toBe ( scope ) ;
7541
+
7542
+ var bossTranscludeFn = capturedTranscludeFn . $$boundTransclude . $$slots [ 'bossSlot' ] ;
7543
+ var boss = bossTranscludeFn ( ) ;
7544
+ expect ( boss [ 0 ] . outerHTML ) . toEqual ( '<boss class="ng-scope">gru</boss>' ) ;
7545
+
7546
+ var bossScope = jqLite ( boss [ 0 ] ) . scope ( ) ;
7547
+ expect ( bossScope . $parent ) . toBe ( scope ) ;
7548
+
7549
+ expect ( bossScope ) . not . toBe ( minionScope ) ;
7550
+
7551
+ dealoc ( boss ) ;
7552
+ dealoc ( minions ) ;
7553
+ } ) ;
7554
+ } ) ;
7555
+ } ) ;
7556
+
7557
+
7268
7558
describe ( 'img[src] sanitization' , function ( ) {
7269
7559
7270
7560
it ( 'should NOT require trusted values for img src' , inject ( function ( $rootScope , $compile , $sce ) {
0 commit comments