MCPcopy
hub / github.com/binux/qiandao / LocationHashbangUrl

Function LocationHashbangUrl

web/static/components/angularjs/angular.js:9269–9350  ·  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

9267 * @param {string} hashPrefix hashbang prefix
9268 */
9269function LocationHashbangUrl(appBase, hashPrefix) {
9270 var appBaseNoFile = stripFile(appBase);
9271
9272 parseAbsoluteUrl(appBase, this, appBase);
9273
9274
9275 /**
9276 * Parse given hashbang url into properties
9277 * @param {string} url Hashbang url
9278 * @private
9279 */
9280 this.$$parse = function(url) {
9281 var withoutBaseUrl = beginsWith(appBase, url) || beginsWith(appBaseNoFile, url);
9282 var withoutHashUrl = withoutBaseUrl.charAt(0) == '#'
9283 ? beginsWith(hashPrefix, withoutBaseUrl)
9284 : (this.$$html5)
9285 ? withoutBaseUrl
9286 : '';
9287
9288 if (!isString(withoutHashUrl)) {
9289 throw $locationMinErr('ihshprfx', 'Invalid url "{0}", missing hash prefix "{1}".', url,
9290 hashPrefix);
9291 }
9292 parseAppUrl(withoutHashUrl, this, appBase);
9293
9294 this.$$path = removeWindowsDriveName(this.$$path, withoutHashUrl, appBase);
9295
9296 this.$$compose();
9297
9298 /*
9299 * In Windows, on an anchor node on documents loaded from
9300 * the filesystem, the browser will return a pathname
9301 * prefixed with the drive name ('/C:/path') when a
9302 * pathname without a drive is set:
9303 * * a.setAttribute('href', '/foo')
9304 * * a.pathname === '/C:/foo' //true
9305 *
9306 * Inside of Angular, we're always using pathnames that
9307 * do not include drive names for routing.
9308 */
9309 function removeWindowsDriveName (path, url, base) {
9310 /*
9311 Matches paths for file protocol on windows,
9312 such as /C:/foo/bar, and captures only /foo/bar.
9313 */
9314 var windowsFilePathExp = /^\/[A-Z]:(\/.*)/;
9315
9316 var firstPathSegmentMatch;
9317
9318 //Get the relative path from the input URL.
9319 if (url.indexOf(base) === 0) {
9320 url = url.replace(base, '');
9321 }
9322
9323 // The input URL intentionally contains a first path segment that ends with a colon.
9324 if (windowsFilePathExp.exec(url)) {
9325 return path;
9326 }

Callers

nothing calls this directly

Calls 10

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

Tested by

no test coverage detected