fixes to enable ie

This commit is contained in:
Misko Hevery
2010-04-20 18:14:13 -07:00
parent 259c2bba4b
commit 22d93e0a3b
14 changed files with 82 additions and 51 deletions

21
lib/nodeserver/server.js Normal file
View File

@@ -0,0 +1,21 @@
var sys = require('sys'),
http = require('http'),
fs = require('fs');
http.createServer(function (req, res) {
res.writeHead(200, {});
sys.p('GET ' + req.url);
var file = fs.createReadStream('.' + req.url);
file.addListener('data', bind(res, res.write));
file.addListener('error', function( error ){
sys.p(error);
res.end();
});
file.addListener('close', bind(res, res.end));
}).listen(8000);
sys.puts('Server running at http://127.0.0.1:8000/');
function bind(_this, _fn) {
return function(){
return _fn.apply(_this, arguments);
};
}

1
nodeserver.sh Executable file
View File

@@ -0,0 +1 @@
node lib/nodeserver/server.js

View File

@@ -1,11 +1,11 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<link rel="stylesheet" type="text/css" href="style.css"></link>
<link rel="stylesheet" type="text/css" href="style.css"/><!--
<script type="text/javascript" src="../lib/jquery/jquery-1.4.2.js"></script>
<script type="text/javascript" src="../src/angular-bootstrap.js#autobind"></script>
--><script type="text/javascript" src="../src/angular-bootstrap.js#autobind"></script>
</head>
<body ng-init="$window.$scope = this">
<body ng:init="$window.$scope = this">
<table>
<tr>
<th width="330">Description</th>
@@ -72,12 +72,12 @@
<tr><th colspan="3">Buttons</th></tr>
<tr>
<td>ng-change<br/>ng-click</td>
<td>
<form ng-init="button.count = 0">
<td ng:init="button.count = 0">
<form>
<input type="button" value="button" ng-change="button.count = button.count + 1"/> <br/>
<input type="submit" value="submit" ng-change="button.count = button.count + 1"/><br/>
<input type="image" src="" ng-change="button.count = button.count + 1"/><br/>
<a href="" ng-click="button.count = button.count + 1">action</a>
<a href="" ng:click="button.count = button.count + 1">action</a>
</form>
</td>
<td>button={{button}}</td>
@@ -93,5 +93,6 @@
<td></td>
</tr>
</table>
-->
</body>
</html>

View File

@@ -112,7 +112,8 @@ function uppercase(value){ return isString(value) ? value.toUpperCase() : value;
function trim(value) { return isString(value) ? value.replace(/^\s*/, '').replace(/\s*$/, '') : value; }
function nodeName(element) { return (element[0] || element).nodeName; }
function isElement(node) {
if (node && node[0]) node = node[0];
if (node && !node.item && isDefined(node.length) && isDefined(node[0]))
node = node[0];
return node && node.nodeName;
}

View File

@@ -29,7 +29,7 @@ Browser.prototype = {
bind: function() {
var self = this;
self.document.bind("mouseover", function(event){
self.hoverListener(jqLite(event.target), true);
self.hoverListener(jqLite(msie ? event.srcElement : event.target), true);
return true;
});
self.document.bind("mouseleave mouseout click dblclick keypress keyup", function(event){
@@ -43,8 +43,11 @@ Browser.prototype = {
},
addCss: function(url) {
var head = jqLite(this.document[0].getElementsByTagName('head')[0]),
link = jqLite('<link rel="stylesheet" type="text/css"></link>');
var doc = this.document[0],
head = jqLite(doc.getElementsByTagName('head')[0]),
link = jqLite(doc.createElement('link'));
link.attr('rel', 'stylesheet');
link.attr('type', 'text/css');
link.attr('href', url);
head.append(link);
},

View File

@@ -185,7 +185,7 @@ function eachAttribute(element, fn){
var i, attrs = element[0].attributes || [], chld, attr, name, value, attrValue = {};
for (i = 0; i < attrs.length; i++) {
attr = attrs[i];
name = attr.name;
name = attr.name.replace(':', '-');
value = attr.value;
if (msie && name == 'href') {
value = decodeURIComponent(element[0].getAttribute(name, 2));

View File

@@ -26,15 +26,20 @@ angularDirective("ng-bind", function(expression){
return function(element) {
var lastValue, lastError;
this.$onEval(function() {
var error, value = this.$tryEval(expression, function(e){
error = toJson(e);
});
var error,
value = this.$tryEval(expression, function(e){
error = toJson(e);
}),
isElem = isElement(value);
if (!isElem && isObject(value)) {
value = toJson(value);
}
if (value != lastValue || error != lastError) {
lastValue = value;
lastError = error;
elementError(element, NG_EXCEPTION, error);
if (error) value = error;
if (isElement(value)) {
if (isElem) {
element.html('');
element.append(value);
} else {
@@ -177,7 +182,7 @@ angularWidget("@ng-repeat", function(expression, element){
angularDirective("ng-click", function(expression, element){
return function(element){
var self = this;
element.click(function(){
element.bind('click', function(){
self.$tryEval(expression, element);
self.$root.$eval();
return false;

View File

@@ -37,14 +37,14 @@ function jqClearData(element) {
}
function JQLite(element) {
if (element.length && element.item) {
if (isElement(element)) {
this[0] = element;
this.length = 1;
} else if (isDefined(element.length) && element.item) {
for(var i=0; i < element.length; i++) {
this[i] = element[i];
}
this.length = element.length;
} else {
this[0] = element;
this.length = 1;
}
}
@@ -92,8 +92,13 @@ JQLite.prototype = {
bubbleEvent = bubbleEvent || fn.call(self, event);
});
if (!bubbleEvent) {
event.preventDefault();
event.stopPropagation();
if (msie) {
event.returnValue = false;
event.cancelBubble = true;
} else {
event.preventDefault();
event.stopPropagation();
}
}
};
eventHandler.fns = [];
@@ -109,13 +114,6 @@ JQLite.prototype = {
this[0].dispatchEvent(evnt);
},
click: function(fn) {
if (fn)
this.bind('click', fn);
else
this.trigger('click');
},
replaceWith: function(replaceNode) {
this[0].parentNode.replaceChild(jqLite(replaceNode)[0], this[0]);
},

View File

@@ -29,14 +29,14 @@ angular.scenario.WHEN = {
// emulate the browser behavior which causes it
// to be overridden at the end.
var checked = input.checked = !input.checked;
element.click();
element.trigger('click');
input.checked = checked;
},
select:function(){
var element = this.element(this.at);
var path = "option[value=" + this.option + "]";
var option = this.assert(element.find(path));
option[0].selected = !option[0].selected;
option[0].selected = !option[0].selected;
element.change();
}
};
@@ -48,7 +48,7 @@ angular.scenario.THEN = {
if (_.isArray(this.should_be))
should_be = JSON.stringify(should_be);
if (element.text() != should_be)
throw "Expected " + should_be +
throw "Expected " + should_be +
" but was " + element.text() + ".";
}
},

View File

@@ -1 +1 @@
java -jar lib/jstestdriver/JsTestDriver.jar --tests BinderTest
java -jar lib/jstestdriver/JsTestDriver.jar --tests all

View File

@@ -151,7 +151,7 @@ BinderTest.prototype.testInputTypeButtonActionExecutesInScope = function(){
c.scope.$set("person.save", function(){
savedCalled = true;
});
c.node.click();
c.node.trigger('click');
assertTrue(savedCalled);
};
@@ -162,7 +162,7 @@ BinderTest.prototype.testInputTypeButtonActionExecutesInScope2 = function(){
log += 'click;';
});
expect(log).toEqual('');
c.node.click();
c.node.trigger('click');
expect(log).toEqual('click;');
};
@@ -172,7 +172,7 @@ BinderTest.prototype.testButtonElementActionExecutesInScope = function(){
c.scope.$set("person.save", function(){
savedCalled = true;
});
c.node.click();
c.node.trigger('click');
assertTrue(savedCalled);
};
@@ -435,13 +435,13 @@ BinderTest.prototype.testActionOnAHrefThrowsError = function(){
throw {a:'abc', b:2};
};
var input = c.node;
input.click();
input.trigger('click');
assertEquals({a:"abc", b:2}, fromJson(input.attr('ng-exception')));
assertTrue("should have an error class", input.hasClass('ng-exception'));
// TODO: I think that exception should never get cleared so this portion of test makes no sense
//c.scope.action = noop;
//input.click();
//input.trigger('click');
//dump(input.attr('ng-error'));
//assertFalse('error class should be cleared', input.hasClass('ng-exception'));
};
@@ -574,10 +574,10 @@ BinderTest.prototype.testItShouldDisplayErrorWhenActionIsSyntacticlyIncorect = f
var first = jqLite(c.node[0].childNodes[0]);
var second = jqLite(c.node[0].childNodes[1]);
first.click();
first.trigger('click');
assertEquals("ABC", c.scope.greeting);
second.click();
second.trigger('click');
assertTrue(second.hasClass("ng-exception"));
};

View File

@@ -75,21 +75,22 @@ describe('compiler', function(){
it('should allow creation of templates', function(){
directives.duplicate = function(expr, element){
var parent = element.parent();
element.replaceWith(document.createComment("marker"));
element.removeAttr("duplicate");
var template = this.compile(element);
return function(marker) {
this.$onEval(function() {
marker.after(template(element.clone()).element);
marker.after(template(element.clone()).$element);
});
};
};
var scope = compile('before<span duplicate="expr">x</span>after');
expect(sortedHtml(scope.$element)).toEqual('<div>before<#comment></#comment>after</div>');
expect(sortedHtml(scope.$element)).toEqual('<div>before<#comment></#comment><span>x</span>after</div>');
scope.$eval();
expect(sortedHtml(scope.$element)).toEqual('<div>before<#comment></#comment>after</div>');
expect(sortedHtml(scope.$element)).toEqual('<div>before<#comment></#comment><span>x</span><span>x</span>after</div>');
scope.$eval();
expect(sortedHtml(scope.$element)).toEqual('<div>before<#comment></#comment>after</div>');
expect(sortedHtml(scope.$element)).toEqual('<div>before<#comment></#comment><span>x</span><span>x</span><span>x</span>after</div>');
});
it('should process markup before directives', function(){

View File

@@ -133,7 +133,7 @@ describe("directives", function(){
scope.$eval();
expect(scope.$get('clicked')).toBeFalsy();
element.click();
element.trigger('click');
expect(scope.$get('clicked')).toEqual(true);
});

View File

@@ -136,23 +136,23 @@ describe("input widget", function(){
it('should call ng-change on button click', function(){
compile('<input type="button" value="Click Me" ng-change="clicked = true"/>');
element.click();
element.trigger('click');
expect(scope.$get('clicked')).toEqual(true);
});
it('should support button alias', function(){
compile('<button ng-change="clicked = true">Click Me</button>');
element.click();
element.trigger('click');
expect(scope.$get('clicked')).toEqual(true);
});
it('should type="checkbox"', function(){
compile('<input type="checkbox" name="checkbox" checked ng-change="action = true"/>');
expect(scope.checkbox).toEqual(true);
trigger(element, 'click');
element.trigger('click');
expect(scope.checkbox).toEqual(false);
expect(scope.action).toEqual(true);
trigger(element, 'click');
element.trigger('click');
expect(scope.checkbox).toEqual(true);
});
@@ -176,7 +176,7 @@ describe("input widget", function(){
expect(b.checked).toEqual(true);
expect(scope.clicked).not.toBeDefined();
trigger(a, 'click');
jqLite(a).trigger('click');
expect(scope.chose).toEqual('A');
expect(scope.clicked).toEqual(1);
});
@@ -218,7 +218,7 @@ describe("input widget", function(){
it('should report error on ng-change exception', function(){
compile('<button ng-change="a-2=x">click</button>');
element.click();
element.trigger('click');
expect(element.hasClass('ng-exception')).toBeTruthy();
});