* 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)
| 12186 | * @param {string} basePrefix url path prefix |
| 12187 | */ |
| 12188 | function LocationHtml5Url(appBase, appBaseNoFile, basePrefix) { |
| 12189 | this.$$html5 = true; |
| 12190 | basePrefix = basePrefix || ''; |
| 12191 | parseAbsoluteUrl(appBase, this); |
| 12192 | |
| 12193 | |
| 12194 | /** |
| 12195 | * Parse given html5 (regular) url string into properties |
| 12196 | * @param {string} url HTML5 url |
| 12197 | * @private |
| 12198 | */ |
| 12199 | this.$$parse = function(url) { |
| 12200 | var pathUrl = beginsWith(appBaseNoFile, url); |
| 12201 | if (!isString(pathUrl)) { |
| 12202 | throw $locationMinErr('ipthprfx', 'Invalid url "{0}", missing path prefix "{1}".', url, |
| 12203 | appBaseNoFile); |
| 12204 | } |
| 12205 | |
| 12206 | parseAppUrl(pathUrl, this); |
| 12207 | |
| 12208 | if (!this.$$path) { |
| 12209 | this.$$path = '/'; |
| 12210 | } |
| 12211 | |
| 12212 | this.$$compose(); |
| 12213 | }; |
| 12214 | |
| 12215 | /** |
| 12216 | * Compose url and update `absUrl` property |
| 12217 | * @private |
| 12218 | */ |
| 12219 | this.$$compose = function() { |
| 12220 | var search = toKeyValue(this.$$search), |
| 12221 | hash = this.$$hash ? '#' + encodeUriSegment(this.$$hash) : ''; |
| 12222 | |
| 12223 | this.$$url = encodePath(this.$$path) + (search ? '?' + search : '') + hash; |
| 12224 | this.$$absUrl = appBaseNoFile + this.$$url.substr(1); // first char is always '/' |
| 12225 | }; |
| 12226 | |
| 12227 | this.$$parseLinkUrl = function(url, relHref) { |
| 12228 | if (relHref && relHref[0] === '#') { |
| 12229 | // special case for links to hash fragments: |
| 12230 | // keep the old url and only replace the hash fragment |
| 12231 | this.hash(relHref.slice(1)); |
| 12232 | return true; |
| 12233 | } |
| 12234 | var appUrl, prevAppUrl; |
| 12235 | var rewrittenUrl; |
| 12236 | |
| 12237 | if (isDefined(appUrl = beginsWith(appBase, url))) { |
| 12238 | prevAppUrl = appUrl; |
| 12239 | if (isDefined(appUrl = beginsWith(basePrefix, appUrl))) { |
| 12240 | rewrittenUrl = appBaseNoFile + (beginsWith('/', appUrl) || appUrl); |
| 12241 | } else { |
| 12242 | rewrittenUrl = appBase + prevAppUrl; |
| 12243 | } |
| 12244 | } else if (isDefined(appUrl = beginsWith(appBaseNoFile, url))) { |
| 12245 | rewrittenUrl = appBaseNoFile + appUrl; |
nothing calls this directly
no test coverage detected