Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 843bd35

Browse files
author
Misko Hevery
committed
various bug fixes
1 parent 41a5c40 commit 843bd35

18 files changed

+320
-181
lines changed

angular-debug.js

Lines changed: 53 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ function merge(src, dst) {
343343
}
344344

345345
function compile(element, parentScope, overrides) {
346-
var compiler = new Compiler(angularTextMarkup, angularAttrMarkup, angularDirective, angularWidget);
346+
var compiler = new Compiler(angularTextMarkup, angularAttrMarkup, angularDirective, angularWidget),
347347
$element = jqLite(element),
348348
parent = extend({}, parentScope);
349349
parent.$element = $element;
@@ -641,30 +641,30 @@ Compiler.prototype = {
641641
};
642642

643643
function eachTextNode(element, fn){
644-
var i, chldNodes = element[0].childNodes || [], size = chldNodes.length, chld;
645-
for (i = 0; i < size; i++) {
644+
var i, chldNodes = element[0].childNodes || [], chld;
645+
for (i = 0; i < chldNodes.length; i++) {
646646
if(isTextNode(chld = chldNodes[i])) {
647647
fn(jqLite(chld), i);
648648
}
649649
}
650650
}
651651

652652
function eachNode(element, fn){
653-
var i, chldNodes = element[0].childNodes || [], size = chldNodes.length, chld;
654-
for (i = 0; i < size; i++) {
653+
var i, chldNodes = element[0].childNodes || [], chld;
654+
for (i = 0; i < chldNodes.length; i++) {
655655
if(!isTextNode(chld = chldNodes[i])) {
656656
fn(jqLite(chld), i);
657657
}
658658
}
659659
}
660660

661661
function eachAttribute(element, fn){
662-
var i, attrs = element[0].attributes || [], size = attrs.length, chld, attr, attrValue = {};
663-
for (i = 0; i < size; i++) {
662+
var i, attrs = element[0].attributes || [], chld, attr, attrValue = {};
663+
for (i = 0; i < attrs.length; i++) {
664664
attr = attrs[i];
665665
attrValue[attr.name] = attr.value;
666666
}
667-
foreach(attrValue, fn);
667+
foreachSorted(attrValue, fn);
668668
}
669669

670670
function getter(instance, path, unboundFn) {
@@ -848,7 +848,10 @@ function createScope(parent, services, existing) {
848848
}
849849

850850
foreach(services, function(_, name){
851-
instance[name] = inject(name);
851+
var service = inject(name);
852+
if (service) {
853+
instance[name] = service;
854+
}
852855
});
853856

854857
return instance;
@@ -2026,7 +2029,9 @@ var angularGlobal = {
20262029
var angularCollection = {
20272030
'size': size
20282031
};
2029-
var angularObject = {};
2032+
var angularObject = {
2033+
'extend': extend
2034+
};
20302035
var angularArray = {
20312036
'indexOf': indexOf,
20322037
'include': includes,
@@ -3135,9 +3140,11 @@ function valueAccessor(scope, element) {
31353140
required = required || required === '';
31363141
if (!validator) throw "Validator named '" + validatorName + "' not found.";
31373142
function validate(value) {
3138-
var error = required && !trim(value) ?
3139-
"Required" :
3140-
validator({state:scope, scope:{get:scope.$get, set:scope.$set}}, value);
3143+
var error,
3144+
validateScope = extend(new (extend(function(){}, {prototype:scope}))(), {$element:element});
3145+
error = required && !trim(value) ?
3146+
"Required" :
3147+
validator({state:validateScope, scope:{get:validateScope.$get, set:validateScope.$set}}, value);
31413148
if (error !== lastError) {
31423149
elementError(element, NG_VALIDATION_ERROR, error);
31433150
lastError = error;
@@ -3298,7 +3305,8 @@ angularWidget('NG:INCLUDE', function(element){
32983305
angularWidget('NG:SWITCH', function ngSwitch(element){
32993306
var compiler = this,
33003307
watchExpr = element.attr("on"),
3301-
whenFn = ngSwitch[element.attr("using") || 'equals'];
3308+
whenExpr = (element.attr("using") || 'equals').split(":");
3309+
whenFn = ngSwitch[whenExpr.shift()];
33023310
changeExpr = element.attr('change') || '',
33033311
cases = [];
33043312
if (!whenFn) throw "Using expression '" + usingExpr + "' unknown.";
@@ -3307,7 +3315,11 @@ angularWidget('NG:SWITCH', function ngSwitch(element){
33073315
if (when) {
33083316
cases.push({
33093317
when: function(scope, value){
3310-
return whenFn.call(scope, value, when);
3318+
var args = [value, when];
3319+
foreach(whenExpr, function(arg){
3320+
args.push(arg);
3321+
});
3322+
return whenFn.apply(scope, args);
33113323
},
33123324
change: changeExpr,
33133325
element: caseElement,
@@ -3320,13 +3332,10 @@ angularWidget('NG:SWITCH', function ngSwitch(element){
33203332
var scope = this, childScope;
33213333
this.$watch(watchExpr, function(value){
33223334
element.html('');
3323-
childScope = null;
3324-
var params = {};
3335+
childScope = createScope(scope);
33253336
foreach(cases, function(switchCase){
3326-
if (switchCase.when(params, value)) {
3337+
if (switchCase.when(childScope, value)) {
33273338
element.append(switchCase.element);
3328-
childScope = createScope(scope);
3329-
extend(childScope, params);
33303339
childScope.$tryEval(switchCase.change, element);
33313340
switchCase.template(switchCase.element, childScope);
33323341
childScope.$init();
@@ -3341,22 +3350,25 @@ angularWidget('NG:SWITCH', function ngSwitch(element){
33413350
equals: function(on, when) {
33423351
return on == when;
33433352
},
3344-
route: function(on, when) {
3345-
var regex = '^' + when.replace(/[\.\\\(\)\^\$]/g, "\$1") + '$', params = [], self = this;
3353+
route: function(on, when, dstName) {
3354+
var regex = '^' + when.replace(/[\.\\\(\)\^\$]/g, "\$1") + '$',
3355+
params = [],
3356+
dst = {};
33463357
foreach(when.split(/\W/), function(param){
33473358
if (param) {
33483359
var paramRegExp = new RegExp(":" + param + "([\\W])");
33493360
if (regex.match(paramRegExp)) {
3350-
regex = regex.replace(paramRegExp, "(.*)$1");
3361+
regex = regex.replace(paramRegExp, "([^\/]*)$1");
33513362
params.push(param);
33523363
}
33533364
}
33543365
});
33553366
var match = on.match(new RegExp(regex));
33563367
if (match) {
33573368
foreach(params, function(name, index){
3358-
self[name] = match[index + 1];
3369+
dst[name] = match[index + 1];
33593370
});
3371+
if (dstName) this.$set(dstName, dst);
33603372
}
33613373
return match;
33623374
}
@@ -3370,6 +3382,7 @@ var URL_MATCH = /^(file|ftp|http|https):\/\/(\w+:{0,1}\w*@)?([\w\.]*)(:([0-9]+))
33703382
var DEFAULT_PORTS = {'http': 80, 'https': 443, 'ftp':21};
33713383
angularService("$location", function(browser){
33723384
var scope = this, location = {parse:parse, toString:toString};
3385+
var lastHash;
33733386
function parse(url){
33743387
if (isDefined(url)) {
33753388
var match = URL_MATCH.exec(url);
@@ -3381,28 +3394,33 @@ angularService("$location", function(browser){
33813394
location.path = match[6];
33823395
location.search = parseKeyValue(match[8]);
33833396
location.hash = match[9];
3384-
if (location.hash) location.hash = location.hash.substr(1);
3397+
if (location.hash)
3398+
location.hash = location.hash.substr(1);
3399+
lastHash = location.hash;
33853400
location.hashPath = match[11] || '';
33863401
location.hashSearch = parseKeyValue(match[13]);
33873402
}
33883403
}
33893404
}
33903405
function toString() {
3391-
var hashKeyValue = toKeyValue(location.hashSearch),
3392-
hash = (location.hashPath ? location.hashPath : '') + (hashKeyValue ? '?' + hashKeyValue : '');
3393-
return location.href.split('#')[0] + '#' + (hash ? hash : '');
3406+
if (lastHash === location.hash) {
3407+
var hashKeyValue = toKeyValue(location.hashSearch),
3408+
hash = (location.hashPath ? location.hashPath : '') + (hashKeyValue ? '?' + hashKeyValue : ''),
3409+
url = location.href.split('#')[0] + '#' + (hash ? hash : '');
3410+
if (url !== location.href) parse(url);
3411+
return url;
3412+
} else {
3413+
parse(location.href.split('#')[0] + '#' + location.hash);
3414+
return toString();
3415+
}
33943416
}
33953417
browser.watchUrl(function(url){
33963418
parse(url);
33973419
scope.$root.$eval();
33983420
});
33993421
parse(browser.getUrl());
34003422
this.$onEval(PRIORITY_LAST, function(){
3401-
var href = toString();
3402-
if (href != location.href) {
3403-
browser.setUrl(href);
3404-
location.href = href;
3405-
}
3423+
browser.setUrl(toString());
34063424
});
34073425
return location;
34083426
}, {inject: ['$browser']});
@@ -3432,13 +3450,15 @@ angularService("$hover", function(browser) {
34323450
tooltip.arrow.addClass('ng-arrow-right');
34333451
tooltip.arrow.css({left: (width + 1)+'px'});
34343452
tooltip.callout.css({
3453+
position: 'fixed',
34353454
left: (elementRect.left - arrowWidth - width - 4) + "px",
34363455
top: (elementRect.top - 3) + "px",
34373456
width: width + "px"
34383457
});
34393458
} else {
34403459
tooltip.arrow.addClass('ng-arrow-left');
34413460
tooltip.callout.css({
3461+
position: 'fixed',
34423462
left: (elementRect.right + arrowWidth) + "px",
34433463
top: (elementRect.top - 3) + "px",
34443464
width: width + "px"

example/temp.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3+
<head>
4+
<script type="text/javascript" src="../src/angular-bootstrap.js#autobind"></script>
5+
</head>
6+
<body>
7+
<a href="#"> {{'first'}}<br/>{{'second'}}</a>
8+
</body>
9+
</html>

jsTestDriver.conf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
server: http://localhost:9876
22

33
load:
4-
- lib/jasmine/jasmine-0.10.1.js
4+
- lib/jasmine/jasmine-0.10.3.js
55
- lib/jasmine-jstd-adapter/JasmineAdapter.js
6-
- lib/webtoolkit/webtoolkit.base64.js
6+
# - lib/webtoolkit/webtoolkit.base64.js
77
# - lib/jquery/jquery-1.4.2.js
88
# - lib/underscore/underscore.js
99
- src/Angular.js

0 commit comments

Comments
 (0)