MCPcopy Index your code
hub / github.com/angular-ui/ui-router / LocationHtml5Url

Function LocationHtml5Url

test/angular/1.2/angular.js:9345–9406  ·  view source on GitHub ↗

* LocationHtml5Url represents an url * This object is exposed as $location service when HTML5 mode is enabled and supported * * @constructor * @param {string} appBase application base URL * @param {string} basePrefix url path prefix

(appBase, basePrefix)

Source from the content-addressed store, hash-verified

9343 * @param {string} basePrefix url path prefix
9344 */
9345function LocationHtml5Url(appBase, basePrefix) {
9346 this.$$html5 = true;
9347 basePrefix = basePrefix || '';
9348 var appBaseNoFile = stripFile(appBase);
9349 parseAbsoluteUrl(appBase, this, appBase);
9350
9351
9352 /**
9353 * Parse given html5 (regular) url string into properties
9354 * @param {string} newAbsoluteUrl HTML5 url
9355 * @private
9356 */
9357 this.$$parse = function(url) {
9358 var pathUrl = beginsWith(appBaseNoFile, url);
9359 if (!isString(pathUrl)) {
9360 throw $locationMinErr('ipthprfx', 'Invalid url "{0}", missing path prefix "{1}".', url,
9361 appBaseNoFile);
9362 }
9363
9364 parseAppUrl(pathUrl, this, appBase);
9365
9366 if (!this.$$path) {
9367 this.$$path = '/';
9368 }
9369
9370 this.$$compose();
9371 };
9372
9373 /**
9374 * Compose url and update `absUrl` property
9375 * @private
9376 */
9377 this.$$compose = function() {
9378 var search = toKeyValue(this.$$search),
9379 hash = this.$$hash ? '#' + encodeUriSegment(this.$$hash) : '';
9380
9381 this.$$url = encodePath(this.$$path) + (search ? '?' + search : '') + hash;
9382 this.$$absUrl = appBaseNoFile + this.$$url.substr(1); // first char is always '/'
9383 };
9384
9385 this.$$parseLinkUrl = function(url, relHref) {
9386 var appUrl, prevAppUrl;
9387 var rewrittenUrl;
9388
9389 if ( (appUrl = beginsWith(appBase, url)) !== undefined ) {
9390 prevAppUrl = appUrl;
9391 if ( (appUrl = beginsWith(basePrefix, appUrl)) !== undefined ) {
9392 rewrittenUrl = appBaseNoFile + (beginsWith('/', appUrl) || appUrl);
9393 } else {
9394 rewrittenUrl = appBase + prevAppUrl;
9395 }
9396 } else if ( (appUrl = beginsWith(appBaseNoFile, url)) !== undefined ) {
9397 rewrittenUrl = appBaseNoFile + appUrl;
9398 } else if (appBaseNoFile == url + '/') {
9399 rewrittenUrl = appBaseNoFile;
9400 }
9401 if (rewrittenUrl) {
9402 this.$$parse(rewrittenUrl);

Callers

nothing calls this directly

Calls 8

stripFileFunction · 0.70
parseAbsoluteUrlFunction · 0.70
beginsWithFunction · 0.70
isStringFunction · 0.70
parseAppUrlFunction · 0.70
toKeyValueFunction · 0.70
encodeUriSegmentFunction · 0.70
encodePathFunction · 0.70

Tested by

no test coverage detected