* LocationHashbangUrl represents url * This object is exposed as $location service when developer doesn't opt into html5 mode. * It also serves as the base class for html5 mode fallback on legacy browsers. * * @constructor * @param {string} appBase application base URL * @param {string} hashPr
(appBase, hashPrefix)
| 11366 | * @param {string} hashPrefix hashbang prefix |
| 11367 | */ |
| 11368 | function LocationHashbangUrl(appBase, hashPrefix) { |
| 11369 | var appBaseNoFile = stripFile(appBase); |
| 11370 | |
| 11371 | parseAbsoluteUrl(appBase, this); |
| 11372 | |
| 11373 | |
| 11374 | /** |
| 11375 | * Parse given hashbang url into properties |
| 11376 | * @param {string} url Hashbang url |
| 11377 | * @private |
| 11378 | */ |
| 11379 | this.$$parse = function(url) { |
| 11380 | var withoutBaseUrl = beginsWith(appBase, url) || beginsWith(appBaseNoFile, url); |
| 11381 | var withoutHashUrl; |
| 11382 | |
| 11383 | if (!isUndefined(withoutBaseUrl) && withoutBaseUrl.charAt(0) === '#') { |
| 11384 | |
| 11385 | // The rest of the url starts with a hash so we have |
| 11386 | // got either a hashbang path or a plain hash fragment |
| 11387 | withoutHashUrl = beginsWith(hashPrefix, withoutBaseUrl); |
| 11388 | if (isUndefined(withoutHashUrl)) { |
| 11389 | // There was no hashbang prefix so we just have a hash fragment |
| 11390 | withoutHashUrl = withoutBaseUrl; |
| 11391 | } |
| 11392 | |
| 11393 | } else { |
| 11394 | // There was no hashbang path nor hash fragment: |
| 11395 | // If we are in HTML5 mode we use what is left as the path; |
| 11396 | // Otherwise we ignore what is left |
| 11397 | if (this.$$html5) { |
| 11398 | withoutHashUrl = withoutBaseUrl; |
| 11399 | } else { |
| 11400 | withoutHashUrl = ''; |
| 11401 | if (isUndefined(withoutBaseUrl)) { |
| 11402 | appBase = url; |
| 11403 | this.replace(); |
| 11404 | } |
| 11405 | } |
| 11406 | } |
| 11407 | |
| 11408 | parseAppUrl(withoutHashUrl, this); |
| 11409 | |
| 11410 | this.$$path = removeWindowsDriveName(this.$$path, withoutHashUrl, appBase); |
| 11411 | |
| 11412 | this.$$compose(); |
| 11413 | |
| 11414 | /* |
| 11415 | * In Windows, on an anchor node on documents loaded from |
| 11416 | * the filesystem, the browser will return a pathname |
| 11417 | * prefixed with the drive name ('/C:/path') when a |
| 11418 | * pathname without a drive is set: |
| 11419 | * * a.setAttribute('href', '/foo') |
| 11420 | * * a.pathname === '/C:/foo' //true |
| 11421 | * |
| 11422 | * Inside of Angular, we're always using pathnames that |
| 11423 | * do not include drive names for routing. |
| 11424 | */ |
| 11425 | function removeWindowsDriveName(path, url, base) { |
nothing calls this directly
no test coverage detected