* LocationHtml5Url represents a 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)
| 14556 | * @param {string} basePrefix URL path prefix |
| 14557 | */ |
| 14558 | function LocationHtml5Url(appBase, appBaseNoFile, basePrefix) { |
| 14559 | this.$$html5 = true; |
| 14560 | basePrefix = basePrefix || ''; |
| 14561 | parseAbsoluteUrl(appBase, this); |
| 14562 | |
| 14563 | |
| 14564 | /** |
| 14565 | * Parse given HTML5 (regular) URL string into properties |
| 14566 | * @param {string} url HTML5 URL |
| 14567 | * @private |
| 14568 | */ |
| 14569 | this.$$parse = function(url) { |
| 14570 | var pathUrl = stripBaseUrl(appBaseNoFile, url); |
| 14571 | if (!isString(pathUrl)) { |
| 14572 | throw $locationMinErr('ipthprfx', 'Invalid url "{0}", missing path prefix "{1}".', url, |
| 14573 | appBaseNoFile); |
| 14574 | } |
| 14575 | |
| 14576 | parseAppUrl(pathUrl, this, true); |
| 14577 | |
| 14578 | if (!this.$$path) { |
| 14579 | this.$$path = '/'; |
| 14580 | } |
| 14581 | |
| 14582 | this.$$compose(); |
| 14583 | }; |
| 14584 | |
| 14585 | this.$$normalizeUrl = function(url) { |
| 14586 | return appBaseNoFile + url.substr(1); // first char is always '/' |
| 14587 | }; |
| 14588 | |
| 14589 | this.$$parseLinkUrl = function(url, relHref) { |
| 14590 | if (relHref && relHref[0] === '#') { |
| 14591 | // special case for links to hash fragments: |
| 14592 | // keep the old url and only replace the hash fragment |
| 14593 | this.hash(relHref.slice(1)); |
| 14594 | return true; |
| 14595 | } |
| 14596 | var appUrl, prevAppUrl; |
| 14597 | var rewrittenUrl; |
| 14598 | |
| 14599 | |
| 14600 | if (isDefined(appUrl = stripBaseUrl(appBase, url))) { |
| 14601 | prevAppUrl = appUrl; |
| 14602 | if (basePrefix && isDefined(appUrl = stripBaseUrl(basePrefix, appUrl))) { |
| 14603 | rewrittenUrl = appBaseNoFile + (stripBaseUrl('/', appUrl) || appUrl); |
| 14604 | } else { |
| 14605 | rewrittenUrl = appBase + prevAppUrl; |
| 14606 | } |
| 14607 | } else if (isDefined(appUrl = stripBaseUrl(appBaseNoFile, url))) { |
| 14608 | rewrittenUrl = appBaseNoFile + appUrl; |
| 14609 | } else if (appBaseNoFile === url + '/') { |
| 14610 | rewrittenUrl = appBaseNoFile; |
| 14611 | } |
| 14612 | if (rewrittenUrl) { |
| 14613 | this.$$parse(rewrittenUrl); |
| 14614 | } |
| 14615 | return !!rewrittenUrl; |
nothing calls this directly
no test coverage detected