fixed xhtml compatibility, fix console in chrome

This commit is contained in:
Misko Hevery 2010-07-20 16:55:32 -07:00
parent 7e96af0fdd
commit bebfbeac0a
9 changed files with 31 additions and 32 deletions

View file

@ -2,19 +2,9 @@
<html> <html>
<head> <head>
<script type="text/javascript" <script type="text/javascript"
src="http://angularjs.org/ng/js/angular-debug.js"></script> src="../src/angular-bootstrap.js#autobind"></script>
<script type="text/javascript">
(function(window, previousOnLoad){
window.onload = function(){
try {
(previousOnLoad||angular.noop)();
} catch(e) {}
angular.compile(window.document).$init();
};
})(window, window.onload);
</script>
</head> </head>
<body> <body ng:init="$window.$root = this">
Hello {{'World'}}! Hello {{'World'}}!
</body> </body>
</html> </html>

View file

@ -22,7 +22,7 @@ var consoleNode,
angularTextMarkup = extensionMap(angular, 'textMarkup'), angularTextMarkup = extensionMap(angular, 'textMarkup'),
angularAttrMarkup = extensionMap(angular, 'attrMarkup'), angularAttrMarkup = extensionMap(angular, 'attrMarkup'),
angularDirective = extensionMap(angular, 'directive'), angularDirective = extensionMap(angular, 'directive'),
angularWidget = extensionMap(angular, 'widget'), angularWidget = extensionMap(angular, 'widget', lowercase),
angularValidator = extensionMap(angular, 'validator'), angularValidator = extensionMap(angular, 'validator'),
angularFilter = extensionMap(angular, 'filter'), angularFilter = extensionMap(angular, 'filter'),
angularFormatter = extensionMap(angular, 'formatter'), angularFormatter = extensionMap(angular, 'formatter'),
@ -84,9 +84,10 @@ function inherit(parent, extra) {
function noop() {} function noop() {}
function identity($) {return $;} function identity($) {return $;}
function extensionMap(angular, name) { function extensionMap(angular, name, transform) {
var extPoint; var extPoint;
return angular[name] || (extPoint = angular[name] = function (name, fn, prop){ return angular[name] || (extPoint = angular[name] = function (name, fn, prop){
name = (transform || identity)(name);
if (isDefined(fn)) { if (isDefined(fn)) {
extPoint[name] = extend(fn, prop || {}); extPoint[name] = extend(fn, prop || {});
} }
@ -419,7 +420,7 @@ function angularInit(config){
function angularJsConfig(document) { function angularJsConfig(document) {
var filename = /(.*)\/angular(-(.*))?.js(#(.*))?/, var filename = /(.*)\/angular(-(.*))?.js(#(.*))?/,
scripts = document.getElementsByTagName("SCRIPT"), scripts = document.getElementsByTagName("script"),
match; match;
for(var j = 0; j < scripts.length; j++) { for(var j = 0; j < scripts.length; j++) {
match = (scripts[j].src || "").match(filename); match = (scripts[j].src || "").match(filename);

View file

@ -18,6 +18,8 @@ extend(angular, {
'foreach': foreach, 'foreach': foreach,
'noop':noop, 'noop':noop,
'bind':bind, 'bind':bind,
'toJson': toJson,
'fromJson': fromJson,
'identity':identity, 'identity':identity,
'isUndefined': isUndefined, 'isUndefined': isUndefined,
'isDefined': isDefined, 'isDefined': isDefined,

View file

@ -121,20 +121,25 @@ Compiler.prototype = {
descend: function(value){ if(isDefined(value)) descend = value; return descend;}, descend: function(value){ if(isDefined(value)) descend = value; return descend;},
directives: function(value){ if(isDefined(value)) directives = value; return directives;} directives: function(value){ if(isDefined(value)) directives = value; return directives;}
}; };
priority = element.attr('ng:eval-order') || priority || 0; try {
priority = element.attr('ng:eval-order') || priority || 0;
} catch (e) {
// for some reason IE throws error under some weird circumstances. so just assume nothing
priority = priority || 0;
}
if (isString(priority)) { if (isString(priority)) {
priority = PRIORITY[uppercase(priority)] || 0; priority = PRIORITY[uppercase(priority)] || 0;
} }
template = new Template(priority); template = new Template(priority);
eachAttribute(element, function(value, name){ eachAttribute(element, function(value, name){
if (!widget) { if (!widget) {
if (widget = self.widgets['@' + name]) { if (widget = self.widgets('@' + name)) {
widget = bind(selfApi, widget, value, element); widget = bind(selfApi, widget, value, element);
} }
} }
}); });
if (!widget) { if (!widget) {
if (widget = self.widgets[nodeName(element)]) { if (widget = self.widgets(nodeName(element))) {
widget = bind(selfApi, widget, element); widget = bind(selfApi, widget, element);
} }
} }

View file

@ -12,6 +12,7 @@ var angularGlobal = {
}; };
var angularCollection = { var angularCollection = {
'copy': copy,
'size': size, 'size': size,
'equals': equals 'equals': equals
}; };

View file

@ -65,13 +65,13 @@ angularService("$location", function(browser){
}, {inject: ['$browser']}); }, {inject: ['$browser']});
angularService("$log", function($window){ angularService("$log", function($window){
var console = $window.console, var console = $window.console || {log: noop, warn: noop, info: noop, error: noop},
log = console && console.log || noop; log = console.log || noop;
return { return {
log: log, log: bind(console, log),
warn: console && console.warn || log, warn: bind(console, console.warn || log),
info: console && console.info || log, info: bind(console, console.info || log),
error: console && console.error || log error: bind(console, console.error || log)
}; };
}, {inject:['$window']}); }, {inject:['$window']});

View file

@ -222,16 +222,16 @@ function inputWidgetSelector(element){
return INPUT_TYPE[lowercase(element[0].type)] || noop; return INPUT_TYPE[lowercase(element[0].type)] || noop;
} }
angularWidget('INPUT', inputWidgetSelector); angularWidget('input', inputWidgetSelector);
angularWidget('TEXTAREA', inputWidgetSelector); angularWidget('textarea', inputWidgetSelector);
angularWidget('BUTTON', inputWidgetSelector); angularWidget('button', inputWidgetSelector);
angularWidget('SELECT', function(element){ angularWidget('select', function(element){
this.descend(true); this.descend(true);
return inputWidgetSelector.call(this, element); return inputWidgetSelector.call(this, element);
}); });
angularWidget('NG:INCLUDE', function(element){ angularWidget('ng:include', function(element){
var compiler = this, var compiler = this,
srcExp = element.attr("src"), srcExp = element.attr("src"),
scopeExp = element.attr("scope") || ''; scopeExp = element.attr("scope") || '';
@ -265,7 +265,7 @@ angularWidget('NG:INCLUDE', function(element){
} }
}); });
var ngSwitch = angularWidget('NG:SWITCH', function (element){ var ngSwitch = angularWidget('ng:switch', function (element){
var compiler = this, var compiler = this,
watchExpr = element.attr("on"), watchExpr = element.attr("on"),
usingExpr = (element.attr("using") || 'equals'), usingExpr = (element.attr("using") || 'equals'),

View file

@ -22,7 +22,7 @@ describe('compiler', function(){
}; };
textMarkup = []; textMarkup = [];
attrMarkup = []; attrMarkup = [];
widgets = {}; widgets = extensionMap({}, 'widget');
compiler = new Compiler(textMarkup, attrMarkup, directives, widgets); compiler = new Compiler(textMarkup, attrMarkup, directives, widgets);
compile = function(html){ compile = function(html){
var e = jqLite("<div>" + html + "</div>"); var e = jqLite("<div>" + html + "</div>");

View file

@ -407,7 +407,7 @@ describe("widget", function(){
it("should match sandwich ids", function(){ it("should match sandwich ids", function(){
var scope = {}; var scope = {};
var match = angular.widget['NG:SWITCH'].route.call(scope, '/a/123/b', '/a/:id'); var match = angular.widget('NG:SWITCH').route.call(scope, '/a/123/b', '/a/:id');
expect(match).toBeFalsy(); expect(match).toBeFalsy();
}); });