MCPcopy
hub / github.com/angular-ui/ui-router / LocationHashbangUrl

Function LocationHashbangUrl

test/angular/1.5/angular.js:13212–13311  ·  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

13210 * @param {string} hashPrefix hashbang prefix
13211 */
13212function LocationHashbangUrl(appBase, appBaseNoFile, hashPrefix) {
13213
13214 parseAbsoluteUrl(appBase, this);
13215
13216
13217 /**
13218 * Parse given hashbang URL into properties
13219 * @param {string} url Hashbang URL
13220 * @private
13221 */
13222 this.$$parse = function(url) {
13223 var withoutBaseUrl = stripBaseUrl(appBase, url) || stripBaseUrl(appBaseNoFile, url);
13224 var withoutHashUrl;
13225
13226 if (!isUndefined(withoutBaseUrl) && withoutBaseUrl.charAt(0) === '#') {
13227
13228 // The rest of the URL starts with a hash so we have
13229 // got either a hashbang path or a plain hash fragment
13230 withoutHashUrl = stripBaseUrl(hashPrefix, withoutBaseUrl);
13231 if (isUndefined(withoutHashUrl)) {
13232 // There was no hashbang prefix so we just have a hash fragment
13233 withoutHashUrl = withoutBaseUrl;
13234 }
13235
13236 } else {
13237 // There was no hashbang path nor hash fragment:
13238 // If we are in HTML5 mode we use what is left as the path;
13239 // Otherwise we ignore what is left
13240 if (this.$$html5) {
13241 withoutHashUrl = withoutBaseUrl;
13242 } else {
13243 withoutHashUrl = '';
13244 if (isUndefined(withoutBaseUrl)) {
13245 appBase = url;
13246 this.replace();
13247 }
13248 }
13249 }
13250
13251 parseAppUrl(withoutHashUrl, this);
13252
13253 this.$$path = removeWindowsDriveName(this.$$path, withoutHashUrl, appBase);
13254
13255 this.$$compose();
13256
13257 /*
13258 * In Windows, on an anchor node on documents loaded from
13259 * the filesystem, the browser will return a pathname
13260 * prefixed with the drive name ('/C:/path') when a
13261 * pathname without a drive is set:
13262 * * a.setAttribute('href', '/foo')
13263 * * a.pathname === '/C:/foo' //true
13264 *
13265 * Inside of Angular, we're always using pathnames that
13266 * do not include drive names for routing.
13267 */
13268 function removeWindowsDriveName(path, url, base) {
13269 /*

Callers

nothing calls this directly

Calls 9

parseAbsoluteUrlFunction · 0.70
stripBaseUrlFunction · 0.70
isUndefinedFunction · 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