fix broken build, fix #autobind and css loading

This commit is contained in:
Misko Hevery 2010-07-29 15:26:10 -07:00
parent 1b768b8443
commit 03aac8b0ab
6 changed files with 31 additions and 17 deletions

View file

@ -2,7 +2,7 @@
<html xmlns:ng="http://angularjs.org">
<head>
<script type="text/javascript"
src="../src/angular-bootstrap.js#autobind"></script>
src="../angular-debug.js" ng:autobind ng:css="css/angular.css"></script>
</head>
<body ng:init="$window.$root = this">
@ -17,10 +17,7 @@ function TicTacToeCntl(){
'cursor': 'pointer'
};
this.reset();
this.$watch('$location.hashPath', this.setMemento);
this.$onEval(function(){
this.$location.hashPath = this.getMemento();
});
this.$watch('$location.hashPath', this.readUrl);
}
TicTacToeCntl.prototype = {
dropPiece: function(row, col) {
@ -28,6 +25,7 @@ TicTacToeCntl.prototype = {
this.board[row][col] = this.nextMove;
this.nextMove = this.nextMove == 'X' ? 'O' : 'X';
this.grade();
this.setUrl();
}
},
reset: function(){
@ -38,6 +36,7 @@ TicTacToeCntl.prototype = {
];
this.nextMove = 'X';
this.winner = '';
this.setUrl();
},
grade: function(){
var b = this.board;
@ -50,14 +49,14 @@ TicTacToeCntl.prototype = {
function diagonal(i) { return same(b[0][1-i], b[1][1], b[2][1+i]);}
function same(a, b, c) { return (a==b && b==c) ? a : '';};
},
getMemento: function(){
setUrl: function(){
var rows = [];
angular.foreach(this.board, function(row){
rows.push(row.join(','));
});
return rows.join(';') + '/' + this.nextMove;
this.$location.hashPath = rows.join(';') + '/' + this.nextMove;
},
setMemento: function(value) {
readUrl: function(value) {
if (value) {
value = value.split('/');
this.nextMove = value[1];

View file

@ -6,6 +6,7 @@ load:
- lib/jquery/jquery-1.4.2.js
- test/jquery_alias.js
- src/Angular.js
- src/JSON.js
- src/*.js
- src/scenario/Runner.js
- src/scenario/*.js

View file

@ -6,6 +6,7 @@ load:
- lib/jquery/jquery-1.4.2.js
- test/jquery_remove.js
- src/Angular.js
- src/JSON.js
- src/*.js
- src/scenario/Runner.js
- src/scenario/*.js

View file

@ -369,22 +369,35 @@ function toKeyValue(obj) {
function angularInit(config){
if (config.autobind) {
var scope = compile(window.document, null, {'$config':config});
// TODO default to the source of angular.js
scope.$browser.addCss('css/angular.css');
var scope = compile(window.document, null, {'$config':config});
if (config.css)
scope.$browser.addCss(config.base_url + config.css);
scope.$init();
}
}
function angularJsConfig(document) {
var filename = /(.*)\/angular(-(.*))?.js(#(.*))?/,
function angularJsConfig(document, config) {
var filename = /^(.*)\/angular(-([^\/]*))?.js(#(.*))?$/,
scripts = document.getElementsByTagName("script"),
match;
config = extend({
base_url: '',
css: '../css/angular.css'
}, config);
for(var j = 0; j < scripts.length; j++) {
match = (scripts[j].src || "").match(filename);
if (match) {
return match[5];
config.base_url = match[1] + '/';
extend(match, config, toKeyValue(match[5]));
eachAttribute(jqLite(scripts[j]), function(value, name){
if (/^ng:/.exec(name)) {
name = name.substring(3).replace(/-/g, '_');
if (name == 'autobind') value = true;
config[name] = value;
}
});
}
}
return "";
return config;
}

View file

@ -22,7 +22,7 @@
* THE SOFTWARE.
*/
(function(previousOnLoad){
var filename = /(.*)\/angular-(.*).js(#.*)?/,
var filename = /^(.*)\/angular-bootstrap.js(#.*)?$/,
scripts = document.getElementsByTagName("SCRIPT"),
serverPath,
match;
@ -61,7 +61,7 @@
try {
if (previousOnLoad) previousOnLoad();
} catch(e) {}
angularInit(parseKeyValue(angularJsConfig(document)));
angularInit(angularJsConfig(document));
};
})(window.onload);

View file

@ -3,7 +3,7 @@
try {
if (previousOnLoad) previousOnLoad();
} catch(e) {}
angularInit(parseKeyValue(angularJsConfig(document)));
angularInit(angularJsConfig(document));
};
})(window, document, window.onload);