From 73916108f8a7b78ce3e146a6b66d5099bb1c0ca9 Mon Sep 17 00:00:00 2001 From: Caitlin Potter Date: Mon, 8 Sep 2014 18:58:02 -0400 Subject: [PATCH 1/3] chore(.jshintrc): add jqLiteBuildFragment to globals --- src/.jshintrc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/.jshintrc b/src/.jshintrc index 99ea5a68de32..d61745ac5b34 100644 --- a/src/.jshintrc +++ b/src/.jshintrc @@ -124,6 +124,7 @@ "jqLiteAddNodes": false, "jqLiteController": false, "jqLiteInheritedData": false, + "jqLiteBuildFragment": false, "getBooleanAttrName": false, "getAliasedAttrName": false, "createEventHandler": false, From 719f42e949040a03dfbfc22170976322daf99f2c Mon Sep 17 00:00:00 2001 From: Caitlin Potter Date: Mon, 8 Sep 2014 19:02:36 -0400 Subject: [PATCH 2/3] chore(.jshintrc): add jqLiteParseHTML to globals --- src/.jshintrc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/.jshintrc b/src/.jshintrc index d61745ac5b34..5eda6c464777 100644 --- a/src/.jshintrc +++ b/src/.jshintrc @@ -125,6 +125,7 @@ "jqLiteController": false, "jqLiteInheritedData": false, "jqLiteBuildFragment": false, + "jqLiteParseHTML": false, "getBooleanAttrName": false, "getAliasedAttrName": false, "createEventHandler": false, From 0df805350c6732b1c4c29e2a8090d96542998f52 Mon Sep 17 00:00:00 2001 From: Caitlin Potter Date: Mon, 8 Sep 2014 14:39:41 -0400 Subject: [PATCH 3/3] fix(ngInclude): correctly add non-html namespaced template content It is now possible for ngInclude to correctly load SVG content in non-blink browsers, which do not sort out the namespace when parsing HTML. Closes #7538 --- src/ng/directive/ngInclude.js | 12 +++++++++ test/ng/directive/ngIncludeSpec.js | 40 ++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/src/ng/directive/ngInclude.js b/src/ng/directive/ngInclude.js index e78e72bc1910..7c6f0856e714 100644 --- a/src/ng/directive/ngInclude.js +++ b/src/ng/directive/ngInclude.js @@ -267,6 +267,18 @@ var ngIncludeFillContentDirective = ['$compile', priority: -400, require: 'ngInclude', link: function(scope, $element, $attr, ctrl) { + if (/SVG/.test($element[0].toString())) { + // WebKit: https://bugs.webkit.org/show_bug.cgi?id=135698 --- SVG elements do not + // support innerHTML, so detect this here and try to generate the contents + // specially. + $element.empty(); + $compile(jqLiteBuildFragment(ctrl.template, document).childNodes)(scope, + function namespaceAdaptedClone(clone) { + $element.append(clone); + }, undefined, undefined, $element); + return; + } + $element.html(ctrl.template); $compile($element.contents())(scope); } diff --git a/test/ng/directive/ngIncludeSpec.js b/test/ng/directive/ngIncludeSpec.js index 4dca3f803dc8..e3f366be6e7e 100644 --- a/test/ng/directive/ngIncludeSpec.js +++ b/test/ng/directive/ngIncludeSpec.js @@ -362,6 +362,46 @@ describe('ngInclude', function() { })); + it('should construct SVG template elements with correct namespace', function() { + if (!window.SVGRectElement) return; + module(function($compileProvider) { + $compileProvider.directive('test', valueFn({ + templateNamespace: 'svg', + templateUrl: 'my-rect.html', + replace: true + })); + }); + inject(function($compile, $rootScope, $httpBackend) { + $httpBackend.expectGET('my-rect.html').respond(''); + $httpBackend.expectGET('include.svg').respond(''); + element = $compile('')($rootScope); + $httpBackend.flush(); + var child = element.find('rect'); + expect(child.length).toBe(2); + expect(child[0] instanceof SVGRectElement).toBe(true); + }); + }); + + + it('should compile only the template content of an SVG template', function() { + if (!window.SVGRectElement) return; + module(function($compileProvider) { + $compileProvider.directive('test', valueFn({ + templateNamespace: 'svg', + templateUrl: 'my-rect.html', + replace: true + })); + }); + inject(function($compile, $rootScope, $httpBackend) { + $httpBackend.expectGET('my-rect.html').respond(''); + $httpBackend.expectGET('include.svg').respond(''); + element = $compile('')($rootScope); + $httpBackend.flush(); + expect(element.find('a').length).toBe(0); + }); + }); + + describe('autoscroll', function() { var autoScrollSpy;