MCPcopy Index your code
hub / github.com/angular-ui/ui-router / LocationHashbangUrl

Function LocationHashbangUrl

test/angular/1.2/angular.js:9418–9501  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

9416 * @param {string} hashPrefix hashbang prefix
9417 */
9418function LocationHashbangUrl(appBase, hashPrefix) {
9419 var appBaseNoFile = stripFile(appBase);
9420
9421 parseAbsoluteUrl(appBase, this, appBase);
9422
9423
9424 /**
9425 * Parse given hashbang url into properties
9426 * @param {string} url Hashbang url
9427 * @private
9428 */
9429 this.$$parse = function(url) {
9430 var withoutBaseUrl = beginsWith(appBase, url) || beginsWith(appBaseNoFile, url);
9431 var withoutHashUrl = withoutBaseUrl.charAt(0) == '#'
9432 ? beginsWith(hashPrefix, withoutBaseUrl)
9433 : (this.$$html5)
9434 ? withoutBaseUrl
9435 : '';
9436
9437 if (!isString(withoutHashUrl)) {
9438 throw $locationMinErr('ihshprfx', 'Invalid url "{0}", missing hash prefix "{1}".', url,
9439 hashPrefix);
9440 }
9441 parseAppUrl(withoutHashUrl, this, appBase);
9442
9443 this.$$path = removeWindowsDriveName(this.$$path, withoutHashUrl, appBase);
9444
9445 this.$$compose();
9446
9447 /*
9448 * In Windows, on an anchor node on documents loaded from
9449 * the filesystem, the browser will return a pathname
9450 * prefixed with the drive name ('/C:/path') when a
9451 * pathname without a drive is set:
9452 * * a.setAttribute('href', '/foo')
9453 * * a.pathname === '/C:/foo' //true
9454 *
9455 * Inside of Angular, we're always using pathnames that
9456 * do not include drive names for routing.
9457 */
9458 function removeWindowsDriveName (path, url, base) {
9459 /*
9460 Matches paths for file protocol on windows,
9461 such as /C:/foo/bar, and captures only /foo/bar.
9462 */
9463 var windowsFilePathExp = /^\/[A-Z]:(\/.*)/;
9464
9465 var firstPathSegmentMatch;
9466
9467 //Get the relative path from the input URL.
9468 if (url.indexOf(base) === 0) {
9469 url = url.replace(base, '');
9470 }
9471
9472 // The input URL intentionally contains a first path segment that ends with a colon.
9473 if (windowsFilePathExp.exec(url)) {
9474 return path;
9475 }

Callers

nothing calls this directly

Calls 10

stripFileFunction · 0.70
parseAbsoluteUrlFunction · 0.70
beginsWithFunction · 0.70
isStringFunction · 0.70
parseAppUrlFunction · 0.70
removeWindowsDriveNameFunction · 0.70
toKeyValueFunction · 0.70
encodeUriSegmentFunction · 0.70
encodePathFunction · 0.70
stripHashFunction · 0.70

Tested by

no test coverage detected