* 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)
| 9199 | * @param {string} basePrefix url path prefix |
| 9200 | */ |
| 9201 | function LocationHtml5Url(appBase, basePrefix) { |
| 9202 | this.$$html5 = true; |
| 9203 | basePrefix = basePrefix || ''; |
| 9204 | var appBaseNoFile = stripFile(appBase); |
| 9205 | parseAbsoluteUrl(appBase, this, appBase); |
| 9206 | |
| 9207 | |
| 9208 | /** |
| 9209 | * Parse given html5 (regular) url string into properties |
| 9210 | * @param {string} newAbsoluteUrl HTML5 url |
| 9211 | * @private |
| 9212 | */ |
| 9213 | this.$$parse = function(url) { |
| 9214 | var pathUrl = beginsWith(appBaseNoFile, url); |
| 9215 | if (!isString(pathUrl)) { |
| 9216 | throw $locationMinErr('ipthprfx', 'Invalid url "{0}", missing path prefix "{1}".', url, |
| 9217 | appBaseNoFile); |
| 9218 | } |
| 9219 | |
| 9220 | parseAppUrl(pathUrl, this, appBase); |
| 9221 | |
| 9222 | if (!this.$$path) { |
| 9223 | this.$$path = '/'; |
| 9224 | } |
| 9225 | |
| 9226 | this.$$compose(); |
| 9227 | }; |
| 9228 | |
| 9229 | /** |
| 9230 | * Compose url and update `absUrl` property |
| 9231 | * @private |
| 9232 | */ |
| 9233 | this.$$compose = function() { |
| 9234 | var search = toKeyValue(this.$$search), |
| 9235 | hash = this.$$hash ? '#' + encodeUriSegment(this.$$hash) : ''; |
| 9236 | |
| 9237 | this.$$url = encodePath(this.$$path) + (search ? '?' + search : '') + hash; |
| 9238 | this.$$absUrl = appBaseNoFile + this.$$url.substr(1); // first char is always '/' |
| 9239 | }; |
| 9240 | |
| 9241 | this.$$rewrite = function(url) { |
| 9242 | var appUrl, prevAppUrl; |
| 9243 | |
| 9244 | if ( (appUrl = beginsWith(appBase, url)) !== undefined ) { |
| 9245 | prevAppUrl = appUrl; |
| 9246 | if ( (appUrl = beginsWith(basePrefix, appUrl)) !== undefined ) { |
| 9247 | return appBaseNoFile + (beginsWith('/', appUrl) || appUrl); |
| 9248 | } else { |
| 9249 | return appBase + prevAppUrl; |
| 9250 | } |
| 9251 | } else if ( (appUrl = beginsWith(appBaseNoFile, url)) !== undefined ) { |
| 9252 | return appBaseNoFile + appUrl; |
| 9253 | } else if (appBaseNoFile == url + '/') { |
| 9254 | return appBaseNoFile; |
| 9255 | } |
| 9256 | }; |
| 9257 | } |
| 9258 |
nothing calls this directly
no test coverage detected