@@ -7,8 +7,25 @@ function calcCacheSize() {
7
7
return size ;
8
8
}
9
9
10
-
11
10
describe ( '$compile' , function ( ) {
11
+ function isUnknownElement ( el ) {
12
+ return ! ! el . toString ( ) . match ( / U n k n o w n / ) ;
13
+ }
14
+
15
+ function isSVGElement ( el ) {
16
+ return ! ! el . toString ( ) . match ( / S V G / ) ;
17
+ }
18
+
19
+ function isHTMLElement ( el ) {
20
+ return ! ! el . toString ( ) . match ( / H T M L / ) ;
21
+ }
22
+
23
+ function supportsMathML ( ) {
24
+ var d = document . createElement ( 'div' ) ;
25
+ d . innerHTML = '<math></math>' ;
26
+ return ! isUnknownElement ( d . firstChild ) ;
27
+ }
28
+
12
29
var element , directive , $compile , $rootScope ;
13
30
14
31
beforeEach ( module ( provideLog , function ( $provide , $compileProvider ) {
@@ -838,58 +855,58 @@ describe('$compile', function() {
838
855
expect ( nodeName_ ( element ) ) . toMatch ( / o p t g r o u p / i) ;
839
856
} ) ) ;
840
857
841
- if ( window . SVGAElement ) {
842
- it ( 'should support SVG templates using directive.type=svg' , function ( ) {
858
+ it ( 'should support SVG templates using directive.templateNamespace=svg' , function ( ) {
859
+ module ( function ( ) {
860
+ directive ( 'svgAnchor' , valueFn ( {
861
+ replace : true ,
862
+ template : '<a xlink:href="{{linkurl}}">{{text}}</a>' ,
863
+ templateNamespace : 'SVG' ,
864
+ scope : {
865
+ linkurl : '@svgAnchor' ,
866
+ text : '@?'
867
+ }
868
+ } ) ) ;
869
+ } ) ;
870
+ inject ( function ( $compile , $rootScope ) {
871
+ element = $compile ( '<svg><g svg-anchor="/foo/bar" text="foo/bar!"></g></svg>' ) ( $rootScope ) ;
872
+ var child = element . children ( ) . eq ( 0 ) ;
873
+ $rootScope . $digest ( ) ;
874
+ expect ( nodeName_ ( child ) ) . toMatch ( / a / i) ;
875
+ expect ( isSVGElement ( child [ 0 ] ) ) . toBe ( true ) ;
876
+ expect ( child [ 0 ] . href . baseVal ) . toBe ( "/foo/bar" ) ;
877
+ } ) ;
878
+ } ) ;
879
+
880
+ if ( supportsMathML ( ) ) {
881
+ // MathML is only natively supported in Firefox at the time of this test's writing,
882
+ // and even there, the browser does not export MathML element constructors globally.
883
+ it ( 'should support MathML templates using directive.templateNamespace=math' , function ( ) {
843
884
module ( function ( ) {
844
- directive ( 'svgAnchor ' , valueFn ( {
885
+ directive ( 'pow ' , valueFn ( {
845
886
replace : true ,
846
- template : '<a xlink:href="{{linkurl}}">{{text}}</a>' ,
847
- type : 'SVG' ,
887
+ transclude : true ,
888
+ template : '<msup><mn>{{pow}}</mn></msup>' ,
889
+ templateNamespace : 'MATH' ,
848
890
scope : {
849
- linkurl : '@svgAnchor' ,
850
- text : '@?'
891
+ pow : '@pow' ,
892
+ } ,
893
+ link : function ( scope , elm , attr , ctrl , transclude ) {
894
+ transclude ( function ( node ) {
895
+ elm . prepend ( node [ 0 ] ) ;
896
+ } ) ;
851
897
}
852
898
} ) ) ;
853
899
} ) ;
854
900
inject ( function ( $compile , $rootScope ) {
855
- element = $compile ( '<svg><g svg-anchor="/foo/bar" text="foo/bar!"></g></svg>' ) ( $rootScope ) ;
856
- var child = element . children ( ) . eq ( 0 ) ;
901
+ element = $compile ( '<math><mn pow="2"><mn>8</mn></mn></math>' ) ( $rootScope ) ;
857
902
$rootScope . $digest ( ) ;
858
- expect ( nodeName_ ( child ) ) . toMatch ( / a / i) ;
859
- expect ( child [ 0 ] . constructor ) . toBe ( window . SVGAElement ) ;
860
- expect ( child [ 0 ] . href . baseVal ) . toBe ( "/foo/bar" ) ;
903
+ var child = element . children ( ) . eq ( 0 ) ;
904
+ expect ( nodeName_ ( child ) ) . toMatch ( / m s u p / i) ;
905
+ expect ( isUnknownElement ( child [ 0 ] ) ) . toBe ( false ) ;
906
+ expect ( isHTMLElement ( child [ 0 ] ) ) . toBe ( false ) ;
861
907
} ) ;
862
908
} ) ;
863
909
}
864
-
865
- // MathML is only natively supported in Firefox at the time of this test's writing,
866
- // and even there, the browser does not export MathML element constructors globally.
867
- // So the test is slightly limited in what it does. But as browsers begin to
868
- // implement MathML natively, this can be tightened up to be more meaningful.
869
- it ( 'should support MathML templates using directive.type=math' , function ( ) {
870
- module ( function ( ) {
871
- directive ( 'pow' , valueFn ( {
872
- replace : true ,
873
- transclude : true ,
874
- template : '<msup><mn>{{pow}}</mn></msup>' ,
875
- type : 'MATH' ,
876
- scope : {
877
- pow : '@pow' ,
878
- } ,
879
- link : function ( scope , elm , attr , ctrl , transclude ) {
880
- transclude ( function ( node ) {
881
- elm . prepend ( node [ 0 ] ) ;
882
- } ) ;
883
- }
884
- } ) ) ;
885
- } ) ;
886
- inject ( function ( $compile , $rootScope ) {
887
- element = $compile ( '<math><mn pow="2"><mn>8</mn></mn></math>' ) ( $rootScope ) ;
888
- $rootScope . $digest ( ) ;
889
- var child = element . children ( ) . eq ( 0 ) ;
890
- expect ( nodeName_ ( child ) ) . toMatch ( / m s u p / i) ;
891
- } ) ;
892
- } ) ;
893
910
} ) ;
894
911
895
912
@@ -1735,60 +1752,60 @@ describe('$compile', function() {
1735
1752
expect ( nodeName_ ( element ) ) . toMatch ( / o p t g r o u p / i) ;
1736
1753
} ) ) ;
1737
1754
1738
- if ( window . SVGAElement ) {
1739
- it ( 'should support SVG templates using directive.type=svg' , function ( ) {
1755
+ it ( 'should support SVG templates using directive.templateNamespace=svg' , function ( ) {
1756
+ module ( function ( ) {
1757
+ directive ( 'svgAnchor' , valueFn ( {
1758
+ replace : true ,
1759
+ templateUrl : 'template.html' ,
1760
+ templateNamespace : 'SVG' ,
1761
+ scope : {
1762
+ linkurl : '@svgAnchor' ,
1763
+ text : '@?'
1764
+ }
1765
+ } ) ) ;
1766
+ } ) ;
1767
+ inject ( function ( $compile , $rootScope , $templateCache ) {
1768
+ $templateCache . put ( 'template.html' , '<a xlink:href="{{linkurl}}">{{text}}</a>' ) ;
1769
+ element = $compile ( '<svg><g svg-anchor="/foo/bar" text="foo/bar!"></g></svg>' ) ( $rootScope ) ;
1770
+ $rootScope . $digest ( ) ;
1771
+ var child = element . children ( ) . eq ( 0 ) ;
1772
+ expect ( nodeName_ ( child ) ) . toMatch ( / a / i) ;
1773
+ expect ( isSVGElement ( child [ 0 ] ) ) . toBe ( true ) ;
1774
+ expect ( child [ 0 ] . href . baseVal ) . toBe ( "/foo/bar" ) ;
1775
+ } ) ;
1776
+ } ) ;
1777
+
1778
+ if ( supportsMathML ( ) ) {
1779
+ // MathML is only natively supported in Firefox at the time of this test's writing,
1780
+ // and even there, the browser does not export MathML element constructors globally.
1781
+ it ( 'should support MathML templates using directive.templateNamespace=math' , function ( ) {
1740
1782
module ( function ( ) {
1741
- directive ( 'svgAnchor ' , valueFn ( {
1783
+ directive ( 'pow ' , valueFn ( {
1742
1784
replace : true ,
1785
+ transclude : true ,
1743
1786
templateUrl : 'template.html' ,
1744
- type : 'SVG ' ,
1787
+ templateNamespace : 'math ' ,
1745
1788
scope : {
1746
- linkurl : '@svgAnchor' ,
1747
- text : '@?'
1789
+ pow : '@pow' ,
1790
+ } ,
1791
+ link : function ( scope , elm , attr , ctrl , transclude ) {
1792
+ transclude ( function ( node ) {
1793
+ elm . prepend ( node [ 0 ] ) ;
1794
+ } ) ;
1748
1795
}
1749
1796
} ) ) ;
1750
1797
} ) ;
1751
1798
inject ( function ( $compile , $rootScope , $templateCache ) {
1752
- $templateCache . put ( 'template.html' , '<a xlink:href="{{linkurl}}">{{text }}</a >' ) ;
1753
- element = $compile ( '<svg><g svg-anchor="/foo/bar" text="foo/bar!" ></g ></svg >' ) ( $rootScope ) ;
1799
+ $templateCache . put ( 'template.html' , '<msup><mn>{{pow }}</mn></msup >' ) ;
1800
+ element = $compile ( '<math><mn pow="2"><mn>8</mn ></mn ></math >' ) ( $rootScope ) ;
1754
1801
$rootScope . $digest ( ) ;
1755
1802
var child = element . children ( ) . eq ( 0 ) ;
1756
- expect ( nodeName_ ( child ) ) . toMatch ( / a / i) ;
1757
- expect ( child [ 0 ] . constructor ) . toBe ( window . SVGAElement ) ;
1758
- expect ( child [ 0 ] . href . baseVal ) . toBe ( "/foo/bar" ) ;
1803
+ expect ( nodeName_ ( child ) ) . toMatch ( / m s u p / i) ;
1804
+ expect ( isUnknownElement ( child [ 0 ] ) ) . toBe ( false ) ;
1805
+ expect ( isHTMLElement ( child [ 0 ] ) ) . toBe ( false ) ;
1759
1806
} ) ;
1760
1807
} ) ;
1761
1808
}
1762
-
1763
- // MathML is only natively supported in Firefox at the time of this test's writing,
1764
- // and even there, the browser does not export MathML element constructors globally.
1765
- // So the test is slightly limited in what it does. But as browsers begin to
1766
- // implement MathML natively, this can be tightened up to be more meaningful.
1767
- it ( 'should support MathML templates using directive.type=math' , function ( ) {
1768
- module ( function ( ) {
1769
- directive ( 'pow' , valueFn ( {
1770
- replace : true ,
1771
- transclude : true ,
1772
- templateUrl : 'template.html' ,
1773
- type : 'MATH' ,
1774
- scope : {
1775
- pow : '@pow' ,
1776
- } ,
1777
- link : function ( scope , elm , attr , ctrl , transclude ) {
1778
- transclude ( function ( node ) {
1779
- elm . prepend ( node [ 0 ] ) ;
1780
- } ) ;
1781
- }
1782
- } ) ) ;
1783
- } ) ;
1784
- inject ( function ( $compile , $rootScope , $templateCache ) {
1785
- $templateCache . put ( 'template.html' , '<msup><mn>{{pow}}</mn></msup>' ) ;
1786
- element = $compile ( '<math><mn pow="2"><mn>8</mn></mn></math>' ) ( $rootScope ) ;
1787
- $rootScope . $digest ( ) ;
1788
- var child = element . children ( ) . eq ( 0 ) ;
1789
- expect ( nodeName_ ( child ) ) . toMatch ( / m s u p / i) ;
1790
- } ) ;
1791
- } ) ;
1792
1809
} ) ;
1793
1810
1794
1811
0 commit comments