Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

support SVG templates #6778

Closed
Closed
@sussh

Description

@sussh

bower.json

{
  "name": "angular",
  "version": "1.2.14",
  "main": "./angular.js",
  "dependencies": {
  }
}
# HG changeset patch
# User Zugr <sussh@synergetica.co>
# Date 1395340922 -7200
#      Thu Mar 20 20:42:02 2014 +0200
#
# Node ID 5ecaba4e38c688524d0a348ff678c240c05d2d73
# Parent  cb5f47358b3d1f33c7edf8ce744eeb2c55f9aa4a
корректировка angular.js с целью исправления обработки svg элементов в шаблонах

diff --git a/www/js/components/angular/angular.js b/www/js/components/angular/angular.js
--- a/www/js/components/angular/angular.js
+++ b/www/js/components/angular/angular.js
@@ -6022,8 +6022,11 @@

           if (directive.replace) {
             replaceDirective = directive;
-            $template = directiveTemplateContents(directiveValue);
-            compileNode = $template[0];
+            $template = ('ownerSVGElement' in $compileNode[0] ?
+               makeSvgElement(trim(directiveValue), $compileNode[0].ownerDocument) :
+               directiveTemplateContents(directiveValue));
+
+          compileNode = $template[0];

             if ($template.length != 1 || compileNode.nodeType !== 1) {
               throw $compileMinErr('tplrt',
@@ -6467,7 +6470,9 @@
           content = denormalizeTemplate(content);

           if (origAsyncDirective.replace) {
-            $template = directiveTemplateContents(content);
+            $template = ('ownerSVGElement' in $compileNode[0] ?
+                makeSvgElement(trim(content), $compileNode[0].ownerDocument) :
+                directiveTemplateContents(content));
             compileNode = $template[0];

             if ($template.length != 1 || compileNode.nodeType !== 1) {
@@ -21050,4 +21055,26 @@

 })(window, document);

-!angular.$$csp() && angular.element(document).find('head').prepend('<style type="text/css">@charset "UTF-8";[ng\\:cloak],[ng-cloak],[data-ng-cloak],[x-ng-cloak],.ng-cloak,.x-ng-cloak,.ng-hide{display:none !important;}ng\\:form{display:block;}.ng-animate-block-transitions{transition:0s all!important;-webkit-transition:0s all!important;}</style>');
\ No newline at end of file
+!angular.$$csp() && angular.element(document).find('head').prepend('<style type="text/css">@charset "UTF-8";[ng\\:cloak],[ng-cloak],[data-ng-cloak],[x-ng-cloak],.ng-cloak,.x-ng-cloak,.ng-hide{display:none !important;}ng\\:form{display:block;}.ng-animate-block-transitions{transition:0s all!important;-webkit-transition:0s all!important;}</style>');
+
+function makeSvgElement(xhtml, ownerDocument)
+   { return angular.element('<svg>' + xhtml + '</svg>').contents(); }
+
+// Inspiration for this derived from a shim known as "innerSVG" which adds "innerHTML" attribute to SVGElement:
+// http://stackoverflow.com/questions/9723422/is-there-some-innerhtml-replacement-in-svg-xml
+Object.defineProperty(SVGElement.prototype, 'innerHTML', {
+   get: function ()
+       {}, // TBD!
+   set: function (markup)
+       {
+       // 1. Remove all children
+       while (this.firstChild)
+           { this.firstChild.parentNode.removeChild(this.firstChild); }
+       // 2. Make the SVG Node
+       var contents = makeSvgElement(markup, this.ownerDocument)[0].childNodes;
+       // 3. Append the childNodes to this node
+       while (contents.length)
+           { this.appendChild(contents[0]); }
+       },
+   enumerable: false,
+   configurable: true});

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions