* 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} basePrefix url path prefix
(appBase, basePrefix)
| 11287 | * @param {string} basePrefix url path prefix |
| 11288 | */ |
| 11289 | function LocationHtml5Url(appBase, basePrefix) { |
| 11290 | this.$$html5 = true; |
| 11291 | basePrefix = basePrefix || ''; |
| 11292 | var appBaseNoFile = stripFile(appBase); |
| 11293 | parseAbsoluteUrl(appBase, this); |
| 11294 | |
| 11295 | |
| 11296 | /** |
| 11297 | * Parse given html5 (regular) url string into properties |
| 11298 | * @param {string} url HTML5 url |
| 11299 | * @private |
| 11300 | */ |
| 11301 | this.$$parse = function(url) { |
| 11302 | var pathUrl = beginsWith(appBaseNoFile, url); |
| 11303 | if (!isString(pathUrl)) { |
| 11304 | throw $locationMinErr('ipthprfx', 'Invalid url "{0}", missing path prefix "{1}".', url, |
| 11305 | appBaseNoFile); |
| 11306 | } |
| 11307 | |
| 11308 | parseAppUrl(pathUrl, this); |
| 11309 | |
| 11310 | if (!this.$$path) { |
| 11311 | this.$$path = '/'; |
| 11312 | } |
| 11313 | |
| 11314 | this.$$compose(); |
| 11315 | }; |
| 11316 | |
| 11317 | /** |
| 11318 | * Compose url and update `absUrl` property |
| 11319 | * @private |
| 11320 | */ |
| 11321 | this.$$compose = function() { |
| 11322 | var search = toKeyValue(this.$$search), |
| 11323 | hash = this.$$hash ? '#' + encodeUriSegment(this.$$hash) : ''; |
| 11324 | |
| 11325 | this.$$url = encodePath(this.$$path) + (search ? '?' + search : '') + hash; |
| 11326 | this.$$absUrl = appBaseNoFile + this.$$url.substr(1); // first char is always '/' |
| 11327 | }; |
| 11328 | |
| 11329 | this.$$parseLinkUrl = function(url, relHref) { |
| 11330 | if (relHref && relHref[0] === '#') { |
| 11331 | // special case for links to hash fragments: |
| 11332 | // keep the old url and only replace the hash fragment |
| 11333 | this.hash(relHref.slice(1)); |
| 11334 | return true; |
| 11335 | } |
| 11336 | var appUrl, prevAppUrl; |
| 11337 | var rewrittenUrl; |
| 11338 | |
| 11339 | if ((appUrl = beginsWith(appBase, url)) !== undefined) { |
| 11340 | prevAppUrl = appUrl; |
| 11341 | if ((appUrl = beginsWith(basePrefix, appUrl)) !== undefined) { |
| 11342 | rewrittenUrl = appBaseNoFile + (beginsWith('/', appUrl) || appUrl); |
| 11343 | } else { |
| 11344 | rewrittenUrl = appBase + prevAppUrl; |
| 11345 | } |
| 11346 | } else if ((appUrl = beginsWith(appBaseNoFile, url)) !== undefined) { |
nothing calls this directly
no test coverage detected