MCPcopy Create free account
hub / github.com/cafebazaar/blacksmith / LocationHashbangUrl

Function LocationHashbangUrl

web/static/bower_components/angular/angular.js:11508–11607  ·  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} appBas

(appBase, appBaseNoFile, hashPrefix)

Source from the content-addressed store, hash-verified

11506 * @param {string} hashPrefix hashbang prefix
11507 */
11508function LocationHashbangUrl(appBase, appBaseNoFile, hashPrefix) {
11509
11510 parseAbsoluteUrl(appBase, this);
11511
11512
11513 /**
11514 * Parse given hashbang url into properties
11515 * @param {string} url Hashbang url
11516 * @private
11517 */
11518 this.$$parse = function(url) {
11519 var withoutBaseUrl = beginsWith(appBase, url) || beginsWith(appBaseNoFile, url);
11520 var withoutHashUrl;
11521
11522 if (!isUndefined(withoutBaseUrl) && withoutBaseUrl.charAt(0) === '#') {
11523
11524 // The rest of the url starts with a hash so we have
11525 // got either a hashbang path or a plain hash fragment
11526 withoutHashUrl = beginsWith(hashPrefix, withoutBaseUrl);
11527 if (isUndefined(withoutHashUrl)) {
11528 // There was no hashbang prefix so we just have a hash fragment
11529 withoutHashUrl = withoutBaseUrl;
11530 }
11531
11532 } else {
11533 // There was no hashbang path nor hash fragment:
11534 // If we are in HTML5 mode we use what is left as the path;
11535 // Otherwise we ignore what is left
11536 if (this.$$html5) {
11537 withoutHashUrl = withoutBaseUrl;
11538 } else {
11539 withoutHashUrl = '';
11540 if (isUndefined(withoutBaseUrl)) {
11541 appBase = url;
11542 this.replace();
11543 }
11544 }
11545 }
11546
11547 parseAppUrl(withoutHashUrl, this);
11548
11549 this.$$path = removeWindowsDriveName(this.$$path, withoutHashUrl, appBase);
11550
11551 this.$$compose();
11552
11553 /*
11554 * In Windows, on an anchor node on documents loaded from
11555 * the filesystem, the browser will return a pathname
11556 * prefixed with the drive name ('/C:/path') when a
11557 * pathname without a drive is set:
11558 * * a.setAttribute('href', '/foo')
11559 * * a.pathname === '/C:/foo' //true
11560 *
11561 * Inside of Angular, we're always using pathnames that
11562 * do not include drive names for routing.
11563 */
11564 function removeWindowsDriveName(path, url, base) {
11565 /*

Callers

nothing calls this directly

Calls 9

parseAbsoluteUrlFunction · 0.85
beginsWithFunction · 0.85
isUndefinedFunction · 0.85
parseAppUrlFunction · 0.85
removeWindowsDriveNameFunction · 0.85
toKeyValueFunction · 0.85
encodePathFunction · 0.85
stripHashFunction · 0.85
encodeUriSegmentFunction · 0.70

Tested by

no test coverage detected