MCPcopy Create free account
hub / github.com/EricSimons/ionic-course / LocationHtml5Url

Function LocationHtml5Url

code/songhop/www/lib/angular/angular.js:10541–10608  ·  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

10539 * @param {string} basePrefix url path prefix
10540 */
10541function LocationHtml5Url(appBase, basePrefix) {
10542 this.$$html5 = true;
10543 basePrefix = basePrefix || '';
10544 var appBaseNoFile = stripFile(appBase);
10545 parseAbsoluteUrl(appBase, this);
10546
10547
10548 /**
10549 * Parse given html5 (regular) url string into properties
10550 * @param {string} url HTML5 url
10551 * @private
10552 */
10553 this.$$parse = function(url) {
10554 var pathUrl = beginsWith(appBaseNoFile, url);
10555 if (!isString(pathUrl)) {
10556 throw $locationMinErr('ipthprfx', 'Invalid url "{0}", missing path prefix "{1}".', url,
10557 appBaseNoFile);
10558 }
10559
10560 parseAppUrl(pathUrl, this);
10561
10562 if (!this.$$path) {
10563 this.$$path = '/';
10564 }
10565
10566 this.$$compose();
10567 };
10568
10569 /**
10570 * Compose url and update `absUrl` property
10571 * @private
10572 */
10573 this.$$compose = function() {
10574 var search = toKeyValue(this.$$search),
10575 hash = this.$$hash ? '#' + encodeUriSegment(this.$$hash) : '';
10576
10577 this.$$url = encodePath(this.$$path) + (search ? '?' + search : '') + hash;
10578 this.$$absUrl = appBaseNoFile + this.$$url.substr(1); // first char is always '/'
10579 };
10580
10581 this.$$parseLinkUrl = function(url, relHref) {
10582 if (relHref && relHref[0] === '#') {
10583 // special case for links to hash fragments:
10584 // keep the old url and only replace the hash fragment
10585 this.hash(relHref.slice(1));
10586 return true;
10587 }
10588 var appUrl, prevAppUrl;
10589 var rewrittenUrl;
10590
10591 if ((appUrl = beginsWith(appBase, url)) !== undefined) {
10592 prevAppUrl = appUrl;
10593 if ((appUrl = beginsWith(basePrefix, appUrl)) !== undefined) {
10594 rewrittenUrl = appBaseNoFile + (beginsWith('/', appUrl) || appUrl);
10595 } else {
10596 rewrittenUrl = appBase + prevAppUrl;
10597 }
10598 } else if ((appUrl = beginsWith(appBaseNoFile, url)) !== undefined) {

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