* LocationHtml5Url represents an url * This object is exposed as $location service when HTML5 mode is enabled and supported * * @constructor * @param {string} appBase application base URL * @param {string} appBaseNoFile application base URL stripped of any filename * @param {string} basePrefix
(appBase, appBaseNoFile, basePrefix)
| 11427 | * @param {string} basePrefix url path prefix |
| 11428 | */ |
| 11429 | function LocationHtml5Url(appBase, appBaseNoFile, basePrefix) { |
| 11430 | this.$$html5 = true; |
| 11431 | basePrefix = basePrefix || ''; |
| 11432 | parseAbsoluteUrl(appBase, this); |
| 11433 | |
| 11434 | |
| 11435 | /** |
| 11436 | * Parse given html5 (regular) url string into properties |
| 11437 | * @param {string} url HTML5 url |
| 11438 | * @private |
| 11439 | */ |
| 11440 | this.$$parse = function(url) { |
| 11441 | var pathUrl = beginsWith(appBaseNoFile, url); |
| 11442 | if (!isString(pathUrl)) { |
| 11443 | throw $locationMinErr('ipthprfx', 'Invalid url "{0}", missing path prefix "{1}".', url, |
| 11444 | appBaseNoFile); |
| 11445 | } |
| 11446 | |
| 11447 | parseAppUrl(pathUrl, this); |
| 11448 | |
| 11449 | if (!this.$$path) { |
| 11450 | this.$$path = '/'; |
| 11451 | } |
| 11452 | |
| 11453 | this.$$compose(); |
| 11454 | }; |
| 11455 | |
| 11456 | /** |
| 11457 | * Compose url and update `absUrl` property |
| 11458 | * @private |
| 11459 | */ |
| 11460 | this.$$compose = function() { |
| 11461 | var search = toKeyValue(this.$$search), |
| 11462 | hash = this.$$hash ? '#' + encodeUriSegment(this.$$hash) : ''; |
| 11463 | |
| 11464 | this.$$url = encodePath(this.$$path) + (search ? '?' + search : '') + hash; |
| 11465 | this.$$absUrl = appBaseNoFile + this.$$url.substr(1); // first char is always '/' |
| 11466 | }; |
| 11467 | |
| 11468 | this.$$parseLinkUrl = function(url, relHref) { |
| 11469 | if (relHref && relHref[0] === '#') { |
| 11470 | // special case for links to hash fragments: |
| 11471 | // keep the old url and only replace the hash fragment |
| 11472 | this.hash(relHref.slice(1)); |
| 11473 | return true; |
| 11474 | } |
| 11475 | var appUrl, prevAppUrl; |
| 11476 | var rewrittenUrl; |
| 11477 | |
| 11478 | if (isDefined(appUrl = beginsWith(appBase, url))) { |
| 11479 | prevAppUrl = appUrl; |
| 11480 | if (isDefined(appUrl = beginsWith(basePrefix, appUrl))) { |
| 11481 | rewrittenUrl = appBaseNoFile + (beginsWith('/', appUrl) || appUrl); |
| 11482 | } else { |
| 11483 | rewrittenUrl = appBase + prevAppUrl; |
| 11484 | } |
| 11485 | } else if (isDefined(appUrl = beginsWith(appBaseNoFile, url))) { |
| 11486 | rewrittenUrl = appBaseNoFile + appUrl; |
nothing calls this directly
no test coverage detected