MCPcopy Create free account
hub / github.com/JacksonTian/fks / LocationHashbangUrl

Function LocationHashbangUrl

fks_chart/bower_components/angular/angular.js:9385–9468  ·  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

9383 * @param {string} hashPrefix hashbang prefix
9384 */
9385function LocationHashbangUrl(appBase, hashPrefix) {
9386 var appBaseNoFile = stripFile(appBase);
9387
9388 parseAbsoluteUrl(appBase, this, appBase);
9389
9390
9391 /**
9392 * Parse given hashbang url into properties
9393 * @param {string} url Hashbang url
9394 * @private
9395 */
9396 this.$$parse = function(url) {
9397 var withoutBaseUrl = beginsWith(appBase, url) || beginsWith(appBaseNoFile, url);
9398 var withoutHashUrl = withoutBaseUrl.charAt(0) == '#'
9399 ? beginsWith(hashPrefix, withoutBaseUrl)
9400 : (this.$$html5)
9401 ? withoutBaseUrl
9402 : '';
9403
9404 if (!isString(withoutHashUrl)) {
9405 throw $locationMinErr('ihshprfx', 'Invalid url "{0}", missing hash prefix "{1}".', url,
9406 hashPrefix);
9407 }
9408 parseAppUrl(withoutHashUrl, this, appBase);
9409
9410 this.$$path = removeWindowsDriveName(this.$$path, withoutHashUrl, appBase);
9411
9412 this.$$compose();
9413
9414 /*
9415 * In Windows, on an anchor node on documents loaded from
9416 * the filesystem, the browser will return a pathname
9417 * prefixed with the drive name ('/C:/path') when a
9418 * pathname without a drive is set:
9419 * * a.setAttribute('href', '/foo')
9420 * * a.pathname === '/C:/foo' //true
9421 *
9422 * Inside of Angular, we're always using pathnames that
9423 * do not include drive names for routing.
9424 */
9425 function removeWindowsDriveName (path, url, base) {
9426 /*
9427 Matches paths for file protocol on windows,
9428 such as /C:/foo/bar, and captures only /foo/bar.
9429 */
9430 var windowsFilePathExp = /^\/[A-Z]:(\/.*)/;
9431
9432 var firstPathSegmentMatch;
9433
9434 //Get the relative path from the input URL.
9435 if (url.indexOf(base) === 0) {
9436 url = url.replace(base, '');
9437 }
9438
9439 // The input URL intentionally contains a first path segment that ends with a colon.
9440 if (windowsFilePathExp.exec(url)) {
9441 return path;
9442 }

Callers

nothing calls this directly

Calls 10

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

Tested by

no test coverage detected