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

Function LocationHtml5Url

test/angular/1.3/angular.js:10661–10727  ·  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} appBaseNoFile application base URL stripped of any filename * @param {string} basePrefix

(appBase, appBaseNoFile, basePrefix)

Source from the content-addressed store, hash-verified

10659 * @param {string} basePrefix url path prefix
10660 */
10661function LocationHtml5Url(appBase, appBaseNoFile, basePrefix) {
10662 this.$$html5 = true;
10663 basePrefix = basePrefix || '';
10664 parseAbsoluteUrl(appBase, this);
10665
10666
10667 /**
10668 * Parse given html5 (regular) url string into properties
10669 * @param {string} url HTML5 url
10670 * @private
10671 */
10672 this.$$parse = function(url) {
10673 var pathUrl = beginsWith(appBaseNoFile, url);
10674 if (!isString(pathUrl)) {
10675 throw $locationMinErr('ipthprfx', 'Invalid url "{0}", missing path prefix "{1}".', url,
10676 appBaseNoFile);
10677 }
10678
10679 parseAppUrl(pathUrl, this);
10680
10681 if (!this.$$path) {
10682 this.$$path = '/';
10683 }
10684
10685 this.$$compose();
10686 };
10687
10688 /**
10689 * Compose url and update `absUrl` property
10690 * @private
10691 */
10692 this.$$compose = function() {
10693 var search = toKeyValue(this.$$search),
10694 hash = this.$$hash ? '#' + encodeUriSegment(this.$$hash) : '';
10695
10696 this.$$url = encodePath(this.$$path) + (search ? '?' + search : '') + hash;
10697 this.$$absUrl = appBaseNoFile + this.$$url.substr(1); // first char is always '/'
10698 };
10699
10700 this.$$parseLinkUrl = function(url, relHref) {
10701 if (relHref && relHref[0] === '#') {
10702 // special case for links to hash fragments:
10703 // keep the old url and only replace the hash fragment
10704 this.hash(relHref.slice(1));
10705 return true;
10706 }
10707 var appUrl, prevAppUrl;
10708 var rewrittenUrl;
10709
10710 if ((appUrl = beginsWith(appBase, url)) !== undefined) {
10711 prevAppUrl = appUrl;
10712 if ((appUrl = beginsWith(basePrefix, appUrl)) !== undefined) {
10713 rewrittenUrl = appBaseNoFile + (beginsWith('/', appUrl) || appUrl);
10714 } else {
10715 rewrittenUrl = appBase + prevAppUrl;
10716 }
10717 } else if ((appUrl = beginsWith(appBaseNoFile, url)) !== undefined) {
10718 rewrittenUrl = appBaseNoFile + appUrl;

Callers

nothing calls this directly

Calls 7

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