diff options
Diffstat (limited to 'src/ng')
| -rw-r--r-- | src/ng/directive/booleanAttrs.js | 14 | ||||
| -rw-r--r-- | src/ng/location.js | 22 |
2 files changed, 15 insertions, 21 deletions
diff --git a/src/ng/directive/booleanAttrs.js b/src/ng/directive/booleanAttrs.js index e25b259c..5da98ef4 100644 --- a/src/ng/directive/booleanAttrs.js +++ b/src/ng/directive/booleanAttrs.js @@ -6,7 +6,7 @@ * @restrict A * * @description - * Using <angular/> markup like {{hash}} in an href attribute makes + * Using Angular markup like {{hash}} in an href attribute makes * the page open to a wrong URL, if the user clicks that link before * angular has a chance to replace the {{hash}} with actual URL, the * link will be broken and will most likely return a 404 error. @@ -32,10 +32,10 @@ <input ng-model="value" /><br /> <a id="link-1" href ng-click="value = 1">link 1</a> (link, don't reload)<br /> <a id="link-2" href="" ng-click="value = 2">link 2</a> (link, don't reload)<br /> - <a id="link-3" ng-href="/{{'123'}}" ng-ext-link>link 3</a> (link, reload!)<br /> + <a id="link-3" ng-href="/{{'123'}}">link 3</a> (link, reload!)<br /> <a id="link-4" href="" name="xx" ng-click="value = 4">anchor</a> (link, don't reload)<br /> <a id="link-5" name="xxx" ng-click="value = 5">anchor</a> (no link)<br /> - <a id="link-6" ng-href="/{{value}}" ng-ext-link>link</a> (link, change hash) + <a id="link-6" ng-href="{{value}}">link</a> (link, change location) </doc:source> <doc:scenario> it('should execute ng-click but not reload when href without value', function() { @@ -60,21 +60,21 @@ it('should execute ng-click but not reload when href empty string and name specified', function() { element('#link-4').click(); expect(input('value').val()).toEqual('4'); - expect(element('#link-4').attr('href')).toBe(""); + expect(element('#link-4').attr('href')).toBe(''); }); it('should execute ng-click but not reload when no href but name specified', function() { element('#link-5').click(); expect(input('value').val()).toEqual('5'); - expect(element('#link-5').attr('href')).toBe(""); + expect(element('#link-5').attr('href')).toBe(''); }); it('should only change url when only ng-href', function() { input('value').enter('6'); - expect(element('#link-6').attr('href')).toBe("/6"); + expect(element('#link-6').attr('href')).toBe('6'); element('#link-6').click(); - expect(browser().window().path()).toEqual('/6'); + expect(browser().location().url()).toEqual('/6'); }); </doc:scenario> </doc:example> diff --git a/src/ng/location.js b/src/ng/location.js index 9feee5ad..575feb7e 100644 --- a/src/ng/location.js +++ b/src/ng/location.js @@ -500,22 +500,16 @@ function $LocationProvider(){ elm = elm.parent(); } - var href = elm.attr('href'); - if (!href || isDefined(elm.attr('ng-ext-link')) || elm.attr('target')) return; + var absHref = elm.prop('href'); - // link to different base path - if (href[0] === '/' && href.indexOf(pathPrefix) !== 0) return; - - // remove same domain from full url links (IE7 always returns full hrefs) - href = href.replace(absUrlPrefix, ''); - - // link to different domain (or base path) - if (href.substr(0, 4) == 'http') return; - - // remove pathPrefix from absolute links - href = href.indexOf(pathPrefix) === 0 ? href.substr(pathPrefix.length) : href; + if (!absHref || + elm.attr('target') || + absHref.indexOf(absUrlPrefix) !== 0) { // link to different domain or base path + return; + } - currentUrl.url(href); + // update location with href without the prefix + currentUrl.url(absHref.substr(absUrlPrefix.length)); $rootScope.$apply(); event.preventDefault(); // hack to work around FF6 bug 684208 when scenario runner clicks on links |
