aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--regression/jqLite_after_NPE.html24
-rw-r--r--src/Compiler.js26
-rw-r--r--src/markups.js2
-rw-r--r--test/CompilerSpec.js23
4 files changed, 59 insertions, 16 deletions
diff --git a/regression/jqLite_after_NPE.html b/regression/jqLite_after_NPE.html
new file mode 100644
index 00000000..a914e953
--- /dev/null
+++ b/regression/jqLite_after_NPE.html
@@ -0,0 +1,24 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html xmlns:ng="http://angularjs.org">
+<head>
+ <script type="text/javascript" src="../src/angular-bootstrap.js" ng:autobind></script>
+ <script type="text/javascript">
+ angular.markup('-'+'--', function(text, textNode, parentElement) {
+ var compiler = this;
+ var index = text.indexOf('-'+'--');
+ if (index > -1) {
+ textNode.after(text.substring(index + 3));
+ textNode.after('<hr/>');
+ textNode.after(compiler.text(text.substring(0, index)));
+ textNode.remove();
+ }
+ });
+ </script>
+</head>
+<body>
+{{1+3}}
+xxx
+---
+xxx
+<select name="something"><option selected="true">{{'a'}}</option><option value="">{{'b'}}</option><option>C</option></select></body>
+</html> \ No newline at end of file
diff --git a/src/Compiler.js b/src/Compiler.js
index a78a04c9..9263dc02 100644
--- a/src/Compiler.js
+++ b/src/Compiler.js
@@ -158,12 +158,17 @@ Compiler.prototype = {
}
if (descend){
// process markup for text nodes only
- eachTextNode(element, function(textNode){
- var text = textNode.text();
- foreach(self.markup, function(markup){
- markup.call(selfApi, text, textNode, element);
- });
- });
+ for(var i=0, child=element[0].childNodes;
+ i<child.length; i++) {
+ if (isTextNode(child[i])) {
+ foreach(self.markup, function(markup){
+ if (i<child.length) {
+ var textNode = jqLite(child[i]);
+ markup.call(selfApi, textNode.text(), textNode, element);
+ }
+ });
+ }
+ }
}
if (directives) {
@@ -187,15 +192,6 @@ Compiler.prototype = {
}
};
-function eachTextNode(element, fn){
- var i, chldNodes = element[0].childNodes || [], chld;
- for (i = 0; i < chldNodes.length; i++) {
- if(isTextNode(chld = chldNodes[i])) {
- fn(jqLite(chld), i);
- }
- }
-}
-
function eachNode(element, fn){
var i, chldNodes = element[0].childNodes || [], chld;
for (i = 0; i < chldNodes.length; i++) {
diff --git a/src/markups.js b/src/markups.js
index f63dd146..159d7b12 100644
--- a/src/markups.js
+++ b/src/markups.js
@@ -52,8 +52,8 @@ angularTextMarkup('{{}}', function(text, textNode, parentElement) {
cursor.after(newElement);
cursor = newElement;
});
+ textNode.remove();
}
- textNode.remove();
}
});
diff --git a/test/CompilerSpec.js b/test/CompilerSpec.js
index 1091337b..59c365e4 100644
--- a/test/CompilerSpec.js
+++ b/test/CompilerSpec.js
@@ -134,4 +134,27 @@ describe('compiler', function(){
expect(scope.$element.text()).toEqual('3');
});
+ it('should allow multiple markups per text element', function(){
+ markup.push(function(text, textNode, parent){
+ var index = text.indexOf('---');
+ if (index > -1) {
+ textNode.after(text.substring(index + 3));
+ textNode.after("<hr/>");
+ textNode.after(text.substring(0, index));
+ textNode.remove();
+ }
+ });
+ markup.push(function(text, textNode, parent){
+ var index = text.indexOf('===');
+ if (index > -1) {
+ textNode.after(text.substring(index + 3));
+ textNode.after("<p>");
+ textNode.after(text.substring(0, index));
+ textNode.remove();
+ }
+ });
+ var scope = compile('A---B---C===D');
+ expect(sortedHtml(scope.$element)).toEqual('<div>A<hr></hr>B<hr></hr>C<p></p>D</div>');
+ });
+
});