diff --git a/angular-debug.js b/angular-debug.js index c3f419f7..dd74428a 100644 --- a/angular-debug.js +++ b/angular-debug.js @@ -343,7 +343,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; @@ -641,8 +641,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); } @@ -650,8 +650,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); } @@ -659,12 +659,12 @@ 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); } function getter(instance, path, unboundFn) { @@ -848,7 +848,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; @@ -2026,7 +2029,9 @@ var angularGlobal = { var angularCollection = { 'size': size }; -var angularObject = {}; +var angularObject = { + 'extend': extend +}; var angularArray = { 'indexOf': indexOf, 'include': includes, @@ -3135,9 +3140,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; @@ -3298,7 +3305,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."; @@ -3307,7 +3315,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, @@ -3320,13 +3332,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(); @@ -3341,13 +3350,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); } } @@ -3355,8 +3366,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; } @@ -3370,6 +3382,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); @@ -3381,16 +3394,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); @@ -3398,11 +3420,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']}); @@ -3432,6 +3450,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" @@ -3439,6 +3458,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/example/temp.html b/example/temp.html new file mode 100644 index 00000000..3580249d --- /dev/null +++ b/example/temp.html @@ -0,0 +1,9 @@ + + +
+ + + + {{'first'}}jasmine.undefined instead of undefined, since undefinedjasmine.undefined instead of undefined, since undefined is just
* a plain old variable and may be redefined by somebody else.
*
* @private
@@ -89,7 +89,38 @@ jasmine.getEnv = function() {
* @returns {Boolean}
*/
jasmine.isArray_ = function(value) {
- return Object.prototype.toString.apply(value) === '[object Array]';
+ return jasmine.isA_("Array", value);
+};
+
+/**
+ * @ignore
+ * @private
+ * @param value
+ * @returns {Boolean}
+ */
+jasmine.isString_ = function(value) {
+ return jasmine.isA_("String", value);
+};
+
+/**
+ * @ignore
+ * @private
+ * @param value
+ * @returns {Boolean}
+ */
+jasmine.isNumber_ = function(value) {
+ return jasmine.isA_("Number", value);
+};
+
+/**
+ * @ignore
+ * @private
+ * @param {String} typeName
+ * @param value
+ * @returns {Boolean}
+ */
+jasmine.isA_ = function(typeName, value) {
+ return Object.prototype.toString.apply(value) === '[object ' + typeName + ']';
};
/**
@@ -527,6 +558,7 @@ jasmine.XmlHttpRequest = (typeof XMLHttpRequest == "undefined") ? function() {
*
* @param {String} url path to the file to include
* @param {Boolean} opt_global
+ * @deprecated We suggest you use a different method of including JS source files. jasmine.include will be removed soon.
*/
jasmine.include = function(url, opt_global) {
if (opt_global) {
@@ -659,6 +691,18 @@ jasmine.Env.prototype.version = function () {
}
};
+/**
+ * @returns string containing jasmine version build info, if set.
+ */
+jasmine.Env.prototype.versionString = function() {
+ if (jasmine.version_) {
+ var version = this.version();
+ return version.major + "." + version.minor + "." + version.build + " revision " + version.revision;
+ } else {
+ return "version unknown";
+ }
+};
+
/**
* @returns a sequential integer starting at 0
*/
@@ -794,6 +838,12 @@ jasmine.Env.prototype.equals_ = function(a, b, mismatchKeys, mismatchValues) {
mismatchKeys = mismatchKeys || [];
mismatchValues = mismatchValues || [];
+ for (var i = 0; i < this.equalityTesters_.length; i++) {
+ var equalityTester = this.equalityTesters_[i];
+ var result = equalityTester(a, b, this, mismatchKeys, mismatchValues);
+ if (result !== jasmine.undefined) return result;
+ }
+
if (a === b) return true;
if (a === jasmine.undefined || a === null || b === jasmine.undefined || b === null) {
@@ -816,14 +866,16 @@ jasmine.Env.prototype.equals_ = function(a, b, mismatchKeys, mismatchValues) {
return b.matches(a);
}
- if (typeof a === "object" && typeof b === "object") {
- return this.compareObjects_(a, b, mismatchKeys, mismatchValues);
+ if (jasmine.isString_(a) && jasmine.isString_(b)) {
+ return (a == b);
}
- for (var i = 0; i < this.equalityTesters_.length; i++) {
- var equalityTester = this.equalityTesters_[i];
- var result = equalityTester(a, b, this, mismatchKeys, mismatchValues);
- if (result !== jasmine.undefined) return result;
+ if (jasmine.isNumber_(a) && jasmine.isNumber_(b)) {
+ return (a == b);
+ }
+
+ if (typeof a === "object" && typeof b === "object") {
+ return this.compareObjects_(a, b, mismatchKeys, mismatchValues);
}
//Straight check
@@ -1009,11 +1061,13 @@ jasmine.Matchers = function(env, actual, spec, opt_isNot) {
this.reportWasCalled_ = false;
};
+// todo: @deprecated as of Jasmine 0.11, remove soon [xw]
jasmine.Matchers.pp = function(str) {
- return jasmine.util.htmlEscape(jasmine.pp(str));
+ throw new Error("jasmine.Matchers.pp() is no longer supported, please use jasmine.pp() instead!");
+ this.report();
};
-/** @deprecated */
+/** @deprecated Deprecated as of Jasmine 0.10. Rewrite your custom matchers to return true or false. */
jasmine.Matchers.prototype.report = function(result, failing_message, details) {
// todo: report a deprecation warning [xw]
@@ -1180,7 +1234,7 @@ jasmine.Matchers.prototype.wasCalled = function() {
}
if (!jasmine.isSpy(this.actual)) {
- throw new Error('Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.');
+ throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.');
}
this.message = function() {
@@ -1199,7 +1253,7 @@ jasmine.Matchers.prototype.wasNotCalled = function() {
}
if (!jasmine.isSpy(this.actual)) {
- throw new Error('Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.');
+ throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.');
}
this.message = function() {
@@ -1218,7 +1272,7 @@ jasmine.Matchers.prototype.wasNotCalled = function() {
jasmine.Matchers.prototype.wasCalledWith = function() {
var expectedArgs = jasmine.util.argsToArray(arguments);
if (!jasmine.isSpy(this.actual)) {
- throw new Error('Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.');
+ throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.');
}
this.message = function() {
if (this.actual.callCount == 0) {
@@ -1234,7 +1288,7 @@ jasmine.Matchers.prototype.wasCalledWith = function() {
jasmine.Matchers.prototype.wasNotCalledWith = function() {
var expectedArgs = jasmine.util.argsToArray(arguments);
if (!jasmine.isSpy(this.actual)) {
- throw new Error('Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.');
+ throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.');
}
this.message = function() {
@@ -1882,8 +1936,7 @@ jasmine.Spec.prototype.finish = function(onComplete) {
}
};
-jasmine.Spec.prototype.after = function(doAfter, test) {
-
+jasmine.Spec.prototype.after = function(doAfter) {
if (this.queue.isRunning()) {
this.queue.add(new jasmine.Block(this.env, doAfter, this));
} else {
@@ -1911,23 +1964,25 @@ jasmine.Spec.prototype.execute = function(onComplete) {
jasmine.Spec.prototype.addBeforesAndAftersToQueue = function() {
var runner = this.env.currentRunner();
+ var i;
+
for (var suite = this.suite; suite; suite = suite.parentSuite) {
- for (var i = 0; i < suite.before_.length; i++) {
+ for (i = 0; i < suite.before_.length; i++) {
this.queue.addBefore(new jasmine.Block(this.env, suite.before_[i], this));
}
}
- for (var i = 0; i < runner.before_.length; i++) {
+ for (i = 0; i < runner.before_.length; i++) {
this.queue.addBefore(new jasmine.Block(this.env, runner.before_[i], this));
}
for (i = 0; i < this.afterCallbacks.length; i++) {
this.queue.add(new jasmine.Block(this.env, this.afterCallbacks[i], this));
}
for (suite = this.suite; suite; suite = suite.parentSuite) {
- for (var i = 0; i < suite.after_.length; i++) {
+ for (i = 0; i < suite.after_.length; i++) {
this.queue.add(new jasmine.Block(this.env, suite.after_[i], this));
}
}
- for (var i = 0; i < runner.after_.length; i++) {
+ for (i = 0; i < runner.after_.length; i++) {
this.queue.add(new jasmine.Block(this.env, runner.after_[i], this));
}
};
@@ -2271,6 +2326,6 @@ window.clearInterval = function(timeoutKey) {
jasmine.version_= {
"major": 0,
"minor": 10,
- "build": 1,
- "revision": 1267503060
+ "build": 3,
+ "revision": 1270162784
};
diff --git a/lib/jstestdriver/JsTestDriver.jar b/lib/jstestdriver/JsTestDriver.jar
index ead31593..00482eda 100644
Binary files a/lib/jstestdriver/JsTestDriver.jar and b/lib/jstestdriver/JsTestDriver.jar differ
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;
}
diff --git a/test/ApiTest.js b/test/ApiTest.js
index 19860822..5d85987b 100644
--- a/test/ApiTest.js
+++ b/test/ApiTest.js
@@ -250,3 +250,7 @@ ApiTest.prototype.testStringFromUTC = function(){
assertEquals("2003-09-10T13:02:03Z", angular.Date.toString(date));
assertEquals("str", angular.String.toDate("str"));
};
+
+ApiTest.prototype.testObjectShouldHaveExtend = function(){
+ assertEquals(angular.Object.extend, extend);
+};
diff --git a/test/ValidatorsTest.js b/test/ValidatorsTest.js
index 2b2f6753..17c67d38 100644
--- a/test/ValidatorsTest.js
+++ b/test/ValidatorsTest.js
@@ -12,7 +12,7 @@ ValidatorTest.prototype.testItShouldHaveThisSet = function() {
scope.$init();
assertEquals('misko', validator.first);
assertEquals('hevery', validator.last);
- assertSame(scope, validator._this);
+ assertSame(scope, validator._this.__proto__);
delete angular.validator.myValidator;
scope.$element.remove();
};
diff --git a/test/markupSpec.js b/test/markupSpec.js
index e416b8ea..a1112490 100644
--- a/test/markupSpec.js
+++ b/test/markupSpec.js
@@ -47,6 +47,11 @@ describe("markups", function(){
expect(element.html()).toEqual('');
});
+ it('should process all bindings when we have leading space', function(){
+ compile(' {{a}}