mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-05 21:54:42 +00:00
fix($location): prevent navigation when event isDefaultPrevented
This commit is contained in:
parent
c575a56fc5
commit
2c69a6735e
3 changed files with 9 additions and 2 deletions
|
|
@ -560,7 +560,7 @@ function createEventHandler(element, events) {
|
||||||
}
|
}
|
||||||
|
|
||||||
event.isDefaultPrevented = function() {
|
event.isDefaultPrevented = function() {
|
||||||
return event.defaultPrevented;
|
return event.defaultPrevented || event.returnValue == false;
|
||||||
};
|
};
|
||||||
|
|
||||||
forEach(events[type || event.type], function(fn) {
|
forEach(events[type || event.type], function(fn) {
|
||||||
|
|
|
||||||
|
|
@ -527,7 +527,7 @@ function $LocationProvider(){
|
||||||
var absHref = elm.prop('href');
|
var absHref = elm.prop('href');
|
||||||
var rewrittenUrl = $location.$$rewrite(absHref);
|
var rewrittenUrl = $location.$$rewrite(absHref);
|
||||||
|
|
||||||
if (absHref && !elm.attr('target') && rewrittenUrl) {
|
if (absHref && !elm.attr('target') && rewrittenUrl && !event.isDefaultPrevented()) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
if (rewrittenUrl != $browser.url()) {
|
if (rewrittenUrl != $browser.url()) {
|
||||||
// update location manually
|
// update location manually
|
||||||
|
|
|
||||||
|
|
@ -835,6 +835,12 @@ describe('$location', function() {
|
||||||
jqLite(link).attr('href', 'http://host.com/base/');
|
jqLite(link).attr('href', 'http://host.com/base/');
|
||||||
browserTrigger(link, 'click');
|
browserTrigger(link, 'click');
|
||||||
expectRewriteTo($browser, 'http://host.com/base/');
|
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://other')).toEqual(undefined);
|
||||||
expect(location.$$rewrite('http://server/pre/')).toEqual('http://server/pre/');
|
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('http://server/pre/#otherPath')).toEqual('http://server/pre/#otherPath');
|
||||||
|
expect(location.$$rewrite('javascript:void(0)')).toEqual(undefined);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue