diff options
| author | Caitlin Potter | 2013-12-02 15:05:21 -0500 | 
|---|---|---|
| committer | Caitlin Potter | 2014-02-14 14:42:55 -0500 | 
| commit | 31c450bcee53d0a3827b7e0a611e9013b2496506 (patch) | |
| tree | 947ca3b89b4153705fe4a2c163672c8d07eb5d18 /src/ng/compile.js | |
| parent | a9fcb0d0fc6456f80501b8820d02b04d7c15b6d6 (diff) | |
| download | angular.js-31c450bcee53d0a3827b7e0a611e9013b2496506.tar.bz2 | |
fix($compile) support templates with table content root nodes
If the first element in a template is a <tr>, <th>, <td>, or <tbody> tag,
the HTML compiler will ensure that the template is wrapped in a <table>
element so that the table content is not discarded.
Closes #2848
Closes #1459
Closes #3647
Closes #3241
Diffstat (limited to 'src/ng/compile.js')
| -rw-r--r-- | src/ng/compile.js | 31 | 
1 files changed, 26 insertions, 5 deletions
| diff --git a/src/ng/compile.js b/src/ng/compile.js index de65c83e..e4bf230e 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -502,7 +502,8 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {    var hasDirectives = {},        Suffix = 'Directive',        COMMENT_DIRECTIVE_REGEXP = /^\s*directive\:\s*([\d\w\-_]+)\s+(.*)$/, -      CLASS_DIRECTIVE_REGEXP = /(([\d\w\-_]+)(?:\:([^;]+))?;?)/; +      CLASS_DIRECTIVE_REGEXP = /(([\d\w\-_]+)(?:\:([^;]+))?;?)/, +      TABLE_CONTENT_REGEXP = /^<\s*(tr|th|td|tbody)(\s+[^>]*)?>/i;    // Ref: http://developers.whatwg.org/webappapis.html#event-handler-idl-attributes    // The assumption is that future DOM event attribute names will begin with @@ -1243,9 +1244,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {            if (directive.replace) {              replaceDirective = directive; -            $template = jqLite('<div>' + -                                 trim(directiveValue) + -                               '</div>').contents(); +            $template = directiveTemplateContents(directiveValue);              compileNode = $template[0];              if ($template.length != 1 || compileNode.nodeType !== 1) { @@ -1644,6 +1643,28 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {      } +    function directiveTemplateContents(template) { +      var type; +      template = trim(template); +      if ((type = TABLE_CONTENT_REGEXP.exec(template))) { +        type = type[1].toLowerCase(); +        var table = jqLite('<table>' + template + '</table>'), +            tbody = table.children('tbody'), +            leaf = /(td|th)/.test(type) && table.find('tr'); +        if (tbody.length && type !== 'tbody') { +          table = tbody; +        } +        if (leaf && leaf.length) { +          table = leaf; +        } +        return table.contents(); +      } +      return jqLite('<div>' + +                      template + +                    '</div>').contents(); +    } + +      function compileTemplateUrl(directives, $compileNode, tAttrs,          $rootElement, childTranscludeFn, preLinkFns, postLinkFns, previousCompileContext) {        var linkQueue = [], @@ -1668,7 +1689,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {            content = denormalizeTemplate(content);            if (origAsyncDirective.replace) { -            $template = jqLite('<div>' + trim(content) + '</div>').contents(); +            $template = directiveTemplateContents(content);              compileNode = $template[0];              if ($template.length != 1 || compileNode.nodeType !== 1) { | 
