MCPcopy Create free account
hub / github.com/angular-ui/ui-grid / LocationHtml5Url

Function LocationHtml5Url

lib/test/angular/1.5.0/angular.js:12188–12254  ·  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

12186 * @param {string} basePrefix url path prefix
12187 */
12188function LocationHtml5Url(appBase, appBaseNoFile, basePrefix) {
12189 this.$$html5 = true;
12190 basePrefix = basePrefix || '';
12191 parseAbsoluteUrl(appBase, this);
12192
12193
12194 /**
12195 * Parse given html5 (regular) url string into properties
12196 * @param {string} url HTML5 url
12197 * @private
12198 */
12199 this.$$parse = function(url) {
12200 var pathUrl = beginsWith(appBaseNoFile, url);
12201 if (!isString(pathUrl)) {
12202 throw $locationMinErr('ipthprfx', 'Invalid url "{0}", missing path prefix "{1}".', url,
12203 appBaseNoFile);
12204 }
12205
12206 parseAppUrl(pathUrl, this);
12207
12208 if (!this.$$path) {
12209 this.$$path = '/';
12210 }
12211
12212 this.$$compose();
12213 };
12214
12215 /**
12216 * Compose url and update `absUrl` property
12217 * @private
12218 */
12219 this.$$compose = function() {
12220 var search = toKeyValue(this.$$search),
12221 hash = this.$$hash ? '#' + encodeUriSegment(this.$$hash) : '';
12222
12223 this.$$url = encodePath(this.$$path) + (search ? '?' + search : '') + hash;
12224 this.$$absUrl = appBaseNoFile + this.$$url.substr(1); // first char is always '/'
12225 };
12226
12227 this.$$parseLinkUrl = function(url, relHref) {
12228 if (relHref && relHref[0] === '#') {
12229 // special case for links to hash fragments:
12230 // keep the old url and only replace the hash fragment
12231 this.hash(relHref.slice(1));
12232 return true;
12233 }
12234 var appUrl, prevAppUrl;
12235 var rewrittenUrl;
12236
12237 if (isDefined(appUrl = beginsWith(appBase, url))) {
12238 prevAppUrl = appUrl;
12239 if (isDefined(appUrl = beginsWith(basePrefix, appUrl))) {
12240 rewrittenUrl = appBaseNoFile + (beginsWith('/', appUrl) || appUrl);
12241 } else {
12242 rewrittenUrl = appBase + prevAppUrl;
12243 }
12244 } else if (isDefined(appUrl = beginsWith(appBaseNoFile, url))) {
12245 rewrittenUrl = appBaseNoFile + appUrl;

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected