MCPcopy Create free account
hub / github.com/bclinkinbeard/angular / LocationHashbangUrl

Function LocationHashbangUrl

test/fixtures/foo.js:9301–9382  ·  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

9299 * @param {string} hashPrefix hashbang prefix
9300 */
9301function LocationHashbangUrl(appBase, hashPrefix) {
9302 var appBaseNoFile = stripFile(appBase);
9303
9304 parseAbsoluteUrl(appBase, this, appBase);
9305
9306
9307 /**
9308 * Parse given hashbang url into properties
9309 * @param {string} url Hashbang url
9310 * @private
9311 */
9312 this.$$parse = function(url) {
9313 var withoutBaseUrl = beginsWith(appBase, url) || beginsWith(appBaseNoFile, url);
9314 var withoutHashUrl = withoutBaseUrl.charAt(0) == '#'
9315 ? beginsWith(hashPrefix, withoutBaseUrl)
9316 : (this.$$html5)
9317 ? withoutBaseUrl
9318 : '';
9319
9320 if (!isString(withoutHashUrl)) {
9321 throw $locationMinErr('ihshprfx', 'Invalid url "{0}", missing hash prefix "{1}".', url,
9322 hashPrefix);
9323 }
9324 parseAppUrl(withoutHashUrl, this, appBase);
9325
9326 this.$$path = removeWindowsDriveName(this.$$path, withoutHashUrl, appBase);
9327
9328 this.$$compose();
9329
9330 /*
9331 * In Windows, on an anchor node on documents loaded from
9332 * the filesystem, the browser will return a pathname
9333 * prefixed with the drive name ('/C:/path') when a
9334 * pathname without a drive is set:
9335 * * a.setAttribute('href', '/foo')
9336 * * a.pathname === '/C:/foo' //true
9337 *
9338 * Inside of Angular, we're always using pathnames that
9339 * do not include drive names for routing.
9340 */
9341 function removeWindowsDriveName (path, url, base) {
9342 /*
9343 Matches paths for file protocol on windows,
9344 such as /C:/foo/bar, and captures only /foo/bar.
9345 */
9346 var windowsFilePathExp = /^\/[A-Z]:(\/.*)/;
9347
9348 var firstPathSegmentMatch;
9349
9350 //Get the relative path from the input URL.
9351 if (url.indexOf(base) === 0) {
9352 url = url.replace(base, '');
9353 }
9354
9355 // The input URL intentionally contains a first path segment that ends with a colon.
9356 if (windowsFilePathExp.exec(url)) {
9357 return path;
9358 }

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