* 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)
| 13130 | * @param {string} basePrefix URL path prefix |
| 13131 | */ |
| 13132 | function LocationHtml5Url(appBase, appBaseNoFile, basePrefix) { |
| 13133 | this.$$html5 = true; |
| 13134 | basePrefix = basePrefix || ''; |
| 13135 | parseAbsoluteUrl(appBase, this); |
| 13136 | |
| 13137 | |
| 13138 | /** |
| 13139 | * Parse given HTML5 (regular) URL string into properties |
| 13140 | * @param {string} url HTML5 URL |
| 13141 | * @private |
| 13142 | */ |
| 13143 | this.$$parse = function(url) { |
| 13144 | var pathUrl = stripBaseUrl(appBaseNoFile, url); |
| 13145 | if (!isString(pathUrl)) { |
| 13146 | throw $locationMinErr('ipthprfx', 'Invalid url "{0}", missing path prefix "{1}".', url, |
| 13147 | appBaseNoFile); |
| 13148 | } |
| 13149 | |
| 13150 | parseAppUrl(pathUrl, this); |
| 13151 | |
| 13152 | if (!this.$$path) { |
| 13153 | this.$$path = '/'; |
| 13154 | } |
| 13155 | |
| 13156 | this.$$compose(); |
| 13157 | }; |
| 13158 | |
| 13159 | /** |
| 13160 | * Compose url and update `absUrl` property |
| 13161 | * @private |
| 13162 | */ |
| 13163 | this.$$compose = function() { |
| 13164 | var search = toKeyValue(this.$$search), |
| 13165 | hash = this.$$hash ? '#' + encodeUriSegment(this.$$hash) : ''; |
| 13166 | |
| 13167 | this.$$url = encodePath(this.$$path) + (search ? '?' + search : '') + hash; |
| 13168 | this.$$absUrl = appBaseNoFile + this.$$url.substr(1); // first char is always '/' |
| 13169 | }; |
| 13170 | |
| 13171 | this.$$parseLinkUrl = function(url, relHref) { |
| 13172 | if (relHref && relHref[0] === '#') { |
| 13173 | // special case for links to hash fragments: |
| 13174 | // keep the old url and only replace the hash fragment |
| 13175 | this.hash(relHref.slice(1)); |
| 13176 | return true; |
| 13177 | } |
| 13178 | var appUrl, prevAppUrl; |
| 13179 | var rewrittenUrl; |
| 13180 | |
| 13181 | |
| 13182 | if (isDefined(appUrl = stripBaseUrl(appBase, url))) { |
| 13183 | prevAppUrl = appUrl; |
| 13184 | if (basePrefix && isDefined(appUrl = stripBaseUrl(basePrefix, appUrl))) { |
| 13185 | rewrittenUrl = appBaseNoFile + (stripBaseUrl('/', appUrl) || appUrl); |
| 13186 | } else { |
| 13187 | rewrittenUrl = appBase + prevAppUrl; |
| 13188 | } |
| 13189 | } else if (isDefined(appUrl = stripBaseUrl(appBaseNoFile, url))) { |
nothing calls this directly
no test coverage detected