aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMisko Hevery2013-05-06 14:53:45 -0700
committerMisko Hevery2013-05-06 21:52:53 -0700
commit2c69a6735e8af5d1b9b73fd221274d374e8efdea (patch)
treecbd98482b47b4f3e09c231eaf9f4c8247b930a7b
parentc575a56fc5c6abcb8442398b53ddd7ea2433b785 (diff)
downloadangular.js-2c69a6735e8af5d1b9b73fd221274d374e8efdea.tar.bz2
fix($location): prevent navigation when event isDefaultPrevented
-rw-r--r--src/jqLite.js2
-rw-r--r--src/ng/location.js2
-rw-r--r--test/ng/locationSpec.js7
3 files changed, 9 insertions, 2 deletions
diff --git a/src/jqLite.js b/src/jqLite.js
index 0abae3d7..958242cd 100644
--- a/src/jqLite.js
+++ b/src/jqLite.js
@@ -560,7 +560,7 @@ function createEventHandler(element, events) {
}
event.isDefaultPrevented = function() {
- return event.defaultPrevented;
+ return event.defaultPrevented || event.returnValue == false;
};
forEach(events[type || event.type], function(fn) {
diff --git a/src/ng/location.js b/src/ng/location.js
index 4c31d0ad..4efa019c 100644
--- a/src/ng/location.js
+++ b/src/ng/location.js
@@ -527,7 +527,7 @@ function $LocationProvider(){
var absHref = elm.prop('href');
var rewrittenUrl = $location.$$rewrite(absHref);
- if (absHref && !elm.attr('target') && rewrittenUrl) {
+ if (absHref && !elm.attr('target') && rewrittenUrl && !event.isDefaultPrevented()) {
event.preventDefault();
if (rewrittenUrl != $browser.url()) {
// update location manually
diff --git a/test/ng/locationSpec.js b/test/ng/locationSpec.js
index cf7ceaf4..c4a88fd9 100644
--- a/test/ng/locationSpec.js
+++ b/test/ng/locationSpec.js
@@ -835,6 +835,12 @@ describe('$location', function() {
jqLite(link).attr('href', 'http://host.com/base/');
browserTrigger(link, 'click');
expectRewriteTo($browser, 'http://host.com/base/');
+
+ jqLite(link).
+ attr('href', 'http://host.com/base/foo').
+ bind('click', function(e) { e.preventDefault(); });
+ browserTrigger(link, 'click');
+ expect($browser.url()).toBe('http://host.com/base/');
}
);
});
@@ -1372,6 +1378,7 @@ describe('$location', function() {
expect(location.$$rewrite('http://other')).toEqual(undefined);
expect(location.$$rewrite('http://server/pre/')).toEqual('http://server/pre/');
expect(location.$$rewrite('http://server/pre/#otherPath')).toEqual('http://server/pre/#otherPath');
+ expect(location.$$rewrite('javascript:void(0)')).toEqual(undefined);
});
});