aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMisko Hevery2010-04-09 16:20:15 -0700
committerMisko Hevery2010-04-09 16:20:15 -0700
commit843bd355d25ebf2369aec79f98cb6704d38497e9 (patch)
tree3850d13b9ad8ab6c5dd975c20cf9d849c7429ed2 /src
parent41a5c408c242269bf31bc0b774c7304fdf7c2f1c (diff)
downloadangular.js-843bd355d25ebf2369aec79f98cb6704d38497e9.tar.bz2
various bug fixes
Diffstat (limited to 'src')
-rw-r--r--src/Angular.js2
-rw-r--r--src/Compiler.js14
-rw-r--r--src/Scope.js5
-rw-r--r--src/angular-bootstrap.js2
-rw-r--r--src/apis.js4
-rw-r--r--src/services.js26
-rw-r--r--src/widgets.js35
7 files changed, 54 insertions, 34 deletions
diff --git a/src/Angular.js b/src/Angular.js
index 7fb59f86..11ebc4bc 100644
--- a/src/Angular.js
+++ b/src/Angular.js
@@ -319,7 +319,7 @@ function merge(src, dst) {
}
function compile(element, parentScope, overrides) {
- var compiler = new Compiler(angularTextMarkup, angularAttrMarkup, angularDirective, angularWidget);
+ var compiler = new Compiler(angularTextMarkup, angularAttrMarkup, angularDirective, angularWidget),
$element = jqLite(element),
parent = extend({}, parentScope);
parent.$element = $element;
diff --git a/src/Compiler.js b/src/Compiler.js
index ae2bcdb6..8c95ee8e 100644
--- a/src/Compiler.js
+++ b/src/Compiler.js
@@ -143,8 +143,8 @@ Compiler.prototype = {
};
function eachTextNode(element, fn){
- var i, chldNodes = element[0].childNodes || [], size = chldNodes.length, chld;
- for (i = 0; i < size; i++) {
+ var i, chldNodes = element[0].childNodes || [], chld;
+ for (i = 0; i < chldNodes.length; i++) {
if(isTextNode(chld = chldNodes[i])) {
fn(jqLite(chld), i);
}
@@ -152,8 +152,8 @@ function eachTextNode(element, fn){
}
function eachNode(element, fn){
- var i, chldNodes = element[0].childNodes || [], size = chldNodes.length, chld;
- for (i = 0; i < size; i++) {
+ var i, chldNodes = element[0].childNodes || [], chld;
+ for (i = 0; i < chldNodes.length; i++) {
if(!isTextNode(chld = chldNodes[i])) {
fn(jqLite(chld), i);
}
@@ -161,11 +161,11 @@ function eachNode(element, fn){
}
function eachAttribute(element, fn){
- var i, attrs = element[0].attributes || [], size = attrs.length, chld, attr, attrValue = {};
- for (i = 0; i < size; i++) {
+ var i, attrs = element[0].attributes || [], chld, attr, attrValue = {};
+ for (i = 0; i < attrs.length; i++) {
attr = attrs[i];
attrValue[attr.name] = attr.value;
}
- foreach(attrValue, fn);
+ foreachSorted(attrValue, fn);
}
diff --git a/src/Scope.js b/src/Scope.js
index 0bc551c4..7529d726 100644
--- a/src/Scope.js
+++ b/src/Scope.js
@@ -179,7 +179,10 @@ function createScope(parent, services, existing) {
}
foreach(services, function(_, name){
- instance[name] = inject(name);
+ var service = inject(name);
+ if (service) {
+ instance[name] = service;
+ }
});
return instance;
diff --git a/src/angular-bootstrap.js b/src/angular-bootstrap.js
index d9633854..704c50e2 100644
--- a/src/angular-bootstrap.js
+++ b/src/angular-bootstrap.js
@@ -43,7 +43,7 @@
addScript("/JSON.js");
addScript("/Compiler.js");
addScript("/Scope.js");
- addScript("/jqlite.js");
+ addScript("/jqLite.js");
addScript("/Parser.js");
addScript("/Resource.js");
addScript("/Browser.js");
diff --git a/src/apis.js b/src/apis.js
index 3d0c5db3..5864ad60 100644
--- a/src/apis.js
+++ b/src/apis.js
@@ -14,7 +14,9 @@ var angularGlobal = {
var angularCollection = {
'size': size
};
-var angularObject = {};
+var angularObject = {
+ 'extend': extend
+};
var angularArray = {
'indexOf': indexOf,
'include': includes,
diff --git a/src/services.js b/src/services.js
index 6e1a1945..e2132f1c 100644
--- a/src/services.js
+++ b/src/services.js
@@ -7,6 +7,7 @@ var URL_MATCH = /^(file|ftp|http|https):\/\/(\w+:{0,1}\w*@)?([\w\.]*)(:([0-9]+))
var DEFAULT_PORTS = {'http': 80, 'https': 443, 'ftp':21};
angularService("$location", function(browser){
var scope = this, location = {parse:parse, toString:toString};
+ var lastHash;
function parse(url){
if (isDefined(url)) {
var match = URL_MATCH.exec(url);
@@ -18,16 +19,25 @@ angularService("$location", function(browser){
location.path = match[6];
location.search = parseKeyValue(match[8]);
location.hash = match[9];
- if (location.hash) location.hash = location.hash.substr(1);
+ if (location.hash)
+ location.hash = location.hash.substr(1);
+ lastHash = location.hash;
location.hashPath = match[11] || '';
location.hashSearch = parseKeyValue(match[13]);
}
}
}
function toString() {
- var hashKeyValue = toKeyValue(location.hashSearch),
- hash = (location.hashPath ? location.hashPath : '') + (hashKeyValue ? '?' + hashKeyValue : '');
- return location.href.split('#')[0] + '#' + (hash ? hash : '');
+ if (lastHash === location.hash) {
+ var hashKeyValue = toKeyValue(location.hashSearch),
+ hash = (location.hashPath ? location.hashPath : '') + (hashKeyValue ? '?' + hashKeyValue : ''),
+ url = location.href.split('#')[0] + '#' + (hash ? hash : '');
+ if (url !== location.href) parse(url);
+ return url;
+ } else {
+ parse(location.href.split('#')[0] + '#' + location.hash);
+ return toString();
+ }
}
browser.watchUrl(function(url){
parse(url);
@@ -35,11 +45,7 @@ angularService("$location", function(browser){
});
parse(browser.getUrl());
this.$onEval(PRIORITY_LAST, function(){
- var href = toString();
- if (href != location.href) {
- browser.setUrl(href);
- location.href = href;
- }
+ browser.setUrl(toString());
});
return location;
}, {inject: ['$browser']});
@@ -69,6 +75,7 @@ angularService("$hover", function(browser) {
tooltip.arrow.addClass('ng-arrow-right');
tooltip.arrow.css({left: (width + 1)+'px'});
tooltip.callout.css({
+ position: 'fixed',
left: (elementRect.left - arrowWidth - width - 4) + "px",
top: (elementRect.top - 3) + "px",
width: width + "px"
@@ -76,6 +83,7 @@ angularService("$hover", function(browser) {
} else {
tooltip.arrow.addClass('ng-arrow-left');
tooltip.callout.css({
+ position: 'fixed',
left: (elementRect.right + arrowWidth) + "px",
top: (elementRect.top - 3) + "px",
width: width + "px"
diff --git a/src/widgets.js b/src/widgets.js
index f87c1d02..f5f02813 100644
--- a/src/widgets.js
+++ b/src/widgets.js
@@ -27,9 +27,11 @@ function valueAccessor(scope, element) {
required = required || required === '';
if (!validator) throw "Validator named '" + validatorName + "' not found.";
function validate(value) {
- var error = required && !trim(value) ?
- "Required" :
- validator({state:scope, scope:{get:scope.$get, set:scope.$set}}, value);
+ var error,
+ validateScope = extend(new (extend(function(){}, {prototype:scope}))(), {$element:element});
+ error = required && !trim(value) ?
+ "Required" :
+ validator({state:validateScope, scope:{get:validateScope.$get, set:validateScope.$set}}, value);
if (error !== lastError) {
elementError(element, NG_VALIDATION_ERROR, error);
lastError = error;
@@ -190,7 +192,8 @@ angularWidget('NG:INCLUDE', function(element){
angularWidget('NG:SWITCH', function ngSwitch(element){
var compiler = this,
watchExpr = element.attr("on"),
- whenFn = ngSwitch[element.attr("using") || 'equals'];
+ whenExpr = (element.attr("using") || 'equals').split(":");
+ whenFn = ngSwitch[whenExpr.shift()];
changeExpr = element.attr('change') || '',
cases = [];
if (!whenFn) throw "Using expression '" + usingExpr + "' unknown.";
@@ -199,7 +202,11 @@ angularWidget('NG:SWITCH', function ngSwitch(element){
if (when) {
cases.push({
when: function(scope, value){
- return whenFn.call(scope, value, when);
+ var args = [value, when];
+ foreach(whenExpr, function(arg){
+ args.push(arg);
+ });
+ return whenFn.apply(scope, args);
},
change: changeExpr,
element: caseElement,
@@ -212,13 +219,10 @@ angularWidget('NG:SWITCH', function ngSwitch(element){
var scope = this, childScope;
this.$watch(watchExpr, function(value){
element.html('');
- childScope = null;
- var params = {};
+ childScope = createScope(scope);
foreach(cases, function(switchCase){
- if (switchCase.when(params, value)) {
+ if (switchCase.when(childScope, value)) {
element.append(switchCase.element);
- childScope = createScope(scope);
- extend(childScope, params);
childScope.$tryEval(switchCase.change, element);
switchCase.template(switchCase.element, childScope);
childScope.$init();
@@ -233,13 +237,15 @@ angularWidget('NG:SWITCH', function ngSwitch(element){
equals: function(on, when) {
return on == when;
},
- route: function(on, when) {
- var regex = '^' + when.replace(/[\.\\\(\)\^\$]/g, "\$1") + '$', params = [], self = this;
+ route: function(on, when, dstName) {
+ var regex = '^' + when.replace(/[\.\\\(\)\^\$]/g, "\$1") + '$',
+ params = [],
+ dst = {};
foreach(when.split(/\W/), function(param){
if (param) {
var paramRegExp = new RegExp(":" + param + "([\\W])");
if (regex.match(paramRegExp)) {
- regex = regex.replace(paramRegExp, "(.*)$1");
+ regex = regex.replace(paramRegExp, "([^\/]*)$1");
params.push(param);
}
}
@@ -247,8 +253,9 @@ angularWidget('NG:SWITCH', function ngSwitch(element){
var match = on.match(new RegExp(regex));
if (match) {
foreach(params, function(name, index){
- self[name] = match[index + 1];
+ dst[name] = match[index + 1];
});
+ if (dstName) this.$set(dstName, dst);
}
return match;
}