Skip to content

Commit fe43430

Browse files
committed
tests work under jquery and without
1 parent 2a9669e commit fe43430

11 files changed

Lines changed: 36 additions & 30 deletions

File tree

jsTestDriver.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ server: http://localhost:9876
33
load:
44
- lib/jasmine/jasmine-0.10.3.js
55
- lib/jasmine-jstd-adapter/JasmineAdapter.js
6-
- lib/jquery/jquery-1.4.2.js
6+
# - lib/jquery/jquery-1.4.2.js
77
- src/Angular.js
88
- src/*.js
99
- src/scenario/_namespace.js

scenario/widgets.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
22
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
33
<head>
4-
<link rel="stylesheet" type="text/css" href="style.css"/><!--
4+
<link rel="stylesheet" type="text/css" href="style.css"/>
55
<script type="text/javascript" src="../lib/jquery/jquery-1.4.2.js"></script>
6-
--><script type="text/javascript" src="../src/angular-bootstrap.js#autobind"></script>
6+
<script type="text/javascript" src="../src/angular-bootstrap.js#autobind"></script>
77
</head>
88
<body ng:init="$window.$scope = this">
99
<table>

src/Angular.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,11 @@ function lowercase(value){ return isString(value) ? value.toLowerCase() : value;
112112
function uppercase(value){ return isString(value) ? value.toUpperCase() : value; }
113113
function trim(value) { return isString(value) ? value.replace(/^\s*/, '').replace(/\s*$/, '') : value; }
114114
function isElement(node) {
115-
return node && (node.nodeName || node instanceof JQLite || node instanceof jQuery);
115+
return node && (node.nodeName || node instanceof JQLite || (jQuery && node instanceof jQuery));
116+
}
117+
118+
function HTML(html) {
119+
this.html = html;
116120
}
117121

118122
if (msie) {

src/directives.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,17 @@ angularDirective("ng-bind", function(expression){
3030
value = this.$tryEval(expression, function(e){
3131
error = toJson(e);
3232
}),
33-
isElem = isElement(value);
34-
if (!isElem && isObject(value)) {
33+
isHtml = value instanceof HTML;
34+
if (!isHtml && isObject(value)) {
3535
value = toJson(value);
3636
}
3737
if (value != lastValue || error != lastError) {
3838
lastValue = value;
3939
lastError = error;
4040
elementError(element, NG_EXCEPTION, error);
4141
if (error) value = error;
42-
if (isElem) {
43-
element.html('');
44-
element.append(value);
42+
if (isHtml) {
43+
element.html(value.html);
4544
} else {
4645
element.text(value);
4746
}

src/filters.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,7 @@ foreach({
269269
},
270270

271271
'html': function(html){
272-
var div = jqLite('div');
273-
div.html(html);
274-
return div.children();
272+
return new HTML(html);
275273
},
276274

277275
'linky': function(text){
@@ -293,7 +291,7 @@ foreach({
293291
raw = raw.substring(i + url.length);
294292
}
295293
html.push(escapeHtml(raw));
296-
return jqLite(html.join(''));
294+
return new HTML(html.join(''));
297295
}
298296
}, function(v,k){angularFilter[k] = v;});
299297

src/jqLite.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,6 @@ if (msie) {
238238
},
239239

240240
trigger: function(type) {
241-
242-
if (nodeName(this) == 'INPUT' && (lowercase(this.attr('type')) == 'radio' || lowercase(this.attr('type')) == 'checkbox')) {
243-
this[0].checked = ! this[0].checked;
244-
}
245241
this[0].fireEvent('on' + type);
246242
}
247243
});

src/widgets.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function valueAccessor(scope, element) {
3232
value = element.val();
3333
force = true;
3434
}
35-
if (element[0].disabled || isString(element.attr('readonly'))) {
35+
if (element[0].disabled || element[0].readOnly) {
3636
elementError(element, NG_VALIDATION_ERROR, null);
3737
invalidWidgets.markValid(element);
3838
return value;

test/BinderTest.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,13 +588,13 @@ BinderTest.prototype.testItShouldSelectTheCorrectRadioBox = function() {
588588
var female = jqLite(c.node[0].childNodes[0]);
589589
var male = jqLite(c.node[0].childNodes[1]);
590590

591-
female.trigger('click');
591+
click(female);
592592
assertEquals("female", c.scope.sex);
593593
assertEquals(true, female[0].checked);
594594
assertEquals(false, male[0].checked);
595595
assertEquals("female", female.val());
596596

597-
male.trigger('click');
597+
click(male);
598598
assertEquals("male", c.scope.sex);
599599
assertEquals(false, female[0].checked);
600600
assertEquals(true, male[0].checked);

test/FiltersTest.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ FiltersTest.prototype.testGoogleChartApiEncode = function() {
133133
};
134134

135135
FiltersTest.prototype.testHtml = function() {
136-
var div = jqLite('<div></div>');
137-
div.append(angular.filter.html("a<b>c</b>d"));
138-
assertEquals("a<b>c</b>d", lowercase(div.html()));
136+
var html = angular.filter.html("a<b>c</b>d");
137+
expect(html instanceof HTML).toBeTruthy();
138+
expect(html.html).toEqual("a<b>c</b>d");
139139
};
140140

141141
FiltersTest.prototype.testLinky = function() {
@@ -145,7 +145,7 @@ FiltersTest.prototype.testLinky = function() {
145145
'(<a href="http://a/">http://a/</a>) ' +
146146
'&lt;<a href="http://a/">http://a/</a>&gt; ' +
147147
'<a href="http://1.2/v:~-123">http://1.2/v:~-123</a>. c',
148-
sortedHtml(linky("http://ab/ (http://a/) <http://a/> http://1.2/v:~-123. c")));
148+
linky("http://ab/ (http://a/) <http://a/> http://1.2/v:~-123. c").html);
149149
assertEquals(undefined, linky(undefined));
150150
};
151151

test/testabilityPatch.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,12 @@ function assertThrows(error, fn){
148148

149149
log = noop;
150150
error = noop;
151+
152+
function click(element) {
153+
element = jqLite(element);
154+
if ( (msie || jqLite == window.jQuery) &&
155+
nodeName(element) == 'INPUT' && (lowercase(element.attr('type')) == 'radio' || lowercase(element.attr('type')) == 'checkbox')) {
156+
element[0].checked = ! element[0].checked;
157+
}
158+
element.trigger('click');
159+
}

0 commit comments

Comments
 (0)