@@ -357,7 +357,7 @@ function $CompileProvider($provide) {
357
357
358
358
//================================
359
359
360
- function compile ( $compileNodes , transcludeFn , maxPriority ) {
360
+ function compile ( $compileNodes , transcludeFn , maxPriority , limitMaxPriorityToFirstElement ) {
361
361
if ( ! ( $compileNodes instanceof jqLite ) ) {
362
362
// jquery always rewraps, whereas we need to preserve the original selector so that we can modify it.
363
363
$compileNodes = jqLite ( $compileNodes ) ;
@@ -369,7 +369,8 @@ function $CompileProvider($provide) {
369
369
$compileNodes [ index ] = jqLite ( node ) . wrap ( '<span></span>' ) . parent ( ) [ 0 ] ;
370
370
}
371
371
} ) ;
372
- var compositeLinkFn = compileNodes ( $compileNodes , transcludeFn , $compileNodes , maxPriority ) ;
372
+ var compositeLinkFn = compileNodes ( $compileNodes , transcludeFn , $compileNodes , maxPriority ,
373
+ limitMaxPriorityToFirstElement ) ;
373
374
return function publicLinkFn ( scope , cloneConnectFn ) {
374
375
assertArg ( scope , 'scope' ) ;
375
376
// important!!: we must call our jqLite.clone() since the jQuery one is trying to be smart
@@ -418,17 +419,21 @@ function $CompileProvider($provide) {
418
419
* rootElement must be set the jqLite collection of the compile root. This is
419
420
* needed so that the jqLite collection items can be replaced with widgets.
420
421
* @param {number= } max directive priority
422
+ * @param {boolean= } if the max priority should only apply to the first element in the list.
423
+ * A true value here will make the maxPriority only apply to the first element on the
424
+ * list while the other elements on the list will not have a maxPriority set
421
425
* @returns {?function } A composite linking function of all of the matched directives or null.
422
426
*/
423
- function compileNodes ( nodeList , transcludeFn , $rootElement , maxPriority ) {
427
+ function compileNodes ( nodeList , transcludeFn , $rootElement , maxPriority , limitMaxPriorityToFirstElement ) {
424
428
var linkFns = [ ] ,
425
429
nodeLinkFn , childLinkFn , directives , attrs , linkFnFound ;
426
430
427
431
for ( var i = 0 ; i < nodeList . length ; i ++ ) {
428
432
attrs = new Attributes ( ) ;
429
433
430
434
// we must always refer to nodeList[i] since the nodes can be replaced underneath us.
431
- directives = collectDirectives ( nodeList [ i ] , [ ] , attrs , maxPriority ) ;
435
+ directives = collectDirectives ( nodeList [ i ] , [ ] , attrs ,
436
+ ( limitMaxPriorityToFirstElement && i != 0 ) ? undefined : maxPriority ) ;
432
437
433
438
nodeLinkFn = ( directives . length )
434
439
? applyDirectivesToNode ( directives , nodeList [ i ] , attrs , transcludeFn , $rootElement )
@@ -646,13 +651,23 @@ function $CompileProvider($provide) {
646
651
replaceWith ( $rootElement , jqLite ( $template [ 0 ] ) , compileNode ) ;
647
652
childTranscludeFn = compile ( $template , transcludeFn , terminalPriority ) ;
648
653
} else if ( directiveValue == 'multi-element' ) {
649
- childTranscludeFn = compile ( jqLite ( extractMultiElementTransclude ( compileNode , directiveName ) ) ,
650
- transcludeFn , terminalPriority ) ;
654
+ // We need to compile a clone of the elements, but at the same time we have to be sure that these elements are siblings
655
+ var nestedContent = extractMultiElementTransclude ( compileNode , directiveName ) ;
656
+ var cloneContent = jqLite ( '<div></div>' ) ;
657
+ forEach ( nestedContent , function ( nestedElement ) {
658
+ cloneContent . append ( JQLiteClone ( nestedElement ) ) ;
659
+ } ) ;
660
+ childTranscludeFn = compile ( cloneContent . contents ( ) , transcludeFn , terminalPriority , true ) ;
651
661
$template = jqLite ( compileNode ) ;
652
662
$compileNode = templateAttrs . $$element =
653
663
jqLite ( document . createComment ( ' ' + directiveName + ': ' + templateAttrs [ directiveName ] + ' ' ) ) ;
654
664
compileNode = $compileNode [ 0 ] ;
655
665
replaceWith ( $rootElement , $template , compileNode ) ;
666
+ forEach ( nestedContent . splice ( 1 ) ,
667
+ function ( toRemove ) {
668
+ replaceWith ( $rootElement , jqLite ( toRemove ) , document . createComment ( ' placeholder ' ) ) ;
669
+ }
670
+ ) ;
656
671
} else {
657
672
$template = jqLite ( JQLiteClone ( compileNode ) ) . contents ( ) ;
658
673
$compileNode . html ( '' ) ; // clear contents
@@ -754,12 +769,6 @@ function $CompileProvider($provide) {
754
769
} while ( count > 0 && cursor ) ;
755
770
if ( count > 0 ) throw Error ( 'Unmatched ' + transcludeStart + '.' ) ;
756
771
if ( count < 0 ) throw Error ( 'Unexpected ' + transcludeEnd + '.' ) ;
757
- for ( var j = 0 ; j < transcludeContent . length ; ++ j ) {
758
- c = transcludeContent [ j ] ;
759
- transcludeContent [ j ] = JQLiteClone ( transcludeContent [ j ] ) ;
760
- // The first element will be replaced by a comment
761
- if ( j != 0 ) jqLite ( c ) . remove ( ) ;
762
- }
763
772
return transcludeContent ;
764
773
}
765
774
0 commit comments