From 31c450bcee53d0a3827b7e0a611e9013b2496506 Mon Sep 17 00:00:00 2001
From: Caitlin Potter
Date: Mon, 2 Dec 2013 15:05:21 -0500
Subject: fix($compile) support templates with table content root nodes
If the first element in a template is a
, | , | , or |
tag,
the HTML compiler will ensure that the template is wrapped in a
element so that the table content is not discarded.
Closes #2848
Closes #1459
Closes #3647
Closes #3241
---
src/ng/compile.js | 31 ++++++++++++++++++++++++++-----
1 file changed, 26 insertions(+), 5 deletions(-)
(limited to 'src')
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('' +
- trim(directiveValue) +
- '
').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(''),
+ 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('' +
+ template +
+ '
').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('' + trim(content) + '
').contents();
+ $template = directiveTemplateContents(content);
compileNode = $template[0];
if ($template.length != 1 || compileNode.nodeType !== 1) {
--
cgit v1.2.3