@@ -768,6 +768,59 @@ describe('$compile', function() {
768
768
} ) . not . toThrow ( ) ;
769
769
expect ( nodeName_ ( element ) ) . toMatch ( / o p t g r o u p / i) ;
770
770
} ) ) ;
771
+
772
+ if ( window . SVGAElement ) {
773
+ it ( 'should support SVG templates using directive.type=svg' , function ( ) {
774
+ module ( function ( ) {
775
+ directive ( 'svgAnchor' , valueFn ( {
776
+ replace : true ,
777
+ template : '<a xlink:href="{{linkurl}}">{{text}}</a>' ,
778
+ type : 'SVG' ,
779
+ scope : {
780
+ linkurl : '@svgAnchor' ,
781
+ text : '@?'
782
+ }
783
+ } ) ) ;
784
+ } ) ;
785
+ inject ( function ( $compile , $rootScope ) {
786
+ element = $compile ( '<svg><g svg-anchor="/foo/bar" text="foo/bar!"></g></svg>' ) ( $rootScope ) ;
787
+ var child = element . children ( ) . eq ( 0 ) ;
788
+ $rootScope . $digest ( ) ;
789
+ expect ( nodeName_ ( child ) ) . toMatch ( / a / i) ;
790
+ expect ( child [ 0 ] . constructor ) . toBe ( window . SVGAElement ) ;
791
+ expect ( child [ 0 ] . href . baseVal ) . toBe ( "/foo/bar" ) ;
792
+ } ) ;
793
+ } ) ;
794
+ }
795
+
796
+ // MathML is only natively supported in Firefox at the time of this test's writing,
797
+ // and even there, the browser does not export MathML element constructors globally.
798
+ // So the test is slightly limited in what it does. But as browsers begin to
799
+ // implement MathML natively, this can be tightened up to be more meaningful.
800
+ it ( 'should support MathML templates using directive.type=math' , function ( ) {
801
+ module ( function ( ) {
802
+ directive ( 'pow' , valueFn ( {
803
+ replace : true ,
804
+ transclude : true ,
805
+ template : '<msup><mn>{{pow}}</mn></msup>' ,
806
+ type : 'MATH' ,
807
+ scope : {
808
+ pow : '@pow' ,
809
+ } ,
810
+ link : function ( scope , elm , attr , ctrl , transclude ) {
811
+ transclude ( function ( node ) {
812
+ elm . prepend ( node [ 0 ] ) ;
813
+ } ) ;
814
+ }
815
+ } ) ) ;
816
+ } ) ;
817
+ inject ( function ( $compile , $rootScope ) {
818
+ element = $compile ( '<math><mn pow="2"><mn>8</mn></mn></math>' ) ( $rootScope ) ;
819
+ $rootScope . $digest ( ) ;
820
+ var child = element . children ( ) . eq ( 0 ) ;
821
+ expect ( nodeName_ ( child ) ) . toMatch ( / m s u p / i) ;
822
+ } ) ;
823
+ } ) ;
771
824
} ) ;
772
825
773
826
@@ -1612,6 +1665,61 @@ describe('$compile', function() {
1612
1665
$rootScope . $digest ( ) ;
1613
1666
expect ( nodeName_ ( element ) ) . toMatch ( / o p t g r o u p / i) ;
1614
1667
} ) ) ;
1668
+
1669
+ if ( window . SVGAElement ) {
1670
+ it ( 'should support SVG templates using directive.type=svg' , function ( ) {
1671
+ module ( function ( ) {
1672
+ directive ( 'svgAnchor' , valueFn ( {
1673
+ replace : true ,
1674
+ templateUrl : 'template.html' ,
1675
+ type : 'SVG' ,
1676
+ scope : {
1677
+ linkurl : '@svgAnchor' ,
1678
+ text : '@?'
1679
+ }
1680
+ } ) ) ;
1681
+ } ) ;
1682
+ inject ( function ( $compile , $rootScope , $templateCache ) {
1683
+ $templateCache . put ( 'template.html' , '<a xlink:href="{{linkurl}}">{{text}}</a>' ) ;
1684
+ element = $compile ( '<svg><g svg-anchor="/foo/bar" text="foo/bar!"></g></svg>' ) ( $rootScope ) ;
1685
+ $rootScope . $digest ( ) ;
1686
+ var child = element . children ( ) . eq ( 0 ) ;
1687
+ expect ( nodeName_ ( child ) ) . toMatch ( / a / i) ;
1688
+ expect ( child [ 0 ] . constructor ) . toBe ( window . SVGAElement ) ;
1689
+ expect ( child [ 0 ] . href . baseVal ) . toBe ( "/foo/bar" ) ;
1690
+ } ) ;
1691
+ } ) ;
1692
+ }
1693
+
1694
+ // MathML is only natively supported in Firefox at the time of this test's writing,
1695
+ // and even there, the browser does not export MathML element constructors globally.
1696
+ // So the test is slightly limited in what it does. But as browsers begin to
1697
+ // implement MathML natively, this can be tightened up to be more meaningful.
1698
+ it ( 'should support MathML templates using directive.type=math' , function ( ) {
1699
+ module ( function ( ) {
1700
+ directive ( 'pow' , valueFn ( {
1701
+ replace : true ,
1702
+ transclude : true ,
1703
+ templateUrl : 'template.html' ,
1704
+ type : 'MATH' ,
1705
+ scope : {
1706
+ pow : '@pow' ,
1707
+ } ,
1708
+ link : function ( scope , elm , attr , ctrl , transclude ) {
1709
+ transclude ( function ( node ) {
1710
+ elm . prepend ( node [ 0 ] ) ;
1711
+ } ) ;
1712
+ }
1713
+ } ) ) ;
1714
+ } ) ;
1715
+ inject ( function ( $compile , $rootScope , $templateCache ) {
1716
+ $templateCache . put ( 'template.html' , '<msup><mn>{{pow}}</mn></msup>' ) ;
1717
+ element = $compile ( '<math><mn pow="2"><mn>8</mn></mn></math>' ) ( $rootScope ) ;
1718
+ $rootScope . $digest ( ) ;
1719
+ var child = element . children ( ) . eq ( 0 ) ;
1720
+ expect ( nodeName_ ( child ) ) . toMatch ( / m s u p / i) ;
1721
+ } ) ;
1722
+ } ) ;
1615
1723
} ) ;
1616
1724
1617
1725
0 commit comments