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

Commit 62c0e5c

Browse files
committedOct 27, 2010
Fix failing tests for ie, and mark elements as ng-widget, ng-directive, and ng-binding
1 parent c67af8a commit 62c0e5c

10 files changed

+88
-21
lines changed
 

‎.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
build/
22
angularjs.netrc
33
jstd.log
4-
.DS_Store
4+
.DS_Store
5+
regression/temp.html

‎docs/filter:currency.html

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<h1>filter:currency</h1>
2+
3+
<p>formats a number as a currency (ie $1,234.56)</p>
4+
5+
<p>@format <em>expression</em> | currency</p>
6+
7+
<p><example>
8+
<input type="text" name="amount" value="1234.56"/> <br/>
9+
{{amount | currency}}
10+
</example></p>
11+
12+
<p><test>
13+
it('should init with 1234.56', function(){
14+
expect(bind('amount')).toEqual('$1,234.56');
15+
});
16+
it('should update', function(){
17+
element(':input[name=amount]').value('-1234');
18+
expect(bind('amount')).toEqual('-$1,234.00');
19+
expect(bind('amount')).toHaveColor('red');
20+
});
21+
</test></p>

‎docs/filter:currency.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# filter:currency
2+
formats a number as a currency (ie $1,234.56)
3+
4+
@format _expression_ | currency
5+
6+
<example>
7+
<input type="text" name="amount" value="1234.56"/> <br/>
8+
{{amount | currency}}
9+
</example>
10+
11+
<test>
12+
it('should init with 1234.56', function(){
13+
expect(bind('amount')).toEqual('$1,234.56');
14+
});
15+
it('should update', function(){
16+
element(':input[name=amount]').value('-1234');
17+
expect(bind('amount')).toEqual('-$1,234.00');
18+
expect(bind('amount')).toHaveColor('red');
19+
});
20+
</test>

‎src/Compiler.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,11 @@ Compiler.prototype = {
112112
templatize: function(element, elementIndex, priority){
113113
var self = this,
114114
widget,
115+
fn,
115116
directiveFns = self.directives,
116117
descend = true,
117118
directives = true,
119+
elementName = nodeName(element),
118120
template,
119121
selfApi = {
120122
compile: bind(self, self.compile),
@@ -138,12 +140,15 @@ Compiler.prototype = {
138140
eachAttribute(element, function(value, name){
139141
if (!widget) {
140142
if (widget = self.widgets('@' + name)) {
143+
element.addClass('ng-attr-widget');
141144
widget = bind(selfApi, widget, value, element);
142145
}
143146
}
144147
});
145148
if (!widget) {
146-
if (widget = self.widgets(nodeName(element))) {
149+
if (widget = self.widgets(elementName)) {
150+
if (elementName.indexOf(':') > 0)
151+
element.addClass('ng-widget');
147152
widget = bind(selfApi, widget, element);
148153
}
149154
}
@@ -179,7 +184,11 @@ Compiler.prototype = {
179184
});
180185
});
181186
eachAttribute(element, function(value, name){
182-
template.addInit((directiveFns[name]||noop).call(selfApi, value, element));
187+
fn = directiveFns[name];
188+
if (fn) {
189+
element.addClass('ng-directive');
190+
template.addInit((directiveFns[name]).call(selfApi, value, element));
191+
}
183192
});
184193
}
185194
// Process non text child nodes

‎src/directives.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ angularDirective("ng:eval", function(expression){
2222
};
2323
});
2424

25-
angularDirective("ng:bind", function(expression){
25+
angularDirective("ng:bind", function(expression, element){
26+
element.addClass('ng-binding');
2627
return function(element) {
2728
var lastValue = noop, lastError = noop;
2829
this.$onEval(function() {
@@ -97,7 +98,8 @@ function compileBindTemplate(template){
9798
return fn;
9899
}
99100

100-
angularDirective("ng:bind-template", function(expression){
101+
angularDirective("ng:bind-template", function(expression, element){
102+
element.addClass('ng-binding');
101103
var templateFn = compileBindTemplate(expression);
102104
return function(element) {
103105
var lastValue;

‎src/scenario/dsl.js

+12-8
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,21 @@ angular.scenario.dsl('using', function() {
8686
* binding(name) returns the value of a binding
8787
*/
8888
angular.scenario.dsl('binding', function() {
89+
function contains(text, value) {
90+
return text && text.indexOf(value) >=0;
91+
}
8992
return function(name) {
9093
return this.addFutureAction("select binding '" + name + "'", function($window, $document, done) {
91-
var element;
92-
try {
93-
element = $document.elements('[ng\\:bind-template*="{{$1}}"]', name);
94-
} catch(e) {
95-
if (e.type !== 'selector')
96-
throw e;
97-
element = $document.elements('[ng\\:bind="$1"]', name);
94+
var elements = $document.elements('.ng-binding');
95+
for ( var i = 0; i < elements.length; i++) {
96+
var element = new elements.init(elements[i]);
97+
if (contains(element.attr('ng:bind'), name) >= 0 ||
98+
contains(element.attr('ng:bind-template'), name) >= 0) {
99+
done(null, element.text());
100+
return;
101+
}
98102
}
99-
done(null, element.text());
103+
throw "Could not find binding: " + name;
100104
});
101105
};
102106
});

‎test/CompilerSpec.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ describe('compiler', function(){
4646
var init = template(e).$init;
4747
expect(log).toEqual("found");
4848
init();
49+
expect(e.hasClass('ng-directive')).toEqual(true);
4950
expect(log).toEqual("found:init");
5051
});
5152

@@ -102,12 +103,13 @@ describe('compiler', function(){
102103
}
103104
});
104105
var scope = compile('before<span>middle</span>after');
105-
expect(lowercase(scope.$element[0].innerHTML)).toEqual('before<span hello="middle">replaced</span>after');
106+
expect(sortedHtml(scope.$element[0], true)).toEqual('<div>before<span class="ng-directive" hello="middle">replaced</span>after</div>');
106107
expect(log).toEqual("hello middle");
107108
});
108109

109110
it('should replace widgets', function(){
110111
widgets['NG:BUTTON'] = function(element) {
112+
expect(element.hasClass('ng-widget')).toEqual(true);
111113
element.replaceWith('<div>button</div>');
112114
return function(element) {
113115
log += 'init';
@@ -120,6 +122,8 @@ describe('compiler', function(){
120122

121123
it('should use the replaced element after calling widget', function(){
122124
widgets['H1'] = function(element) {
125+
// HTML elements which are augmented by acting as widgets, should not be marked as so
126+
expect(element.hasClass('ng-widget')).toEqual(false);
123127
var span = angular.element('<span>{{1+2}}</span>');
124128
element.replaceWith(span);
125129
this.descend(true);

‎test/directivesSpec.js

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ describe("directives", function(){
3535
expect(element.text()).toEqual('');
3636
scope.a = 'misko';
3737
scope.$eval();
38+
expect(element.hasClass('ng-binding')).toEqual(true);
3839
expect(element.text()).toEqual('misko');
3940
});
4041

@@ -87,6 +88,7 @@ describe("directives", function(){
8788
var scope = compile('<div ng:bind-template="Hello {{name}}!"></div>');
8889
scope.$set('name', 'Misko');
8990
scope.$eval();
91+
expect(element.hasClass('ng-binding')).toEqual(true);
9092
expect(element.text()).toEqual('Hello Misko!');
9193
});
9294

‎test/scenario/dslSpec.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -260,15 +260,13 @@ describe("angular.scenario.dsl", function() {
260260

261261
describe('Binding', function() {
262262
it('should select binding by name', function() {
263-
if (msie) return; // TODO reenable!
264-
doc.append('<span ng:bind="foo.bar">some value</span>');
263+
doc.append('<span class="ng-binding" ng:bind="foo.bar">some value</span>');
265264
$root.dsl.binding('foo.bar');
266265
expect($root.futureResult).toEqual('some value');
267266
});
268267

269268
it('should select binding in template by name', function() {
270-
if (msie) return; // TODO reenable!
271-
doc.append('<pre ng:bind-template="foo {{bar}} baz">foo some baz</pre>');
269+
doc.append('<pre class="ng-binding" ng:bind-template="foo {{bar}} baz">foo some baz</pre>');
272270
$root.dsl.binding('bar');
273271
expect($root.futureResult).toEqual('foo some baz');
274272
});

‎test/testabilityPatch.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ extend(angular, {
8181
});
8282

8383

84-
function sortedHtml(element) {
84+
function sortedHtml(element, showNgClass) {
8585
var html = "";
8686
foreach(jqLite(element), function toString(node) {
8787
if (node.nodeName == "#text") {
@@ -93,8 +93,14 @@ function sortedHtml(element) {
9393
html += '<' + node.nodeName.toLowerCase();
9494
var attributes = node.attributes || [];
9595
var attrs = [];
96-
if (node.className)
97-
attrs.push(' class="' + node.className + '"');
96+
var className = node.className || '';
97+
if (!showNgClass) {
98+
className = className.replace(/ng-[\w-]+\s*/g, '');
99+
}
100+
className = trim(className);
101+
if (className) {
102+
attrs.push(' class="' + className + '"');
103+
}
98104
for(var i=0; i<attributes.length; i++) {
99105
var attr = attributes[i];
100106
if(attr.name.match(/^ng:/) ||

0 commit comments

Comments
 (0)
This repository has been archived.