@@ -92,13 +92,13 @@ function serverBase(url) {
92
92
93
93
94
94
/**
95
- * LocationHtml5Url represents an url
95
+ * LocationHtml5Url represents a URL
96
96
* This object is exposed as $location service when HTML5 mode is enabled and supported
97
97
*
98
98
* @constructor
99
99
* @param {string } appBase application base URL
100
100
* @param {string } appBaseNoFile application base URL stripped of any filename
101
- * @param {string } basePrefix url path prefix
101
+ * @param {string } basePrefix URL path prefix
102
102
*/
103
103
function LocationHtml5Url ( appBase , appBaseNoFile , basePrefix ) {
104
104
this . $$html5 = true ;
@@ -107,8 +107,8 @@ function LocationHtml5Url(appBase, appBaseNoFile, basePrefix) {
107
107
108
108
109
109
/**
110
- * Parse given html5 (regular) url string into properties
111
- * @param {string } url HTML5 url
110
+ * Parse given HTML5 (regular) URL string into properties
111
+ * @param {string } url HTML5 URL
112
112
* @private
113
113
*/
114
114
this . $$parse = function ( url ) {
@@ -171,7 +171,7 @@ function LocationHtml5Url(appBase, appBaseNoFile, basePrefix) {
171
171
172
172
173
173
/**
174
- * LocationHashbangUrl represents url
174
+ * LocationHashbangUrl represents URL
175
175
* This object is exposed as $location service when developer doesn't opt into html5 mode.
176
176
* It also serves as the base class for html5 mode fallback on legacy browsers.
177
177
*
@@ -186,8 +186,8 @@ function LocationHashbangUrl(appBase, appBaseNoFile, hashPrefix) {
186
186
187
187
188
188
/**
189
- * Parse given hashbang url into properties
190
- * @param {string } url Hashbang url
189
+ * Parse given hashbang URL into properties
190
+ * @param {string } url Hashbang URL
191
191
* @private
192
192
*/
193
193
this . $$parse = function ( url ) {
@@ -196,7 +196,7 @@ function LocationHashbangUrl(appBase, appBaseNoFile, hashPrefix) {
196
196
197
197
if ( ! isUndefined ( withoutBaseUrl ) && withoutBaseUrl . charAt ( 0 ) === '#' ) {
198
198
199
- // The rest of the url starts with a hash so we have
199
+ // The rest of the URL starts with a hash so we have
200
200
// got either a hashbang path or a plain hash fragment
201
201
withoutHashUrl = stripBaseUrl ( hashPrefix , withoutBaseUrl ) ;
202
202
if ( isUndefined ( withoutHashUrl ) ) {
@@ -261,7 +261,7 @@ function LocationHashbangUrl(appBase, appBaseNoFile, hashPrefix) {
261
261
} ;
262
262
263
263
/**
264
- * Compose hashbang url and update `absUrl` property
264
+ * Compose hashbang URL and update `absUrl` property
265
265
* @private
266
266
*/
267
267
this . $$compose = function ( ) {
@@ -283,7 +283,7 @@ function LocationHashbangUrl(appBase, appBaseNoFile, hashPrefix) {
283
283
284
284
285
285
/**
286
- * LocationHashbangUrl represents url
286
+ * LocationHashbangUrl represents URL
287
287
* This object is exposed as $location service when html5 history api is enabled but the browser
288
288
* does not support it.
289
289
*
@@ -335,7 +335,7 @@ function LocationHashbangInHtml5Url(appBase, appBaseNoFile, hashPrefix) {
335
335
var locationPrototype = {
336
336
337
337
/**
338
- * Ensure absolute url is initialized.
338
+ * Ensure absolute URL is initialized.
339
339
* @private
340
340
*/
341
341
$$absUrl :'' ,
@@ -359,17 +359,17 @@ var locationPrototype = {
359
359
* @description
360
360
* This method is getter only.
361
361
*
362
- * Return full url representation with all segments encoded according to rules specified in
362
+ * Return full URL representation with all segments encoded according to rules specified in
363
363
* [RFC 3986](http://www.ietf.org/rfc/rfc3986.txt).
364
364
*
365
365
*
366
366
* ```js
367
- * // given url http://example.com/#/some/path?foo=bar&baz=xoxo
367
+ * // given URL http://example.com/#/some/path?foo=bar&baz=xoxo
368
368
* var absUrl = $location.absUrl();
369
369
* // => "http://example.com/#/some/path?foo=bar&baz=xoxo"
370
370
* ```
371
371
*
372
- * @return {string } full url
372
+ * @return {string } full URL
373
373
*/
374
374
absUrl : locationGetter ( '$$absUrl' ) ,
375
375
@@ -380,18 +380,18 @@ var locationPrototype = {
380
380
* @description
381
381
* This method is getter / setter.
382
382
*
383
- * Return url (e.g. `/path?a=b#hash`) when called without any parameter.
383
+ * Return URL (e.g. `/path?a=b#hash`) when called without any parameter.
384
384
*
385
385
* Change path, search and hash, when called with parameter and return `$location`.
386
386
*
387
387
*
388
388
* ```js
389
- * // given url http://example.com/#/some/path?foo=bar&baz=xoxo
389
+ * // given URL http://example.com/#/some/path?foo=bar&baz=xoxo
390
390
* var url = $location.url();
391
391
* // => "/some/path?foo=bar&baz=xoxo"
392
392
* ```
393
393
*
394
- * @param {string= } url New url without base prefix (e.g. `/path?a=b#hash`)
394
+ * @param {string= } url New URL without base prefix (e.g. `/path?a=b#hash`)
395
395
* @return {string } url
396
396
*/
397
397
url : function ( url ) {
@@ -414,16 +414,16 @@ var locationPrototype = {
414
414
* @description
415
415
* This method is getter only.
416
416
*
417
- * Return protocol of current url .
417
+ * Return protocol of current URL .
418
418
*
419
419
*
420
420
* ```js
421
- * // given url http://example.com/#/some/path?foo=bar&baz=xoxo
421
+ * // given URL http://example.com/#/some/path?foo=bar&baz=xoxo
422
422
* var protocol = $location.protocol();
423
423
* // => "http"
424
424
* ```
425
425
*
426
- * @return {string } protocol of current url
426
+ * @return {string } protocol of current URL
427
427
*/
428
428
protocol : locationGetter ( '$$protocol' ) ,
429
429
@@ -434,24 +434,24 @@ var locationPrototype = {
434
434
* @description
435
435
* This method is getter only.
436
436
*
437
- * Return host of current url .
437
+ * Return host of current URL .
438
438
*
439
439
* Note: compared to the non-angular version `location.host` which returns `hostname:port`, this returns the `hostname` portion only.
440
440
*
441
441
*
442
442
* ```js
443
- * // given url http://example.com/#/some/path?foo=bar&baz=xoxo
443
+ * // given URL http://example.com/#/some/path?foo=bar&baz=xoxo
444
444
* var host = $location.host();
445
445
* // => "example.com"
446
446
*
447
- * // given url http://user:password@example .com:8080/#/some/path?foo=bar&baz=xoxo
447
+ * // given URL http://user:password@example .com:8080/#/some/path?foo=bar&baz=xoxo
448
448
* host = $location.host();
449
449
* // => "example.com"
450
450
* host = location.host;
451
451
* // => "example.com:8080"
452
452
* ```
453
453
*
454
- * @return {string } host of current url .
454
+ * @return {string } host of current URL .
455
455
*/
456
456
host : locationGetter ( '$$host' ) ,
457
457
@@ -462,11 +462,11 @@ var locationPrototype = {
462
462
* @description
463
463
* This method is getter only.
464
464
*
465
- * Return port of current url .
465
+ * Return port of current URL .
466
466
*
467
467
*
468
468
* ```js
469
- * // given url http://example.com/#/some/path?foo=bar&baz=xoxo
469
+ * // given URL http://example.com/#/some/path?foo=bar&baz=xoxo
470
470
* var port = $location.port();
471
471
* // => 80
472
472
* ```
@@ -482,7 +482,7 @@ var locationPrototype = {
482
482
* @description
483
483
* This method is getter / setter.
484
484
*
485
- * Return path of current url when called without any parameter.
485
+ * Return path of current URL when called without any parameter.
486
486
*
487
487
* Change path when called with parameter and return `$location`.
488
488
*
@@ -491,7 +491,7 @@ var locationPrototype = {
491
491
*
492
492
*
493
493
* ```js
494
- * // given url http://example.com/#/some/path?foo=bar&baz=xoxo
494
+ * // given URL http://example.com/#/some/path?foo=bar&baz=xoxo
495
495
* var path = $location.path();
496
496
* // => "/some/path"
497
497
* ```
@@ -511,13 +511,13 @@ var locationPrototype = {
511
511
* @description
512
512
* This method is getter / setter.
513
513
*
514
- * Return search part (as object) of current url when called without any parameter.
514
+ * Return search part (as object) of current URL when called without any parameter.
515
515
*
516
516
* Change search part when called with parameter and return `$location`.
517
517
*
518
518
*
519
519
* ```js
520
- * // given url http://example.com/#/some/path?foo=bar&baz=xoxo
520
+ * // given URL http://example.com/#/some/path?foo=bar&baz=xoxo
521
521
* var searchObject = $location.search();
522
522
* // => {foo: 'bar', baz: 'xoxo'}
523
523
*
@@ -533,7 +533,7 @@ var locationPrototype = {
533
533
* of `$location` to the specified value.
534
534
*
535
535
* If the argument is a hash object containing an array of values, these values will be encoded
536
- * as duplicate search parameters in the url .
536
+ * as duplicate search parameters in the URL .
537
537
*
538
538
* @param {(string|Number|Array<string>|boolean)= } paramValue If `search` is a string or number, then `paramValue`
539
539
* will override only a single search property.
@@ -595,7 +595,7 @@ var locationPrototype = {
595
595
*
596
596
*
597
597
* ```js
598
- * // given url http://example.com/#/some/path?foo=bar&baz=xoxo#hashValue
598
+ * // given URL http://example.com/#/some/path?foo=bar&baz=xoxo#hashValue
599
599
* var hash = $location.hash();
600
600
* // => "hashValue"
601
601
* ```
@@ -755,8 +755,12 @@ function $LocationProvider() {
755
755
* whether or not a <base> tag is required to be present. If `enabled` and `requireBase` are
756
756
* true, and a base tag is not present, an error will be thrown when `$location` is injected.
757
757
* See the {@link guide/$location $location guide for more information}
758
- * - **rewriteLinks** - `{boolean}` - (default: `true`) When html5Mode is enabled,
759
- * enables/disables url rewriting for relative links.
758
+ * - **rewriteLinks** - `{boolean|string}` - (default: `true`) When html5Mode is enabled,
759
+ * enables/disables URL rewriting for relative links. If set to a string, URL rewriting will
760
+ * only happen on links with an attribute that matches the given string. For example, if set
761
+ * to `'internal-link'`, then the URL will only be rewritten for `<a internal-link>` links.
762
+ * Note that [attribute name normalization](guide/directive#normalization) does not apply
763
+ * here, so `'internalLink'` will **not** match `'internal-link'`.
760
764
*
761
765
* @returns {Object } html5Mode object if used as getter or itself (chaining) if used as setter
762
766
*/
@@ -774,7 +778,7 @@ function $LocationProvider() {
774
778
html5Mode . requireBase = mode . requireBase ;
775
779
}
776
780
777
- if ( isBoolean ( mode . rewriteLinks ) ) {
781
+ if ( isBoolean ( mode . rewriteLinks ) || isString ( mode . rewriteLinks ) ) {
778
782
html5Mode . rewriteLinks = mode . rewriteLinks ;
779
783
}
780
784
@@ -871,10 +875,11 @@ function $LocationProvider() {
871
875
}
872
876
873
877
$rootElement . on ( 'click' , function ( event ) {
878
+ var rewriteLinks = html5Mode . rewriteLinks ;
874
879
// TODO(vojta): rewrite link when opening in new tab/window (in legacy browser)
875
880
// currently we open nice url link and redirect then
876
881
877
- if ( ! html5Mode . rewriteLinks || event . ctrlKey || event . metaKey || event . shiftKey || event . which === 2 || event . button === 2 ) return ;
882
+ if ( ! rewriteLinks || event . ctrlKey || event . metaKey || event . shiftKey || event . which === 2 || event . button === 2 ) return ;
878
883
879
884
var elm = jqLite ( event . target ) ;
880
885
@@ -884,6 +889,8 @@ function $LocationProvider() {
884
889
if ( elm [ 0 ] === $rootElement [ 0 ] || ! ( elm = elm . parent ( ) ) [ 0 ] ) return ;
885
890
}
886
891
892
+ if ( isString ( rewriteLinks ) && isUndefined ( elm . attr ( rewriteLinks ) ) ) return ;
893
+
887
894
var absHref = elm . prop ( 'href' ) ;
888
895
// get the actual href attribute - see
889
896
// http://msdn.microsoft.com/en-us/library/ie/dd347148(v=vs.85).aspx
0 commit comments